Skip to content

Commit

Permalink
Chore: increase test coverage (#153)
Browse files Browse the repository at this point in the history
  • Loading branch information
emmercm authored Nov 2, 2022
1 parent 1cf5ecb commit 4f44dc5
Show file tree
Hide file tree
Showing 10 changed files with 22 additions and 27 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.**

Expand Down
12 changes: 0 additions & 12 deletions src/polyfill/filePoly.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,18 +99,6 @@ export default class FilePoly {
return result;
}

async readAll(): Promise<Buffer> {
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<number> {
return (await util.promisify(fs.write)(this.fd, buffer)).bytesWritten;
}
Expand Down
4 changes: 2 additions & 2 deletions src/types/archives/sevenZip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ 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
'.lzma86', // lzma86
'.pmd', // ppmd
'.001', // split
'.tar', '.ova', // tar
'.xz', // xz
// '.xz', // xz
'.z', // z
'.zip', '.z01', '.zipx', // zip
'.zst', // zstd
Expand Down
6 changes: 0 additions & 6 deletions src/types/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
Binary file added test/fixtures/roms/patchable/best.gz
Binary file not shown.
1 change: 0 additions & 1 deletion test/fixtures/roms/patchable/best.rom

This file was deleted.

8 changes: 8 additions & 0 deletions test/modules/argumentsParser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,14 @@ describe('options', () => {
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);
Expand Down
6 changes: 3 additions & 3 deletions test/modules/romScanner.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down
4 changes: 2 additions & 2 deletions test/modules/romWriter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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/*',
Expand Down Expand Up @@ -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/*',
Expand Down
6 changes: 6 additions & 0 deletions test/polyfill/fsPoly.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});

0 comments on commit 4f44dc5

Please sign in to comment.