Skip to content

Commit 153a836

Browse files
authoredNov 13, 2024··
jest: support custom testEnvironment (#834)
1 parent 9730d02 commit 153a836

File tree

4 files changed

+14
-3
lines changed

4 files changed

+14
-3
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
module.exports = {
22
displayName: 'dev',
3+
testEnvironment:
4+
'<rootDir>/jest.environment.js',
35
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = {};

‎packages/knip/src/plugins/jest/index.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,12 @@ const resolveDependencies = async (config: JestInitialOptions, options: PluginOp
5858

5959
const runner = config.runner ? [config.runner] : [];
6060
const runtime = config.runtime && config.runtime !== 'jest-circus' ? [config.runtime] : [];
61-
const environments = config.testEnvironment === 'jsdom' ? ['jest-environment-jsdom'] : [];
61+
const environments =
62+
config.testEnvironment === 'jsdom'
63+
? ['jest-environment-jsdom']
64+
: config.testEnvironment
65+
? [config.testEnvironment]
66+
: [];
6267
const resolvers = config.resolver ? [config.resolver] : [];
6368
const reporters = config.reporters
6469
? config.reporters

‎packages/knip/test/plugins/jest2.test.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,16 @@ test('Find dependencies with the Jest plugin', async () => {
1919
// <rootDir> to reference the root directory.
2020
assert(!issues.files.has(join(cwd, 'project1/setupFiles/setup.js')));
2121

22+
// Correctly identifies a local `testEnvironment` file.
23+
assert(!issues.files.has(join(cwd, 'jest.environment.js')));
24+
2225
assert.deepEqual(counters, {
2326
...baseCounters,
2427
files: 0,
2528
devDependencies: 1,
2629
unlisted: 0,
2730
unresolved: 0,
28-
processed: 4,
29-
total: 4,
31+
processed: 5,
32+
total: 5,
3033
});
3134
});

0 commit comments

Comments
 (0)
Please sign in to comment.