Skip to content

Commit

Permalink
Support rootDir tag in testEnvironment (#4579)
Browse files Browse the repository at this point in the history
  • Loading branch information
thymikee authored and cpojer committed Oct 2, 2017
1 parent b430e51 commit d355b3b
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
15 changes: 15 additions & 0 deletions packages/jest-config/src/__tests__/normalize.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -583,6 +583,9 @@ describe('testEnvironment', () => {
if (name === 'jest-environment-jsdom') {
return 'node_modules/jest-environment-jsdom';
}
if (name.startsWith('/root')) {
return name;
}
return findNodeModule(name);
});
});
Expand Down Expand Up @@ -612,6 +615,18 @@ describe('testEnvironment', () => {
),
).toThrowErrorMatchingSnapshot();
});

it('works with rootDir', () => {
const {options} = normalize(
{
rootDir: '/root',
testEnvironment: '<rootDir>/testEnvironment.js',
},
{},
);

expect(options.testEnvironment).toEqual('/root/testEnvironment.js');
});
});

describe('babel-jest', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-config/src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ export const _replaceRootDirTags = (rootDir: string, config: any) => {
* 1. looks for <name> relative to Jest.
*/
export const getTestEnvironment = (config: Object) => {
const env = config.testEnvironment;
const env = _replaceRootDirInPath(config.rootDir, config.testEnvironment);
let module = Resolver.findNodeModule(`jest-environment-${env}`, {
basedir: config.rootDir,
});
Expand Down
2 changes: 1 addition & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5837,7 +5837,7 @@ typedarray@^0.0.6, typedarray@~0.0.5:
version "0.0.6"
resolved "https://registry.yarnpkg.com/typedarray/-/typedarray-0.0.6.tgz#867ac74e3864187b1d3d47d996a78ec5c8830777"

typescript@^2.5.3:
typescript@^2.2.2, typescript@^2.5.3:
version "2.5.3"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-2.5.3.tgz#df3dcdc38f3beb800d4bc322646b04a3f6ca7f0d"

Expand Down

0 comments on commit d355b3b

Please sign in to comment.