UNPKG

1.8 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: [
27 resolve('config/polyfills.js'),
28 resolve('config/jest/setupTests.js')
29 ],
30 setupTestFrameworkScriptFile: setupTestsFile,
31 testPathIgnorePatterns: [
32 '<rootDir>[/\\\\](build|docs|node_modules|scripts)[/\\\\]'
33 ],
34 testEnvironment: 'node',
35 testURL: 'http://localhost',
36 transform: {
37 '^.+\\.(js|jsx)$': isEjecting ?
38 '<rootDir>/node_modules/babel-jest'
39 : resolve('config/jest/babelTransform.js'),
40 '^.+\\.css$': resolve('config/jest/cssTransform.js'),
41 '^(?!.*\\.(js|jsx|css|json)$)': resolve('config/jest/fileTransform.js'),
42 },
43 transformIgnorePatterns: [
44 '[/\\\\]node_modules[/\\\\].+\\.(js|jsx)$'
45 ],
46 moduleNameMapper: {
47 '^react-native$': 'react-native-web'
48 }
49 };
50 if (rootDir) {
51 config.rootDir = rootDir;
52 }
53 return config;
54};