-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest.js
51 lines (40 loc) · 1.23 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
process.env.BABEL_ENV = 'test';
process.env.NODE_ENV = 'test';
process.env.PUBLIC_URL = '';
require('react-scripts/config/env');
const patchModule = require('./utils/cache');
const fs = require('fs-extra');
const path = require('path');
const chalk = require('chalk');
const appPath = require('react-scripts/config/paths').appPath;
const webpackMonkeyPath = path.resolve(appPath, 'webpack.monkey.js');
require('react-scripts/config/jest/babelTransform.js')
if (fs.existsSync(webpackMonkeyPath)) {
console.log(chalk.yellow('WARNING! .babelrc file is enabled!'));
const babelJest = require('babel-jest').default;
const hasJsxRuntime = (() => {
if (process.env.DISABLE_NEW_JSX_TRANSFORM === 'true') {
return false;
}
try {
require.resolve('react/jsx-runtime');
return true;
} catch (e) {
return false;
}
})();
const babelTransform = babelJest.createTransformer({
presets: [
[
require.resolve('babel-preset-react-app'),
{
runtime: hasJsxRuntime ? 'automatic' : 'classic',
},
],
],
babelrc: true,
configFile: false,
});
patchModule('react-scripts/config/jest/babelTransform.js', babelTransform);
}
require('react-scripts/scripts/test');