createJestConfig.js 2.05 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
'use strict';

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

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

22
23
  // 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
24
  const config = {
25
    collectCoverageFrom: ['src/**/*.{js,jsx}'],
26
27
    setupFiles: [resolve('config/polyfills.js')],
    setupTestFrameworkScriptFile: setupTestsFile,
28
    testPathIgnorePatterns: [
29
30
31
32
33
34
35
36
37
38
39
40
      // Ignore the following directories:
      // build
      //   - the build output directory
      // .cache
      //   - the yarn module cache on Ubuntu if $HOME === rootDir
      // docs
      //   - often used to publish to Github Pages
      // node_modules
      //   - ignore tests in dependencies
      // scripts
      //   - directory generated upon eject
      '<rootDir>[/\\\\](build|\\.cache|docs|node_modules|scripts)[/\\\\]',
41
    ],
42
    testEnvironment: 'node',
43
    testURL: 'http://localhost',
44
    transform: {
45
46
      '^.+\\.(js|jsx)$': isEjecting
        ? '<rootDir>/node_modules/babel-jest'
47
48
49
50
        : resolve('config/jest/babelTransform.js'),
      '^.+\\.css$': resolve('config/jest/cssTransform.js'),
      '^(?!.*\\.(js|jsx|css|json)$)': resolve('config/jest/fileTransform.js'),
    },
51
    transformIgnorePatterns: ['[/\\\\]node_modules[/\\\\].+\\.(js|jsx)$'],
52
    moduleNameMapper: {
53
54
      '^react-native$': 'react-native-web',
    },
Christoph Pojer's avatar
Christoph Pojer committed
55
56
57
58
59
60
  };
  if (rootDir) {
    config.rootDir = rootDir;
  }
  return config;
};