Unverified Commit d639e90b authored by Dan Abramov's avatar Dan Abramov Committed by GitHub
Browse files

Work around Jest environment resolving bug (#4247)

parent 609aeea6
13 merge requests!4749replace workspaceRoot with workspaceFolder,!4933Facebook next,!12191Lim.Pisey.168:/Identified - We are currently investigating reports of missing build logs. The issue has been identified and a resolution is in progress. We will provide a further update when available.Mar 21, 09:02 UTC,!12853brikk,!4397Master,!5023Master,!4330Fix broken link,!4886Proper folder structure,!5717Automatically extract project file structure from build bundle file,!4950Master,!5063Babel 7,!4394Patch 1,!4324Fixed typo
Showing with 56 additions and 1 deletion
+56 -1
...@@ -51,6 +51,7 @@ ...@@ -51,6 +51,7 @@
"promise": "8.0.1", "promise": "8.0.1",
"raf": "3.4.0", "raf": "3.4.0",
"react-dev-utils": "^5.0.0", "react-dev-utils": "^5.0.0",
"resolve": "1.6.0",
"style-loader": "0.19.0", "style-loader": "0.19.0",
"sw-precache-webpack-plugin": "0.11.4", "sw-precache-webpack-plugin": "0.11.4",
"url-loader": "0.6.2", "url-loader": "0.6.2",
......
...@@ -24,7 +24,7 @@ process.on('unhandledRejection', err => { ...@@ -24,7 +24,7 @@ process.on('unhandledRejection', err => {
require('../config/env'); require('../config/env');
const jest = require('jest'); const jest = require('jest');
const argv = process.argv.slice(2); let argv = process.argv.slice(2);
// Watch unless on CI or in coverage mode // Watch unless on CI or in coverage mode
if (!process.env.CI && argv.indexOf('--coverage') < 0) { if (!process.env.CI && argv.indexOf('--coverage') < 0) {
...@@ -46,5 +46,59 @@ argv.push( ...@@ -46,5 +46,59 @@ argv.push(
) )
) )
); );
// This is a very dirty workaround for https://github.com/facebook/jest/issues/5913.
// We're trying to resolve the environment ourselves because Jest does it incorrectly.
// TODO: remove this (and the `resolve` dependency) as soon as it's fixed in Jest.
const resolve = require('resolve');
function resolveJestDefaultEnvironment(name) {
const jestDir = path.dirname(
resolve.sync('jest', {
basedir: __dirname,
})
);
const jestCLIDir = path.dirname(
resolve.sync('jest-cli', {
basedir: jestDir,
})
);
const jestConfigDir = path.dirname(
resolve.sync('jest-config', {
basedir: jestCLIDir,
})
);
return resolve.sync(name, {
basedir: jestConfigDir,
});
}
let cleanArgv = [];
let env = 'node';
let next;
do {
next = argv.shift();
if (next === '--env') {
env = argv.shift();
} else if (next.indexOf('--env=') === 0) {
env = next.substring('--env='.length);
} else {
cleanArgv.push(next);
}
} while (argv.length > 0);
argv = cleanArgv;
let resolvedEnv;
try {
resolvedEnv = resolveJestDefaultEnvironment(`jest-environment-${env}`);
} catch (e) {
// ignore
}
if (!resolvedEnv) {
try {
resolvedEnv = resolveJestDefaultEnvironment(env);
} catch (e) {
// ignore
}
}
const testEnvironment = resolvedEnv || env;
argv.push('--env', testEnvironment);
// @remove-on-eject-end // @remove-on-eject-end
jest.run(argv); jest.run(argv);
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment