-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathjest.js
155 lines (147 loc) · 5.77 KB
/
jest.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
let readPkgUp
try {
readPkgUp = import("read-package-up")
} catch (error) {
console.error("Error importing readPkgUp:", error)
}
/**
* @see https://github.com/eslint/eslint/issues/3458
* @see https://www.npmjs.com/package/@rushstack/eslint-patch
*/
require("@rushstack/eslint-patch/modern-module-resolution")
let hasJestDom = false
let hasTestingLibrary = false
try {
const { packageJson } = readPkgUp.sync({ normalize: true })
const allDeps = Object.keys({
...packageJson.peerDependencies,
...packageJson.devDependencies,
...packageJson.dependencies,
})
hasJestDom = allDeps.includes("@testing-library/jest-dom")
hasTestingLibrary = allDeps.includes("@testing-library/react")
} catch {
// ignore error
}
module.exports = {
plugins: [
"jest",
hasJestDom ? "jest-dom" : null,
hasTestingLibrary ? "testing-library" : null,
].filter(Boolean),
env: {
"jest/globals": true,
},
rules: {},
overrides: [
{
files: [
"**/__tests__/**/*.+(js|ts)?(x)",
"**/*.{spec,test}.+(js|ts)?(x)",
],
rules: {
"react/display-name": "off", // we don't need a display name in test files
"jest/consistent-test-it": "off",
"jest/expect-expect": "off",
"jest/max-nested-describe": "error",
"jest/no-alias-methods": "off",
"jest/no-commented-out-tests": "warn",
"jest/no-conditional-expect": "error",
"jest/no-conditional-in-test": "error",
"jest/no-deprecated-functions": "error",
"jest/no-disabled-tests": "warn",
"jest/no-done-callback": "error",
"jest/no-duplicate-hooks": "off",
"jest/no-export": "error",
"jest/no-focused-tests": "error",
"jest/no-hooks": "off",
"jest/no-identical-title": "error",
"jest/no-if": "error",
"jest/no-interpolation-in-snapshots": "error",
"jest/no-jasmine-globals": "off",
"jest/no-large-snapshots": ["warn", { maxSize: 300 }],
"jest/no-mocks-import": "error",
"jest/no-restricted-matchers": "off",
"jest/no-standalone-expect": "off",
"jest/no-test-prefixes": "error",
"jest/no-test-return-statement": "off",
"jest/prefer-called-with": "error",
"jest/prefer-comparison-matcher": "error",
"jest/prefer-equality-matcher": "error",
"jest/prefer-expect-assertions": "off",
"jest/prefer-expect-resolves": "off",
"jest/prefer-hooks-in-order": "error",
"jest/prefer-hooks-on-top": "error",
"jest/prefer-lowercase-title": "off",
"jest/prefer-snapshot-hint": "error",
"jest/prefer-spy-on": "off",
"jest/prefer-strict-equal": "off",
"jest/prefer-to-be": "off",
"jest/prefer-to-contain": "warn",
"jest/prefer-to-have-length": "warn",
"jest/prefer-todo": "warn",
"jest/require-hook": "off",
"jest/require-to-throw-message": "off",
"jest/require-top-level-describe": "off",
"jest/unbound-method": "off",
"jest/valid-describe-callback": "error",
"jest/valid-expect": "error",
"jest/valid-expect-in-promise": "error",
"jest/valid-title": "warn",
...(hasJestDom
? {
"jest-dom/prefer-checked": "error",
"jest-dom/prefer-empty": "error",
"jest-dom/prefer-enabled-disabled": "error",
"jest-dom/prefer-focus": "error",
"jest-dom/prefer-in-document": "error",
"jest-dom/prefer-required": "error",
"jest-dom/prefer-to-have-attribute": "error",
"jest-dom/prefer-to-have-class": "error",
"jest-dom/prefer-to-have-style": "error",
"jest-dom/prefer-to-have-text-content": "error",
"jest-dom/prefer-to-have-value": "error",
}
: null),
...(hasTestingLibrary
? {
"testing-library/await-async-query": "error",
"testing-library/await-async-utils": "error",
"testing-library/await-fire-event": "off",
"testing-library/consistent-data-testid": "off",
"testing-library/no-await-sync-events": "error",
"testing-library/no-await-sync-query": "error",
"testing-library/no-container": "error",
"testing-library/no-debugging-utils": "error",
"testing-library/no-dom-import": ["error", "react"],
"testing-library/no-global-regexp-flag-in-query": "error",
"testing-library/no-manual-cleanup": "error",
"testing-library/no-node-access": "error",
"testing-library/no-promise-in-fire-event": "error",
"testing-library/no-render-in-setup": "error",
"testing-library/no-unnecessary-act": "error",
"testing-library/no-wait-for-empty-callback": "error",
"testing-library/no-wait-for-multiple-assertions": "error",
"testing-library/no-wait-for-side-effects": "error",
"testing-library/no-wait-for-snapshot": "error",
"testing-library/prefer-explicit-assert": "warn",
"testing-library/prefer-find-by": "error",
"testing-library/prefer-presence-queries": "error",
"testing-library/prefer-query-by-disappearance": "error",
"testing-library/prefer-screen-queries": "error",
"testing-library/prefer-user-event": "error",
"testing-library/prefer-wait-for": "error",
"testing-library/render-result-naming-convention": "error",
}
: null),
},
},
{
files: ["**/__tests__/**/*.ts?(x)", "**/*.{spec,test}.ts?(x)"],
rules: {
"@typescript-eslint/unbound-method": "off",
"jest/unbound-method": "error",
},
},
],
}