createJestConfig.js 1.5 KB
Newer Older
Christoph Pojer's avatar
Christoph Pojer committed
1
2
3
4
5
6
7
8
/**
 * 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.
 */
9
10

// Note: this file does not exist after ejecting.
Christoph Pojer's avatar
Christoph Pojer committed
11

12
const pathExists = require('path-exists');
13
const paths = require('../config/paths');
14

15
module.exports = (resolve, rootDir, isEjecting) => {
16
17
  const setupFiles = [resolve('config/polyfills.js')];
  if (pathExists.sync(paths.testsSetup)) {
18
19
20
    // Use this instead of `paths.testsSetup` to avoid putting
    // an absolute filename into configuration after ejecting.
    setupFiles.push('<rootDir>/src/setupTests.js');
21
22
  }

Christoph Pojer's avatar
Christoph Pojer committed
23
  const config = {
24
    moduleFileExtensions: ['jsx', 'js', 'json'],
Christoph Pojer's avatar
Christoph Pojer committed
25
    moduleNameMapper: {
Dan Harper's avatar
Dan Harper committed
26
      '^.+\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$': resolve('config/jest/FileStub.js'),
27
      '^.+\\.css$': resolve('config/jest/CSSStub.js')
Christoph Pojer's avatar
Christoph Pojer committed
28
    },
29
    setupFiles: setupFiles,
Dan Abramov's avatar
Dan Abramov committed
30
    testPathIgnorePatterns: ['<rootDir>/(build|docs|node_modules)/'],
31
32
    testEnvironment: 'node',
    testRegex: '(/__tests__/.*|\\.(test|spec))\\.(js|jsx)$',
Christoph Pojer's avatar
Christoph Pojer committed
33
34
35
36
  };
  if (rootDir) {
    config.rootDir = rootDir;
  }
37
38
39
40
41
  if (!isEjecting) {
    // This is unnecessary after ejecting because Jest
    // will just use .babelrc in the project folder.
    config.scriptPreprocessor = resolve('config/jest/transform.js');
  }
Christoph Pojer's avatar
Christoph Pojer committed
42
43
  return config;
};