createJestConfig.js 1.68 KB
Newer Older
Daniel Grant's avatar
Daniel Grant committed
1
// @remove-file-on-eject
Christoph Pojer's avatar
Christoph Pojer committed
2
3
4
5
6
7
8
9
/**
 * Copyright (c) 2015-present, Facebook, Inc.
 * All rights reserved.
 *
 * This source code is licensed under the BSD-style license found in the
 * LICENSE file in the root directory of this source tree. An additional grant
 * of patent rights can be found in the PATENTS file in the same directory.
 */
10

11
12
'use strict';

13
const fs = require('fs');
Daniel Grant's avatar
Daniel Grant committed
14
const paths = require('../../config/paths');
15

16
module.exports = (resolve, rootDir, isEjecting) => {
17
18
  // Use this instead of `paths.testsSetup` to avoid putting
  // an absolute filename into configuration after ejecting.
19
  const setupTestsFile = fs.existsSync(paths.testsSetup) ? '<rootDir>/src/setupTests.js' : undefined;
20

21
22
  // TODO: I don't know if it's safe or not to just use / as path separator
  // in Jest configs. We need help from somebody with Windows to determine this.
Christoph Pojer's avatar
Christoph Pojer committed
23
  const config = {
24
    collectCoverageFrom: ['src/**/*.{js,jsx}'],
25
26
    setupFiles: [resolve('config/polyfills.js')],
    setupTestFrameworkScriptFile: setupTestsFile,
27
    testPathIgnorePatterns: [
28
      '<rootDir>[/\\\\](build|docs|node_modules|scripts)[/\\\\]'
29
    ],
30
    testEnvironment: 'node',
31
    testURL: 'http://localhost',
32
33
34
35
36
37
38
39
40
41
    transform: {
      '^.+\\.(js|jsx)$': isEjecting ?
        '<rootDir>/node_modules/babel-jest'
        : resolve('config/jest/babelTransform.js'),
      '^.+\\.css$': resolve('config/jest/cssTransform.js'),
      '^(?!.*\\.(js|jsx|css|json)$)': resolve('config/jest/fileTransform.js'),
    },
    transformIgnorePatterns: [
      '[/\\\\]node_modules[/\\\\].+\\.(js|jsx)$'
    ],
42
43
44
    moduleNameMapper: {
      '^react-native$': 'react-native-web'
    }
Christoph Pojer's avatar
Christoph Pojer committed
45
46
47
48
49
50
  };
  if (rootDir) {
    config.rootDir = rootDir;
  }
  return config;
};