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
18
  // Use this instead of `paths.testsSetup` to avoid putting
  // an absolute filename into configuration after ejecting.
  const setupTestsFile = pathExists.sync(paths.testsSetup) ? '<rootDir>/src/setupTests.js' : undefined;
19

Christoph Pojer's avatar
Christoph Pojer committed
20
  const config = {
21
    collectCoverageFrom: ['src/**/*.{js,jsx}'],
22
    moduleFileExtensions: ['jsx', 'js', 'json'],
Christoph Pojer's avatar
Christoph Pojer committed
23
    moduleNameMapper: {
24
      '^.+\\.(ico|jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$': resolve('config/jest/FileStub.js'),
25
      '^.+\\.css$': resolve('config/jest/CSSStub.js')
Christoph Pojer's avatar
Christoph Pojer committed
26
    },
27
28
    setupFiles: [resolve('config/polyfills.js')],
    setupTestFrameworkScriptFile: setupTestsFile,
Dan Abramov's avatar
Dan Abramov committed
29
    testPathIgnorePatterns: ['<rootDir>/(build|docs|node_modules)/'],
30
    testEnvironment: 'node',
Christoph Pojer's avatar
Christoph Pojer committed
31
32
33
34
  };
  if (rootDir) {
    config.rootDir = rootDir;
  }
35
36
37
38
39
  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
40
41
  return config;
};