UNPKG

1.99 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// Note: this file does not exist after ejecting.
11
12const fs = require('fs');
13const paths = require('../config/paths');
14
15module.exports = (resolve, rootDir, isEjecting) => {
16 // Use this instead of `paths.testsSetup` to avoid putting
17 // an absolute filename into configuration after ejecting.
18 const setupTestsFile = fs.existsSync(paths.testsSetup) ? `<rootDir>/src/setupTests${path.extname(paths.testsSetup)}` : undefined;
19
20 // TODO: I don't know if it's safe or not to just use / as path separator
21 // in Jest configs. We need help from somebody with Windows to determine this.
22 const config = {
23 collectCoverageFrom: ['src/**/*.{ts,tsx,js,jsx}'],
24 setupFiles: [resolve('config/polyfills.js')],
25 setupTestFrameworkScriptFile: setupTestsFile,
26 testPathIgnorePatterns: [
27 '<rootDir>[/\\\\](build|docs|node_modules|scripts)[/\\\\]'
28 ],
29 testEnvironment: 'node',
30 testURL: 'http://localhost',
31 transform: {
32 '^.+\\.(ts|tsx)$': '<rootDir>/node_modules/ts-jest/preprocessor.js',
33 '^.+\\.(js|jsx)$': isEjecting ?
34 '<rootDir>/node_modules/babel-jest'
35 : resolve('config/jest/babelTransform.js'),
36 '^.+\\.(scss|css)$': resolve('config/jest/cssTransform.js'),
37 '^(?!.*\\.(ts|tsx|js|jsx|scss|css|json)$)': resolve('config/jest/fileTransform.js'),
38 },
39 transformIgnorePatterns: [
40 '[/\\\\]node_modules[/\\\\].+\\.(js|jsx)$'
41 ],
42 moduleNameMapper: {
43 '^react-native$': 'react-native-web'
44 },
45 moduleFileExtensions: ['js', 'jsx', 'json', 'ts', 'tsx'],
46 testRegex: '(/__tests__/.*|\\.(test|spec))\\.(ts|tsx|js|jsx)$'
47 };
48 if (rootDir) {
49 config.rootDir = rootDir;
50 }
51 return config;
52};