eslint-plugin-jest 27.2.2 → 27.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -0
- package/docs/rules/no-confusing-set-timeout.md +62 -0
- package/lib/rules/expect-expect.js +3 -1
- package/lib/rules/no-confusing-set-timeout.js +65 -0
- package/lib/rules/no-deprecated-functions.js +2 -2
- package/lib/rules/no-test-return-statement.js +9 -3
- package/lib/rules/no-untyped-mock-factory.js +3 -1
- package/lib/rules/prefer-spy-on.js +6 -2
- package/lib/rules/unbound-method.js +1 -1
- package/package.json +13 -16
- package/lib/processors/__tests__/snapshot-processor.test.js +0 -36
- package/lib/rules/__tests__/consistent-test-it.test.js +0 -921
- package/lib/rules/__tests__/expect-expect.test.js +0 -347
- package/lib/rules/__tests__/fixtures/class.ts +0 -13
- package/lib/rules/__tests__/fixtures/file.ts +0 -0
- package/lib/rules/__tests__/fixtures/foo.ts +0 -1
- package/lib/rules/__tests__/fixtures/indent/indent-invalid-fixture-1.js +0 -530
- package/lib/rules/__tests__/fixtures/indent/indent-valid-fixture-1.js +0 -530
- package/lib/rules/__tests__/fixtures/react.tsx +0 -0
- package/lib/rules/__tests__/fixtures/tsconfig-withmeta.json +0 -6
- package/lib/rules/__tests__/fixtures/tsconfig.json +0 -16
- package/lib/rules/__tests__/fixtures/unstrict/file.ts +0 -0
- package/lib/rules/__tests__/fixtures/unstrict/react.tsx +0 -0
- package/lib/rules/__tests__/fixtures/unstrict/tsconfig.json +0 -15
- package/lib/rules/__tests__/max-expects.test.js +0 -330
- package/lib/rules/__tests__/max-nested-describe.test.js +0 -247
- package/lib/rules/__tests__/no-alias-methods.test.js +0 -190
- package/lib/rules/__tests__/no-commented-out-tests.test.js +0 -213
- package/lib/rules/__tests__/no-conditional-expect.test.js +0 -696
- package/lib/rules/__tests__/no-conditional-in-test.test.js +0 -777
- package/lib/rules/__tests__/no-deprecated-functions.test.js +0 -119
- package/lib/rules/__tests__/no-disabled-tests.test.js +0 -241
- package/lib/rules/__tests__/no-done-callback.test.js +0 -424
- package/lib/rules/__tests__/no-duplicate-hooks.test.js +0 -469
- package/lib/rules/__tests__/no-export.test.js +0 -107
- package/lib/rules/__tests__/no-focused-tests.test.js +0 -373
- package/lib/rules/__tests__/no-hooks.test.js +0 -90
- package/lib/rules/__tests__/no-identical-title.test.js +0 -270
- package/lib/rules/__tests__/no-if.test.js +0 -787
- package/lib/rules/__tests__/no-interpolation-in-snapshots.test.js +0 -58
- package/lib/rules/__tests__/no-jasmine-globals.test.js +0 -206
- package/lib/rules/__tests__/no-large-snapshots.test.js +0 -237
- package/lib/rules/__tests__/no-mocks-import.test.js +0 -73
- package/lib/rules/__tests__/no-restricted-jest-methods.test.js +0 -103
- package/lib/rules/__tests__/no-restricted-matchers.test.js +0 -244
- package/lib/rules/__tests__/no-standalone-expect.test.js +0 -230
- package/lib/rules/__tests__/no-test-prefixes.test.js +0 -206
- package/lib/rules/__tests__/no-test-return-statement.test.js +0 -122
- package/lib/rules/__tests__/no-untyped-mock-factory.test.js +0 -149
- package/lib/rules/__tests__/prefer-called-with.test.js +0 -40
- package/lib/rules/__tests__/prefer-comparison-matcher.test.js +0 -200
- package/lib/rules/__tests__/prefer-each.test.js +0 -295
- package/lib/rules/__tests__/prefer-equality-matcher.test.js +0 -184
- package/lib/rules/__tests__/prefer-expect-assertions.test.js +0 -1437
- package/lib/rules/__tests__/prefer-expect-resolves.test.js +0 -96
- package/lib/rules/__tests__/prefer-hooks-in-order.test.js +0 -678
- package/lib/rules/__tests__/prefer-hooks-on-top.test.js +0 -218
- package/lib/rules/__tests__/prefer-lowercase-title.test.js +0 -619
- package/lib/rules/__tests__/prefer-mock-promise-shorthand.test.js +0 -360
- package/lib/rules/__tests__/prefer-snapshot-hint.test.js +0 -784
- package/lib/rules/__tests__/prefer-spy-on.test.js +0 -100
- package/lib/rules/__tests__/prefer-strict-equal.test.js +0 -46
- package/lib/rules/__tests__/prefer-to-be.test.js +0 -438
- package/lib/rules/__tests__/prefer-to-contain.test.js +0 -301
- package/lib/rules/__tests__/prefer-to-have-length.test.js +0 -99
- package/lib/rules/__tests__/prefer-todo.test.js +0 -78
- package/lib/rules/__tests__/require-hook.test.js +0 -403
- package/lib/rules/__tests__/require-to-throw-message.test.js +0 -108
- package/lib/rules/__tests__/require-top-level-describe.test.js +0 -236
- package/lib/rules/__tests__/test-utils.js +0 -11
- package/lib/rules/__tests__/unbound-method.test.js +0 -518
- package/lib/rules/__tests__/valid-describe-callback.test.js +0 -305
- package/lib/rules/__tests__/valid-expect-in-promise.test.js +0 -1583
- package/lib/rules/__tests__/valid-expect.test.js +0 -894
- package/lib/rules/__tests__/valid-title.test.js +0 -1147
- package/lib/rules/utils/__tests__/detectJestVersion.test.js +0 -221
- package/lib/rules/utils/__tests__/parseJestFnCall.test.js +0 -809
|
@@ -1,221 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _child_process = require("child_process");
|
|
4
|
-
var fs = _interopRequireWildcard(require("fs"));
|
|
5
|
-
var os = _interopRequireWildcard(require("os"));
|
|
6
|
-
var path = _interopRequireWildcard(require("path"));
|
|
7
|
-
var _tsNode = require("ts-node");
|
|
8
|
-
var _detectJestVersion = require("../detectJestVersion");
|
|
9
|
-
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
10
|
-
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
11
|
-
const compileFnCode = pathToFn => {
|
|
12
|
-
const fnContents = fs.readFileSync(pathToFn, 'utf-8');
|
|
13
|
-
return (0, _tsNode.create)({
|
|
14
|
-
transpileOnly: true,
|
|
15
|
-
compilerOptions: {
|
|
16
|
-
sourceMap: false
|
|
17
|
-
}
|
|
18
|
-
}).compile(fnContents, pathToFn);
|
|
19
|
-
};
|
|
20
|
-
const compiledFn = compileFnCode(require.resolve('../detectJestVersion.ts'));
|
|
21
|
-
const relativePathToFn = 'eslint-plugin-jest/lib/rules/detectJestVersion.js';
|
|
22
|
-
const runNodeScript = (cwd, script) => {
|
|
23
|
-
return (0, _child_process.spawnSync)('node', ['-e', script.split('\n').join(' ')], {
|
|
24
|
-
cwd,
|
|
25
|
-
encoding: 'utf-8'
|
|
26
|
-
});
|
|
27
|
-
};
|
|
28
|
-
const runDetectJestVersion = cwd => {
|
|
29
|
-
return runNodeScript(cwd, `
|
|
30
|
-
try {
|
|
31
|
-
console.log(require('${relativePathToFn}').detectJestVersion());
|
|
32
|
-
} catch (error) {
|
|
33
|
-
console.error(error.message);
|
|
34
|
-
}
|
|
35
|
-
`);
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* Makes a new temp directory, prefixed with `eslint-plugin-jest-`
|
|
40
|
-
*
|
|
41
|
-
* @return {Promise<string>}
|
|
42
|
-
*/
|
|
43
|
-
const makeTempDir = () => fs.mkdtempSync(path.join(os.tmpdir(), 'eslint-plugin-jest-'));
|
|
44
|
-
const setupFakeProject = structure => {
|
|
45
|
-
const tempDir = makeTempDir();
|
|
46
|
-
for (const [filePath, contents] of Object.entries(structure)) {
|
|
47
|
-
if (contents === null) {
|
|
48
|
-
fs.mkdirSync(path.join(tempDir, filePath), {
|
|
49
|
-
recursive: true
|
|
50
|
-
});
|
|
51
|
-
continue;
|
|
52
|
-
}
|
|
53
|
-
const folderPath = path.dirname(filePath);
|
|
54
|
-
|
|
55
|
-
// make the directory (recursively)
|
|
56
|
-
fs.mkdirSync(path.join(tempDir, folderPath), {
|
|
57
|
-
recursive: true
|
|
58
|
-
});
|
|
59
|
-
const finalContents = typeof contents === 'string' ? contents : JSON.stringify(contents);
|
|
60
|
-
fs.writeFileSync(path.join(tempDir, filePath), finalContents);
|
|
61
|
-
}
|
|
62
|
-
return tempDir;
|
|
63
|
-
};
|
|
64
|
-
describe('detectJestVersion', () => {
|
|
65
|
-
describe('basic tests', () => {
|
|
66
|
-
const packageJsonFactory = jest.fn();
|
|
67
|
-
beforeEach(() => {
|
|
68
|
-
jest.resetModules();
|
|
69
|
-
jest.doMock(require.resolve('jest/package.json'), packageJsonFactory);
|
|
70
|
-
});
|
|
71
|
-
describe('when the package.json is missing the version property', () => {
|
|
72
|
-
it('throws an error', () => {
|
|
73
|
-
packageJsonFactory.mockReturnValue({});
|
|
74
|
-
expect(() => (0, _detectJestVersion.detectJestVersion)()).toThrow(/Unable to detect Jest version/iu);
|
|
75
|
-
});
|
|
76
|
-
});
|
|
77
|
-
it('caches versions', () => {
|
|
78
|
-
packageJsonFactory.mockReturnValue({
|
|
79
|
-
version: '1.2.3'
|
|
80
|
-
});
|
|
81
|
-
const version = (0, _detectJestVersion.detectJestVersion)();
|
|
82
|
-
jest.resetModules();
|
|
83
|
-
expect(_detectJestVersion.detectJestVersion).not.toThrow();
|
|
84
|
-
expect((0, _detectJestVersion.detectJestVersion)()).toBe(version);
|
|
85
|
-
});
|
|
86
|
-
});
|
|
87
|
-
describe('when in a simple project', () => {
|
|
88
|
-
it('finds the correct version', () => {
|
|
89
|
-
const projectDir = setupFakeProject({
|
|
90
|
-
'package.json': {
|
|
91
|
-
name: 'simple-project'
|
|
92
|
-
},
|
|
93
|
-
[`node_modules/${relativePathToFn}`]: compiledFn,
|
|
94
|
-
'node_modules/jest/package.json': {
|
|
95
|
-
name: 'jest',
|
|
96
|
-
version: '21.0.0'
|
|
97
|
-
}
|
|
98
|
-
});
|
|
99
|
-
const {
|
|
100
|
-
stdout,
|
|
101
|
-
stderr
|
|
102
|
-
} = runDetectJestVersion(projectDir);
|
|
103
|
-
expect(stdout.trim()).toBe('21');
|
|
104
|
-
expect(stderr.trim()).toBe('');
|
|
105
|
-
});
|
|
106
|
-
});
|
|
107
|
-
describe('when in a hoisted mono-repo', () => {
|
|
108
|
-
it('finds the correct version', () => {
|
|
109
|
-
const projectDir = setupFakeProject({
|
|
110
|
-
'package.json': {
|
|
111
|
-
name: 'mono-repo'
|
|
112
|
-
},
|
|
113
|
-
[`node_modules/${relativePathToFn}`]: compiledFn,
|
|
114
|
-
'node_modules/jest/package.json': {
|
|
115
|
-
name: 'jest',
|
|
116
|
-
version: '19.0.0'
|
|
117
|
-
},
|
|
118
|
-
'packages/a/package.json': {
|
|
119
|
-
name: 'package-a'
|
|
120
|
-
},
|
|
121
|
-
'packages/b/package.json': {
|
|
122
|
-
name: 'package-b'
|
|
123
|
-
}
|
|
124
|
-
});
|
|
125
|
-
const {
|
|
126
|
-
stdout,
|
|
127
|
-
stderr
|
|
128
|
-
} = runDetectJestVersion(projectDir);
|
|
129
|
-
expect(stdout.trim()).toBe('19');
|
|
130
|
-
expect(stderr.trim()).toBe('');
|
|
131
|
-
});
|
|
132
|
-
});
|
|
133
|
-
describe('when in a subproject', () => {
|
|
134
|
-
it('finds the correct versions', () => {
|
|
135
|
-
const projectDir = setupFakeProject({
|
|
136
|
-
'backend/package.json': {
|
|
137
|
-
name: 'package-a'
|
|
138
|
-
},
|
|
139
|
-
[`backend/node_modules/${relativePathToFn}`]: compiledFn,
|
|
140
|
-
'backend/node_modules/jest/package.json': {
|
|
141
|
-
name: 'jest',
|
|
142
|
-
version: '24.0.0'
|
|
143
|
-
},
|
|
144
|
-
'frontend/package.json': {
|
|
145
|
-
name: 'package-b'
|
|
146
|
-
},
|
|
147
|
-
[`frontend/node_modules/${relativePathToFn}`]: compiledFn,
|
|
148
|
-
'frontend/node_modules/jest/package.json': {
|
|
149
|
-
name: 'jest',
|
|
150
|
-
version: '15.0.0'
|
|
151
|
-
}
|
|
152
|
-
});
|
|
153
|
-
const {
|
|
154
|
-
stdout: stdoutBackend,
|
|
155
|
-
stderr: stderrBackend
|
|
156
|
-
} = runDetectJestVersion(path.join(projectDir, 'backend'));
|
|
157
|
-
expect(stdoutBackend.trim()).toBe('24');
|
|
158
|
-
expect(stderrBackend.trim()).toBe('');
|
|
159
|
-
const {
|
|
160
|
-
stdout: stdoutFrontend,
|
|
161
|
-
stderr: stderrFrontend
|
|
162
|
-
} = runDetectJestVersion(path.join(projectDir, 'frontend'));
|
|
163
|
-
expect(stdoutFrontend.trim()).toBe('15');
|
|
164
|
-
expect(stderrFrontend.trim()).toBe('');
|
|
165
|
-
});
|
|
166
|
-
});
|
|
167
|
-
describe('when jest is not installed', () => {
|
|
168
|
-
it('throws an error', () => {
|
|
169
|
-
const projectDir = setupFakeProject({
|
|
170
|
-
'package.json': {
|
|
171
|
-
name: 'no-jest'
|
|
172
|
-
},
|
|
173
|
-
[`node_modules/${relativePathToFn}`]: compiledFn,
|
|
174
|
-
'node_modules/pack/package.json': {
|
|
175
|
-
name: 'pack'
|
|
176
|
-
}
|
|
177
|
-
});
|
|
178
|
-
const {
|
|
179
|
-
stdout,
|
|
180
|
-
stderr
|
|
181
|
-
} = runDetectJestVersion(projectDir);
|
|
182
|
-
expect(stdout.trim()).toBe('');
|
|
183
|
-
expect(stderr.trim()).toContain('Unable to detect Jest version');
|
|
184
|
-
});
|
|
185
|
-
});
|
|
186
|
-
describe('when jest is changed on disk', () => {
|
|
187
|
-
it('uses the cached version', () => {
|
|
188
|
-
const projectDir = setupFakeProject({
|
|
189
|
-
'package.json': {
|
|
190
|
-
name: 'no-jest'
|
|
191
|
-
},
|
|
192
|
-
[`node_modules/${relativePathToFn}`]: compiledFn,
|
|
193
|
-
'node_modules/jest/package.json': {
|
|
194
|
-
name: 'jest',
|
|
195
|
-
version: '26.0.0'
|
|
196
|
-
}
|
|
197
|
-
});
|
|
198
|
-
const {
|
|
199
|
-
stdout,
|
|
200
|
-
stderr
|
|
201
|
-
} = runNodeScript(projectDir, `
|
|
202
|
-
const { detectJestVersion } = require('${relativePathToFn}');
|
|
203
|
-
const fs = require('fs');
|
|
204
|
-
|
|
205
|
-
console.log(detectJestVersion());
|
|
206
|
-
fs.writeFileSync(
|
|
207
|
-
'node_modules/jest/package.json',
|
|
208
|
-
JSON.stringify({
|
|
209
|
-
name: 'jest',
|
|
210
|
-
version: '25.0.0',
|
|
211
|
-
}),
|
|
212
|
-
);
|
|
213
|
-
console.log(detectJestVersion());
|
|
214
|
-
`);
|
|
215
|
-
const [firstCall, secondCall] = stdout.split('\n');
|
|
216
|
-
expect(firstCall).toBe('26');
|
|
217
|
-
expect(secondCall).toBe('26');
|
|
218
|
-
expect(stderr.trim()).toBe('');
|
|
219
|
-
});
|
|
220
|
-
});
|
|
221
|
-
});
|