-
Notifications
You must be signed in to change notification settings - Fork 65
/
jest.js
106 lines (101 loc) · 3.57 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
const readPkgUp = require('read-pkg-up')
let hasJestDom = false
let hasTestingLibrary = false
try {
const pkg = readPkgUp.sync({normalize: true})
// eslint-disable-next-line prefer-object-spread
const allDeps = Object.assign(
pkg.peerDependencies,
pkg.devDependencies,
pkg.dependencies,
)
hasJestDom = allDeps.hasOwnProperty('@testing-library/jest-dom')
hasTestingLibrary =
allDeps.hasOwnProperty('@testing-library/dom') ||
allDeps.hasOwnProperty('@testing-library/react') ||
allDeps.hasOwnProperty('@testing-library/angular') ||
allDeps.hasOwnProperty('@testing-library/vue')
} catch (error) {
// ignore error
}
module.exports = {
env: {
'jest/globals': true,
},
plugins: [
'jest',
hasJestDom ? 'jest-dom' : null,
hasTestingLibrary ? 'testing-library' : null,
].filter(Boolean),
rules: {
'jest/no-disabled-tests': 'warn',
'jest/no-focused-tests': 'error',
'jest/no-identical-title': 'error',
'jest/valid-expect': 'error',
'jest/no-alias-methods': 'off',
'jest/no-jest-import': 'error',
'jest/no-large-snapshots': ['warn', {maxSize: 300}],
'jest/no-test-prefixes': 'error',
'jest/prefer-to-contain': 'warn',
'jest/prefer-to-have-length': 'warn',
'jest/valid-describe': 'error',
'jest/valid-expect-in-promise': 'error',
'jest/consistent-test-it': 'off',
'jest/lowercase-name': 'off',
'jest/no-deprecated-functions': 'error',
'jest/no-hooks': 'off',
'jest/no-jasmine-globals': 'off',
'jest/no-test-callback': 'off',
'jest/prefer-expect-assertions': 'off',
'jest/prefer-to-be-null': 'off',
'jest/prefer-to-be-undefined': 'off',
'jest/require-to-throw-message': 'off',
'jest/expect-expect': 'off',
'jest/no-test-return-statement': 'off',
'jest/prefer-inline-snapshots': 'off',
'jest/prefer-strict-equal': 'off',
'jest/prefer-spy-on': 'off',
'jest/prefer-todo': 'warn',
'jest/prefer-called-with': 'error',
'jest/no-truthy-falsy': 'off',
'jest/no-mocks-import': 'error',
'jest/no-commented-out-tests': 'warn',
'jest/no-duplicate-hooks': 'off',
'jest/no-expect-resolves': 'off',
'jest/no-export': 'error',
'jest/no-if': 'error',
'jest/no-standalone-expect': 'off',
'jest/no-try-expect': 'error',
'jest/require-top-level-describe': 'off',
'jest/prefer-hooks-on-top': '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-required': 'error',
'jest-dom/prefer-to-have-attribute': 'error',
'jest-dom/prefer-to-have-text-content': '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-query': 'error',
'testing-library/no-debug': 'error',
'testing-library/no-dom-import': ['error', 'react'],
'testing-library/no-manual-cleanup': 'error',
'testing-library/no-wait-for-empty-callback': 'error',
'testing-library/prefer-explicit-assert': 'warn',
'testing-library/prefer-presence-queries': 'error',
'testing-library/prefer-screen-queries': 'error',
'testing-library/prefer-wait-for': 'error',
}
: null),
},
}