Jest lint (#118)

* Jest lint

* Feedback
This commit is contained in:
Will Scullin 2022-05-30 09:29:48 -07:00 committed by GitHub
parent e525e12c3c
commit d4db26574d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 54 additions and 11 deletions

View File

@ -72,8 +72,13 @@
}
],
"@typescript-eslint/require-await": ["error"],
"react-hooks/rules-of-hooks": "error",
"react-hooks/exhaustive-deps": "error"
"jest/expect-expect": ["error", {
"assertFunctionNames": [
"expect*",
"checkImageData",
"testCode"
]
}]
},
"env": {
"builtin": true,
@ -86,6 +91,7 @@
},
"extends": [
"eslint:recommended",
"plugin:jest/recommended",
"plugin:react/recommended",
"plugin:react-hooks/recommended"
],

34
package-lock.json generated
View File

@ -32,6 +32,7 @@
"babel-jest": "^27.2.4",
"canvas": "^2.8.0",
"eslint": "^8.16.0",
"eslint-plugin-jest": "^26.4.3",
"eslint-plugin-react": "^7.30.0",
"eslint-plugin-react-hooks": "^4.5.0",
"file-loader": "^6.0.0",
@ -5669,6 +5670,30 @@
"url": "https://opencollective.com/eslint"
}
},
"node_modules/eslint-plugin-jest": {
"version": "26.4.3",
"resolved": "https://registry.npmjs.org/eslint-plugin-jest/-/eslint-plugin-jest-26.4.3.tgz",
"integrity": "sha512-eb4sIRLy7hBdBphCBttE1Gx3Go6GsCYXRfy1xtuSg56UBlLLuFpbA79jPipbUfz7AwuDJ+j9UShN7AOi6VDEuQ==",
"dev": true,
"dependencies": {
"@typescript-eslint/utils": "^5.10.0"
},
"engines": {
"node": "^12.22.0 || ^14.17.0 || >=16.0.0"
},
"peerDependencies": {
"@typescript-eslint/eslint-plugin": "^5.0.0",
"eslint": "^6.0.0 || ^7.0.0 || ^8.0.0"
},
"peerDependenciesMeta": {
"@typescript-eslint/eslint-plugin": {
"optional": true
},
"jest": {
"optional": true
}
}
},
"node_modules/eslint-plugin-react": {
"version": "7.30.0",
"resolved": "https://registry.npmjs.org/eslint-plugin-react/-/eslint-plugin-react-7.30.0.tgz",
@ -18916,6 +18941,15 @@
}
}
},
"eslint-plugin-jest": {
"version": "26.4.3",
"resolved": "https://registry.npmjs.org/eslint-plugin-jest/-/eslint-plugin-jest-26.4.3.tgz",
"integrity": "sha512-eb4sIRLy7hBdBphCBttE1Gx3Go6GsCYXRfy1xtuSg56UBlLLuFpbA79jPipbUfz7AwuDJ+j9UShN7AOi6VDEuQ==",
"dev": true,
"requires": {
"@typescript-eslint/utils": "^5.10.0"
}
},
"eslint-plugin-react": {
"version": "7.30.0",
"resolved": "https://registry.npmjs.org/eslint-plugin-react/-/eslint-plugin-react-7.30.0.tgz",

View File

@ -41,6 +41,7 @@
"babel-jest": "^27.2.4",
"canvas": "^2.8.0",
"eslint": "^8.16.0",
"eslint-plugin-jest": "^26.4.3",
"eslint-plugin-react": "^7.30.0",
"eslint-plugin-react-hooks": "^4.5.0",
"file-loader": "^6.0.0",

View File

@ -2,7 +2,6 @@
* @jest-environment ./test/env/jsdom-with-backdoors
*/
import 'jest';
import { h } from 'preact';
import { fireEvent, render, screen, waitFor } from '@testing-library/preact';
@ -79,7 +78,9 @@ describe('FileChooser', () => {
const mockFilePicker = jest.fn<ReturnType<ShowOpenFilePicker>, Parameters<ShowOpenFilePicker>>();
beforeEach(() => {
expect(window.showOpenFilePicker).not.toBeDefined();
if (typeof window.showOpenFilePicker !== 'undefined') {
throw new Error('window.showOpenFilePicker not undefined');
}
window.showOpenFilePicker = mockFilePicker as unknown as ShowOpenFilePicker;
mockFilePicker.mockReset();
});
@ -126,4 +127,4 @@ describe('FileChooser', () => {
});
});
});
});
});

View File

@ -7,7 +7,7 @@ export function skipGap(track: memory, start: number = 0): number {
i++;
}
if (i === end) {
fail(`found more than 0x100 0xFF bytes after ${start}`);
throw new Error(`found more than 0x100 0xFF bytes after ${start}`);
}
return i;
}
@ -24,7 +24,7 @@ export function compareSequences(track: memory, bytes: number[], pos: number): b
export function expectSequence(track: memory, pos: number, bytes: number[]): number {
if (!compareSequences(track, bytes, pos)) {
const track_slice = track.slice(pos, Math.min(track.length, pos + bytes.length));
fail(`expected ${bytes} got ${track_slice}`);
throw new Error(`expected ${bytes} got ${track_slice}`);
}
return pos + bytes.length;
}

View File

@ -18,7 +18,7 @@ const roms: { [name: string]: { new(): ROM } } = {
for (const rom of Object.keys(roms)) {
describe(`${rom}`, () => {
it('is constructable', () => {
new roms[rom]();
expect(new roms[rom]()).not.toBeNull();
});
});
}

View File

@ -25,16 +25,17 @@ describe('allocMem', () => {
});
it('has garbage in the right places', () => {
const memory = allocMem(0x800);
let passed = false;
for (let i = 0; i < 0x800; i += 0x200) {
const passed = memory[i + 0x28] !== 0xff
passed = memory[i + 0x28] !== 0xff
&& memory[i + 0x29] !== 0xff
&& memory[i + 0x68] !== 0xff
&& memory[i + 0x69] !== 0xff;
if (passed) {
return;
break;
}
}
fail('garbage not found');
expect(passed).toBe(true);
});
});