source: frontend/node_modules/react-scripts/scripts/test.js

Last change on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 11 days ago

Fix frontend appearance

  • Property mode set to 100644
File size: 3.3 KB
RevLine 
[9af201e]1// @remove-on-eject-begin
2/**
3 * Copyright (c) 2015-present, Facebook, Inc.
4 *
5 * This source code is licensed under the MIT license found in the
6 * LICENSE file in the root directory of this source tree.
7 */
8// @remove-on-eject-end
9'use strict';
10
11// Do this as the first thing so that any code reading it knows the right env.
12process.env.BABEL_ENV = 'test';
13process.env.NODE_ENV = 'test';
14process.env.PUBLIC_URL = '';
15
16// Makes the script crash on unhandled rejections instead of silently
17// ignoring them. In the future, promise rejections that are not handled will
18// terminate the Node.js process with a non-zero exit code.
19process.on('unhandledRejection', err => {
20 throw err;
21});
22
23// Ensure environment variables are read.
24require('../config/env');
25
26const jest = require('jest');
27const execSync = require('child_process').execSync;
28let argv = process.argv.slice(2);
29
30function isInGitRepository() {
31 try {
32 execSync('git rev-parse --is-inside-work-tree', { stdio: 'ignore' });
33 return true;
34 } catch (e) {
35 return false;
36 }
37}
38
39function isInMercurialRepository() {
40 try {
41 execSync('hg --cwd . root', { stdio: 'ignore' });
42 return true;
43 } catch (e) {
44 return false;
45 }
46}
47
48// Watch unless on CI or explicitly running all tests
49if (
50 !process.env.CI &&
51 argv.indexOf('--watchAll') === -1 &&
52 argv.indexOf('--watchAll=false') === -1
53) {
54 // https://github.com/facebook/create-react-app/issues/5210
55 const hasSourceControl = isInGitRepository() || isInMercurialRepository();
56 argv.push(hasSourceControl ? '--watch' : '--watchAll');
57}
58
59// @remove-on-eject-begin
60// This is not necessary after eject because we embed config into package.json.
61const createJestConfig = require('./utils/createJestConfig');
62const path = require('path');
63const paths = require('../config/paths');
64argv.push(
65 '--config',
66 JSON.stringify(
67 createJestConfig(
68 relativePath => path.resolve(__dirname, '..', relativePath),
69 path.resolve(paths.appSrc, '..'),
70 false
71 )
72 )
73);
74
75// This is a very dirty workaround for https://github.com/facebook/jest/issues/5913.
76// We're trying to resolve the environment ourselves because Jest does it incorrectly.
77// TODO: remove this as soon as it's fixed in Jest.
78const resolve = require('resolve');
79function resolveJestDefaultEnvironment(name) {
80 const jestDir = path.dirname(
81 resolve.sync('jest', {
82 basedir: __dirname,
83 })
84 );
85 const jestCLIDir = path.dirname(
86 resolve.sync('jest-cli', {
87 basedir: jestDir,
88 })
89 );
90 const jestConfigDir = path.dirname(
91 resolve.sync('jest-config', {
92 basedir: jestCLIDir,
93 })
94 );
95 return resolve.sync(name, {
96 basedir: jestConfigDir,
97 });
98}
99let cleanArgv = [];
100let env = 'jsdom';
101let next;
102do {
103 next = argv.shift();
104 if (next === '--env') {
105 env = argv.shift();
106 } else if (next.indexOf('--env=') === 0) {
107 env = next.substring('--env='.length);
108 } else {
109 cleanArgv.push(next);
110 }
111} while (argv.length > 0);
112argv = cleanArgv;
113let resolvedEnv;
114try {
115 resolvedEnv = resolveJestDefaultEnvironment(`jest-environment-${env}`);
116} catch (e) {
117 // ignore
118}
119if (!resolvedEnv) {
120 try {
121 resolvedEnv = resolveJestDefaultEnvironment(env);
122 } catch (e) {
123 // ignore
124 }
125}
126const testEnvironment = resolvedEnv || env;
127argv.push('--env', testEnvironment);
128// @remove-on-eject-end
129jest.run(argv);
Note: See TracBrowser for help on using the repository browser.