Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix test environment resolution. #1580

Merged
merged 1 commit into from
Sep 2, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions packages/jest-config/src/normalize.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,14 @@ function _replaceRootDirTags(rootDir, config) {
return config;
}

/**
* Finds the test environment to use:
*
* 1. looks for jest-environment-<name> relative to project.
* 1. looks for jest-environment-<name> relative to Jest.
* 1. looks for <name> relative to project.
* 1. looks for <name> relative to Jest.
*/
function getTestEnvironment(config) {
const env = config.testEnvironment;
let module = Resolver.findNodeModule(`jest-environment-${env}`, {
Expand All @@ -84,15 +92,15 @@ function getTestEnvironment(config) {
return module;
}

try {
return require.resolve(`jest-environment-${env}`);
} catch (e) {}

module = Resolver.findNodeModule(env, {basedir: config.rootDir});
if (module) {
return module;
}

try {
return require.resolve(`jest-environment-${env}`);
} catch (e) {}

try {
return require.resolve(env);
} catch (e) {}
Expand Down