Skip to content

Commit

Permalink
Add jest-dom pugin to testing-library config
Browse files Browse the repository at this point in the history
  • Loading branch information
burtek committed Jun 22, 2023
1 parent dce98fe commit 6482c86
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 16 deletions.
21 changes: 9 additions & 12 deletions configs/testing-library.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,22 @@
import { defineFlatConfig } from 'eslint-define-config';
import jestDom from 'eslint-plugin-jest-dom';
import testingLibrary from 'eslint-plugin-testing-library';


const files = ['**/*.test.{js,cjs,mjs,jsx,ts,cts,mts,tsx}'];
const cyFiles = ['**/*.cy.{js,cjs,mjs,jsx,ts,cts,mts,tsx}'];

// eslint-disable-next-line no-warning-comments
// TODO: move to FlatConfig once testing-library is upgraded
/**
* @param {Object} [config]
* @param {boolean} [config.enableCypress]
*/
export function prepareConfig({ enableCypress = false } = {}) {
// TODO: move to FlatConfig once testing-library and jest-dom are upgraded
export function prepareConfig() {
return defineFlatConfig([
{
files: [
...files,
...(enableCypress ? cyFiles : [])
],
plugins: { 'testing-library': { rules: testingLibrary.rules } },
files,
plugins: {
'jest-dom': { rules: jestDom.rules },
'testing-library': { rules: testingLibrary.rules }
},
rules: {
...jestDom.configs.all.rules,
...testingLibrary.configs.react.rules,
'testing-library/prefer-user-event': 'warn'
}
Expand Down
16 changes: 16 additions & 0 deletions import-types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,3 +200,19 @@ declare module 'eslint-plugin-testing-library/configs/*.js' {

export default config;
}

declare module 'eslint-plugin-jest-dom' {
import type { Rule } from 'eslint';
import type { Severity } from 'eslint-define-config/src/rules/rule-severity.js';


const plugin: {
configs: Record<'recommended' | 'all', {
plugins: [string];
rules: Record<string, Severity>;
}>;
rules: Record<string, Rule.RuleModule>;
};

export default plugin;
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"eslint-plugin-cypress": "^2.13.3",
"eslint-plugin-import": "^2.27.5",
"eslint-plugin-jest": "^27.2.1",
"eslint-plugin-jest-dom": "^5.0.1",
"eslint-plugin-jest-formatting": "^3.1.0",
"eslint-plugin-jsonc": "^2.8.0",
"eslint-plugin-jsx-a11y": "^6.7.1",
Expand Down
21 changes: 17 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
# yarn lockfile v1


"@babel/runtime@^7.20.7":
version "7.21.5"
resolved "https://registry.yarnpkg.com/@babel/runtime/-/runtime-7.21.5.tgz#8492dddda9644ae3bda3b45eabe87382caee7200"
integrity sha512-8jI69toZqqcsnqGGqwGS4Qb1VwLOEp4hz+CXPywcvjs60u3B4Pom/U/7rm4W8tMOYEB+E9wgD0mW1l3r8qlI9Q==
"@babel/runtime@^7.16.3", "@babel/runtime@^7.20.7":
version "7.22.5"
resolved "https://registry.yarnpkg.com/@babel/runtime/-/runtime-7.22.5.tgz#8564dd588182ce0047d55d7a75e93921107b57ec"
integrity sha512-ecjvYlnAaZ/KVneE/OdKYBYfgXV3Ptu6zQWmgEF7vwKhQnvVS6bjMD2XYgj+SNvQ1GfK/pjgokfPkC/2CO8CuA==
dependencies:
regenerator-runtime "^0.13.11"

Expand Down Expand Up @@ -759,6 +759,14 @@ eslint-plugin-import@^2.27.5:
semver "^6.3.0"
tsconfig-paths "^3.14.1"

eslint-plugin-jest-dom@^5.0.1:
version "5.0.1"
resolved "https://registry.yarnpkg.com/eslint-plugin-jest-dom/-/eslint-plugin-jest-dom-5.0.1.tgz#48a0bec664665f206535c87a70d063a05e4189da"
integrity sha512-zD/BjNk12R5R9cxIu8oa2HfNeDSknI3ewtN8nygIUMQuieWDnTY9Np//6a1Z3G7Y3dx3l45hCUR4EphsgRmUtA==
dependencies:
"@babel/runtime" "^7.16.3"
requireindex "^1.2.0"

eslint-plugin-jest-formatting@^3.1.0:
version "3.1.0"
resolved "https://registry.yarnpkg.com/eslint-plugin-jest-formatting/-/eslint-plugin-jest-formatting-3.1.0.tgz#b26dd5a40f432b642dcc880021a771bb1c93dcd2"
Expand Down Expand Up @@ -1946,6 +1954,11 @@ regexp.prototype.flags@^1.4.3, regexp.prototype.flags@^1.5.0:
define-properties "^1.2.0"
functions-have-names "^1.2.3"

requireindex@^1.2.0:
version "1.2.0"
resolved "https://registry.yarnpkg.com/requireindex/-/requireindex-1.2.0.tgz#3463cdb22ee151902635aa6c9535d4de9c2ef1ef"
integrity sha512-L9jEkOi3ASd9PYit2cwRfyppc9NoABujTP8/5gFcbERmo5jUoAKovIC3fsF17pkTnGsrByysqX+Kxd2OTNI1ww==

resolve-from@^4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/resolve-from/-/resolve-from-4.0.0.tgz#4abcd852ad32dd7baabfe9b40e00a36db5f392e6"
Expand Down

0 comments on commit 6482c86

Please sign in to comment.