From 4f44dc57f7290d5ab7aed5d917c71367abe8bf1b Mon Sep 17 00:00:00 2001 From: Christian Emmer Date: Wed, 2 Nov 2022 16:51:28 -0700 Subject: [PATCH] Chore: increase test coverage (#153) --- README.md | 2 +- src/polyfill/filePoly.ts | 12 ------------ src/types/archives/sevenZip.ts | 4 ++-- src/types/options.ts | 6 ------ test/fixtures/roms/patchable/best.gz | Bin 0 -> 57 bytes test/fixtures/roms/patchable/best.rom | 1 - test/modules/argumentsParser.test.ts | 8 ++++++++ test/modules/romScanner.test.ts | 6 +++--- test/modules/romWriter.test.ts | 4 ++-- test/polyfill/fsPoly.test.ts | 6 ++++++ 10 files changed, 22 insertions(+), 27 deletions(-) create mode 100644 test/fixtures/roms/patchable/best.gz delete mode 100644 test/fixtures/roms/patchable/best.rom diff --git a/README.md b/README.md index 03960162e..ebcc432fc 100644 --- a/README.md +++ b/README.md @@ -33,7 +33,7 @@ With a large ROM collection it can be difficult to: **`igir` needs an input set of ROMs, of course!** -Those ROMs can be in archives (`.001`, `.7z`, `.bz2`, `.gz`, `.rar`, `.tar.gz`, `.z01`, `.zip`, `.zipx`, and more!) or on their own. They can also contain a header or not (see [docs](docs/rom-headers.md)). +Those ROMs can be in archives (`.001`, `.7z`, `.gz`, `.rar`, `.tar.gz`, `.z01`, `.zip`, `.zipx`, and more!) or on their own. They can also contain a header or not (see [docs](docs/rom-headers.md)). **`igir` works best with a set of DATs as well.** diff --git a/src/polyfill/filePoly.ts b/src/polyfill/filePoly.ts index 18917e920..decb8839e 100644 --- a/src/polyfill/filePoly.ts +++ b/src/polyfill/filePoly.ts @@ -99,18 +99,6 @@ export default class FilePoly { return result; } - async readAll(): Promise { - const buffer = Buffer.alloc(this.size); - await util.promisify(fs.read)( - this.fd, - buffer, - 0, - this.size, - 0, - ); - return buffer; - } - async write(buffer: Buffer): Promise { return (await util.promisify(fs.write)(this.fd, buffer)).bytesWritten; } diff --git a/src/types/archives/sevenZip.ts b/src/types/archives/sevenZip.ts index 7580ff73f..fa5f8f01b 100644 --- a/src/types/archives/sevenZip.ts +++ b/src/types/archives/sevenZip.ts @@ -10,7 +10,7 @@ export default class SevenZip extends Archive { // WARNING: tar+compression doesn't work, you'll be left with a tar file output static readonly SUPPORTED_EXTENSIONS = [ '.7z', // 7z - '.bz2', '.bzip2', // bzip2 + // '.bz2', '.bzip2', // bzip2 '.cab', // cab '.gz', '.gzip', // gzip '.lzma', // lzma @@ -18,7 +18,7 @@ export default class SevenZip extends Archive { '.pmd', // ppmd '.001', // split '.tar', '.ova', // tar - '.xz', // xz + // '.xz', // xz '.z', // z '.zip', '.z01', '.zipx', // zip '.zst', // zstd diff --git a/src/types/options.ts b/src/types/options.ts index 1d54de235..6d96aec9f 100644 --- a/src/types/options.ts +++ b/src/types/options.ts @@ -542,12 +542,6 @@ export default class Options implements OptionsProps { return this.help; } - static filterUniqueLower(array: string[]): string[] { - return array - .map((value) => value.toLowerCase()) - .filter((val, idx, arr) => arr.indexOf(val) === idx); - } - static filterUniqueUpper(array: string[]): string[] { return array .map((value) => value.toUpperCase()) diff --git a/test/fixtures/roms/patchable/best.gz b/test/fixtures/roms/patchable/best.gz new file mode 100644 index 0000000000000000000000000000000000000000..55c04bc98bd63fc346b8f28b86a7d4182ef80696 GIT binary patch literal 57 zcmb2|=HU4LBPp4MAt|-EM6W16mw{1|;o1Mp5{2@_Vug~7R0WWPLVlV;NoH { expect(argumentsParser.parse([...dummyCommandAndRequiredArgs, '--no-bad', 'true', '--no-bad', 'false']).getNoBad()).toEqual(false); }); + it('should parse "verbose"', () => { + expect(argumentsParser.parse(dummyCommandAndRequiredArgs).getLogLevel()).toEqual(LogLevel.WARN); + expect(argumentsParser.parse([...dummyCommandAndRequiredArgs, '-v']).getLogLevel()).toEqual(LogLevel.INFO); + expect(argumentsParser.parse([...dummyCommandAndRequiredArgs, '--verbose']).getLogLevel()).toEqual(LogLevel.INFO); + expect(argumentsParser.parse([...dummyCommandAndRequiredArgs, '-vv']).getLogLevel()).toEqual(LogLevel.DEBUG); + expect(argumentsParser.parse([...dummyCommandAndRequiredArgs, '-vvv']).getLogLevel()).toEqual(LogLevel.DEBUG); + }); + it('should parse "help"', () => { expect(argumentsParser.parse(['-h']).getHelp()).toEqual(true); expect(argumentsParser.parse(['--help']).getHelp()).toEqual(true); diff --git a/test/modules/romScanner.test.ts b/test/modules/romScanner.test.ts index 4190c628e..94f42d3b9 100644 --- a/test/modules/romScanner.test.ts +++ b/test/modules/romScanner.test.ts @@ -41,9 +41,9 @@ describe('multiple files', () => { }); it('some files are excluded', async () => { - await expect(createRomScanner(['test/fixtures/roms/**/*'], ['test/fixtures/roms/**/*.rom']).scan()).resolves.toHaveLength(41); - await expect(createRomScanner(['test/fixtures/roms/**/*'], ['test/fixtures/roms/**/*.rom', 'test/fixtures/roms/**/*.rom']).scan()).resolves.toHaveLength(41); - await expect(createRomScanner(['test/fixtures/roms/**/*'], ['test/fixtures/roms/**/*.rom', 'test/fixtures/roms/**/*.zip']).scan()).resolves.toHaveLength(32); + await expect(createRomScanner(['test/fixtures/roms/**/*'], ['test/fixtures/roms/**/*.rom']).scan()).resolves.toHaveLength(42); + await expect(createRomScanner(['test/fixtures/roms/**/*'], ['test/fixtures/roms/**/*.rom', 'test/fixtures/roms/**/*.rom']).scan()).resolves.toHaveLength(42); + await expect(createRomScanner(['test/fixtures/roms/**/*'], ['test/fixtures/roms/**/*.rom', 'test/fixtures/roms/**/*.zip']).scan()).resolves.toHaveLength(33); }); it('all files are excluded', async () => { diff --git a/test/modules/romWriter.test.ts b/test/modules/romWriter.test.ts index a5e70cd17..981926ede 100644 --- a/test/modules/romWriter.test.ts +++ b/test/modules/romWriter.test.ts @@ -372,7 +372,7 @@ describe('zip', () => { [ '**/!(*headered)/*', ['before.zip', 'best.zip', 'empty.zip', 'fizzbuzz.zip', 'foobar.zip', 'loremipsum.zip', 'one.zip', 'three.zip', 'two.zip', 'unknown.zip'], - ['patchable/before.rom', 'patchable/best.rom', 'raw/empty.rom', 'raw/fizzbuzz.nes', 'raw/foobar.lnx', 'raw/loremipsum.rom', 'raw/one.rom', 'raw/three.rom', 'raw/two.rom', 'raw/unknown.rom'], + ['patchable/before.rom', 'patchable/best.gz', 'raw/empty.rom', 'raw/fizzbuzz.nes', 'raw/foobar.lnx', 'raw/loremipsum.rom', 'raw/one.rom', 'raw/three.rom', 'raw/two.rom', 'raw/unknown.rom'], ], [ '7z/*', @@ -619,7 +619,7 @@ describe('raw', () => { [ '**/!(*headered)/*', ['before.rom', 'best.rom', 'empty.rom', 'fizzbuzz.nes', 'foobar.lnx', 'loremipsum.rom', 'one.rom', 'three.rom', 'two.rom', 'unknown.rom'], - ['patchable/before.rom', 'patchable/best.rom', 'raw/empty.rom', 'raw/fizzbuzz.nes', 'raw/foobar.lnx', 'raw/loremipsum.rom', 'raw/one.rom', 'raw/three.rom', 'raw/two.rom', 'raw/unknown.rom'], + ['patchable/before.rom', 'patchable/best.gz', 'raw/empty.rom', 'raw/fizzbuzz.nes', 'raw/foobar.lnx', 'raw/loremipsum.rom', 'raw/one.rom', 'raw/three.rom', 'raw/two.rom', 'raw/unknown.rom'], ], [ '7z/*', diff --git a/test/polyfill/fsPoly.test.ts b/test/polyfill/fsPoly.test.ts index 9c41c38d9..fceb9618d 100644 --- a/test/polyfill/fsPoly.test.ts +++ b/test/polyfill/fsPoly.test.ts @@ -48,4 +48,10 @@ describe('rmSync', () => { fsPoly.rmSync(file); await expect(fsPoly.exists(file)).resolves.toEqual(false); }); + + it('should delete an existing directory', async () => { + const dir = fsPoly.mkdtempSync(path.join(process.cwd(), 'temp')); + fsPoly.rmSync(dir); + await expect(fsPoly.exists(dir)).resolves.toEqual(false); + }); });