Skip to content

Add ESLint plugins for Jest, Jest DOM, and Testing Library #8155

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions packages/eslint-config-react-app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,17 @@ module.exports = {
'@typescript-eslint/no-useless-constructor': 'warn',
},
},
{
files: [
'**/__tests__/**/*.{js,jsx,ts,tsx}',
'**/*.{spec,test}.{js,jsx,ts,tsx}',
],
extends: [
'plugin:jest/recommended',
'plugin:jest-dom/recommended',
'plugin:testing-library/react',
],
},
],

// NOTE: When adding rules here, you need to make sure they are compatible with
Expand Down
5 changes: 4 additions & 1 deletion packages/eslint-config-react-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,12 @@
"eslint": "6.x",
"eslint-plugin-flowtype": "3.x || 4.x",
"eslint-plugin-import": "2.x",
"eslint-plugin-jest": "23.x",
"eslint-plugin-jest-dom": "2.x",
"eslint-plugin-jsx-a11y": "6.x",
"eslint-plugin-react": "7.x",
"eslint-plugin-react-hooks": "1.x || 2.x || 3.x || 4.x"
"eslint-plugin-react-hooks": "1.x || 2.x || 3.x || 4.x",
"eslint-plugin-testing-library": "2.x"
},
"dependencies": {
"confusing-browser-globals": "^1.0.9"
Expand Down
13 changes: 3 additions & 10 deletions packages/react-error-overlay/src/__tests__/extract-source-map.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,8 @@ test('extracts last source map directive', async () => {
});

test('errors when no source map', async () => {
expect.assertions(1);

const testFileName = 'test.js';
try {
await extractSourceMapUrl(
testFileName,
`console.log('hi')\n\nconsole.log('bye')`
);
} catch (e) {
expect(e).toBe(`Cannot find a source map directive for ${testFileName}.`);
}
await expect(
extractSourceMapUrl(testFileName, `console.log('hi')\n\nconsole.log('bye')`)
).rejects.toBe(`Cannot find a source map directive for ${testFileName}.`);
});
13 changes: 3 additions & 10 deletions packages/react-error-overlay/src/__tests__/get-source-map.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,10 @@ test('find an inline source map', async () => {
});

test('error on a source map with unsupported encoding', async () => {
expect.assertions(2);

const file = fs
.readFileSync(resolve(__dirname, '../../fixtures/junk-inline.mjs'))
.toString('utf8');
try {
await getSourceMap('/', file);
} catch (e) {
expect(e instanceof Error).toBe(true);
expect(e.message).toBe(
'Sorry, non-base64 inline source-map encoding is not supported.'
);
}
await expect(getSourceMap('/', file)).rejects.toThrow(
new Error('Sorry, non-base64 inline source-map encoding is not supported.')
);
});
22 changes: 6 additions & 16 deletions packages/react-error-overlay/src/__tests__/parser/generic.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,13 @@
import { parse } from '../../utils/parser';

test('throws on null', () => {
expect.assertions(2);
try {
parse(null);
} catch (e) {
expect(e instanceof Error).toBe(true);
expect(e.message).toBe('You cannot pass a null object.');
}
expect(() => parse(null)).toThrow(
new Error('You cannot pass a null object.')
);
});

test('throws on unparsable', () => {
expect.assertions(2);
try {
parse({});
} catch (e) {
expect(e instanceof Error).toBe(true);
expect(e.message).toBe(
'The error you provided does not contain a stack trace.'
);
}
expect(() => parse({})).toThrow(
new Error('The error you provided does not contain a stack trace.')
);
});
3 changes: 3 additions & 0 deletions packages/react-scripts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,12 @@
"eslint-loader": "4.0.2",
"eslint-plugin-flowtype": "4.7.0",
"eslint-plugin-import": "2.20.2",
"eslint-plugin-jest": "23.6.0",
"eslint-plugin-jest-dom": "2.0.0",
"eslint-plugin-jsx-a11y": "6.2.3",
"eslint-plugin-react": "7.20.0",
"eslint-plugin-react-hooks": "^4.0.0",
"eslint-plugin-testing-library": "2.2.1",
"file-loader": "6.0.0",
"fs-extra": "^9.0.0",
"html-webpack-plugin": "4.3.0",
Expand Down