diff --git a/packages/knip/fixtures/plugins/jest2/jest.config.js b/packages/knip/fixtures/plugins/jest2/jest.config.js index cd556eae..3669705e 100644 --- a/packages/knip/fixtures/plugins/jest2/jest.config.js +++ b/packages/knip/fixtures/plugins/jest2/jest.config.js @@ -1,3 +1,5 @@ module.exports = { displayName: 'dev', + testEnvironment: + '/jest.environment.js', }; diff --git a/packages/knip/fixtures/plugins/jest2/jest.environment.js b/packages/knip/fixtures/plugins/jest2/jest.environment.js new file mode 100644 index 00000000..f053ebf7 --- /dev/null +++ b/packages/knip/fixtures/plugins/jest2/jest.environment.js @@ -0,0 +1 @@ +module.exports = {}; diff --git a/packages/knip/src/plugins/jest/index.ts b/packages/knip/src/plugins/jest/index.ts index 583594ef..2bfe0950 100644 --- a/packages/knip/src/plugins/jest/index.ts +++ b/packages/knip/src/plugins/jest/index.ts @@ -58,7 +58,12 @@ const resolveDependencies = async (config: JestInitialOptions, options: PluginOp const runner = config.runner ? [config.runner] : []; const runtime = config.runtime && config.runtime !== 'jest-circus' ? [config.runtime] : []; - const environments = config.testEnvironment === 'jsdom' ? ['jest-environment-jsdom'] : []; + const environments = + config.testEnvironment === 'jsdom' + ? ['jest-environment-jsdom'] + : config.testEnvironment + ? [config.testEnvironment] + : []; const resolvers = config.resolver ? [config.resolver] : []; const reporters = config.reporters ? config.reporters diff --git a/packages/knip/test/plugins/jest2.test.ts b/packages/knip/test/plugins/jest2.test.ts index 66404297..e85de032 100644 --- a/packages/knip/test/plugins/jest2.test.ts +++ b/packages/knip/test/plugins/jest2.test.ts @@ -19,13 +19,16 @@ test('Find dependencies with the Jest plugin', async () => { // to reference the root directory. assert(!issues.files.has(join(cwd, 'project1/setupFiles/setup.js'))); + // Correctly identifies a local `testEnvironment` file. + assert(!issues.files.has(join(cwd, 'jest.environment.js'))); + assert.deepEqual(counters, { ...baseCounters, files: 0, devDependencies: 1, unlisted: 0, unresolved: 0, - processed: 4, - total: 4, + processed: 5, + total: 5, }); });