UNPKG

1.74 kBJavaScriptView Raw
1/**
2 * Copyright (c) 2015-present, Facebook, Inc.
3 * All rights reserved.
4 *
5 * This source code is licensed under the BSD-style license found in the
6 * LICENSE file in the root directory of this source tree. An additional grant
7 * of patent rights can be found in the PATENTS file in the same directory.
8 */
9
10'use strict';
11
12// Note: this file does not exist after ejecting.
13
14const fs = require('fs');
15const paths = require('../config/paths');
16
17module.exports = (resolve, rootDir, isEjecting) => {
18 // Use this instead of `paths.testsSetup` to avoid putting
19 // an absolute filename into configuration after ejecting.
20 const setupTestsFile = fs.existsSync(paths.testsSetup) ? '<rootDir>/src/setupTests.js' : undefined;
21
22 // TODO: I don't know if it's safe or not to just use / as path separator
23 // in Jest configs. We need help from somebody with Windows to determine this.
24 const config = {
25 collectCoverageFrom: ['src/**/*.{js,jsx}'],
26 setupFiles: [resolve('config/polyfills.js')],
27 setupTestFrameworkScriptFile: setupTestsFile,
28 testPathIgnorePatterns: [
29 '<rootDir>[/\\\\](build|docs|node_modules|scripts)[/\\\\]'
30 ],
31 testEnvironment: 'node',
32 testURL: 'http://localhost',
33 transform: {
34 '^.+\\.(js|jsx)$': isEjecting ?
35 '<rootDir>/node_modules/babel-jest'
36 : resolve('config/jest/babelTransform.js'),
37 '^.+\\.css$': resolve('config/jest/cssTransform.js'),
38 '^(?!.*\\.(js|jsx|css|json)$)': resolve('config/jest/fileTransform.js'),
39 },
40 transformIgnorePatterns: [
41 '[/\\\\]node_modules[/\\\\].+\\.(js|jsx)$'
42 ],
43 moduleNameMapper: {
44 '^react-native$': 'react-native-web'
45 }
46 };
47 if (rootDir) {
48 config.rootDir = rootDir;
49 }
50 return config;
51};