Skip to content

Commit

Permalink
Merge pull request #1580 from cpojer/master
Browse files Browse the repository at this point in the history
Fix test environment resolution.
  • Loading branch information
cpojer committed Sep 2, 2016
2 parents 813de84 + 8b6d0a1 commit 06033a1
Showing 1 changed file with 12 additions and 4 deletions.
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

0 comments on commit 06033a1

Please sign in to comment.