1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 | 'use strict';
|
10 |
|
11 |
|
12 | process.env.BABEL_ENV = 'test';
|
13 | process.env.NODE_ENV = 'test';
|
14 | process.env.PUBLIC_URL = '';
|
15 |
|
16 |
|
17 |
|
18 |
|
19 | process.on('unhandledRejection', err => {
|
20 | throw err;
|
21 | });
|
22 |
|
23 |
|
24 | require('../config/env');
|
25 |
|
26 |
|
27 | const verifyPackageTree = require('./utils/verifyPackageTree');
|
28 | if (process.env.SKIP_PREFLIGHT_CHECK !== 'true') {
|
29 | verifyPackageTree();
|
30 | }
|
31 |
|
32 |
|
33 | const jest = require('jest');
|
34 | let argv = process.argv.slice(2);
|
35 |
|
36 |
|
37 | if (
|
38 | !process.env.CI &&
|
39 | argv.indexOf('--coverage') === -1 &&
|
40 | argv.indexOf('--watchAll') === -1
|
41 | ) {
|
42 | argv.push('--watch');
|
43 | }
|
44 |
|
45 |
|
46 |
|
47 | const createJestConfig = require('./utils/createJestConfig');
|
48 | const path = require('path');
|
49 | const paths = require('../config/paths');
|
50 | argv.push(
|
51 | '--config',
|
52 | JSON.stringify(
|
53 | createJestConfig(
|
54 | relativePath => path.resolve(__dirname, '..', relativePath),
|
55 | path.resolve(paths.appSrc, '..'),
|
56 | false
|
57 | )
|
58 | )
|
59 | );
|
60 |
|
61 |
|
62 |
|
63 |
|
64 | const resolve = require('resolve');
|
65 | function resolveJestDefaultEnvironment(name) {
|
66 | const jestDir = path.dirname(
|
67 | resolve.sync('jest', {
|
68 | basedir: __dirname,
|
69 | })
|
70 | );
|
71 | const jestCLIDir = path.dirname(
|
72 | resolve.sync('jest-cli', {
|
73 | basedir: jestDir,
|
74 | })
|
75 | );
|
76 | const jestConfigDir = path.dirname(
|
77 | resolve.sync('jest-config', {
|
78 | basedir: jestCLIDir,
|
79 | })
|
80 | );
|
81 | return resolve.sync(name, {
|
82 | basedir: jestConfigDir,
|
83 | });
|
84 | }
|
85 | let cleanArgv = [];
|
86 | let env = 'jsdom';
|
87 | let next;
|
88 | do {
|
89 | next = argv.shift();
|
90 | if (next === '--env') {
|
91 | env = argv.shift();
|
92 | } else if (next.indexOf('--env=') === 0) {
|
93 | env = next.substring('--env='.length);
|
94 | } else {
|
95 | cleanArgv.push(next);
|
96 | }
|
97 | } while (argv.length > 0);
|
98 | argv = cleanArgv;
|
99 | let resolvedEnv;
|
100 | try {
|
101 | resolvedEnv = resolveJestDefaultEnvironment(`jest-environment-${env}`);
|
102 | } catch (e) {
|
103 |
|
104 | }
|
105 | if (!resolvedEnv) {
|
106 | try {
|
107 | resolvedEnv = resolveJestDefaultEnvironment(env);
|
108 | } catch (e) {
|
109 |
|
110 | }
|
111 | }
|
112 | const testEnvironment = resolvedEnv || env;
|
113 | argv.push('--env', testEnvironment);
|
114 |
|
115 | jest.run(argv);
|