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