-
-
Notifications
You must be signed in to change notification settings - Fork 153
Expand file tree
/
Copy pathcreateJestConfig.js
More file actions
104 lines (96 loc) · 2.94 KB
/
createJestConfig.js
File metadata and controls
104 lines (96 loc) · 2.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/* eslint-disable */
/**
* Based on https://github.com/facebook/create-react-app/blob/master/packages/react-scripts/scripts/utils/createJestConfig.js
*/
"use strict";
const fs = require("fs");
const chalk = require("chalk");
const paths = require("./paths");
module.exports = (resolve, rootDir) => {
const config = {
collectCoverageFrom: ["./**/*.{js,jsx,ts,tsx}"],
preset: "ts-jest",
globals: {
"ts-jest": {
babelConfig: {
presets: [require.resolve("@babel/preset-env")]
}
}
},
setupFiles: [
require.resolve("core-js/stable"),
require.resolve("regenerator-runtime/runtime")
],
testMatch: [
"<rootDir>/**/__tests__/**/*.{js,jsx,ts,tsx}",
"<rootDir>/**/*.{spec,test}.{js,jsx,ts,tsx}"
],
transform: {
"^.+\\.(js|jsx)$": resolve("scripts/config/babelJestTransform.js")
},
transformIgnorePatterns: ["[/\\\\]node_modules[/\\\\].+\\.(js|jsx|ts|tsx)$"]
};
if (rootDir) {
config.rootDir = rootDir;
}
const overrides = Object.assign({}, require(paths.appPackageJson).jest);
const supportedKeys = [
"collectCoverageFrom",
"coverageReporters",
"coverageThreshold",
"extraGlobals",
"globalSetup",
"globalTeardown",
"reporters",
"resetMocks",
"resetModules",
"setupFilesAfterEnv",
"snapshotSerializers",
"testResultsProcessor",
"transform",
"transformIgnorePatterns",
"watchPathIgnorePatterns",
"moduleNameMapper",
"moduleDirectories"
];
if (overrides) {
supportedKeys.forEach(key => {
if (overrides.hasOwnProperty(key)) {
if (Array.isArray(config[key]) || typeof config[key] !== "object") {
// for arrays or primitive types, directly override the config key
config[key] = overrides[key];
} else {
// for object types, extend gracefully
config[key] = Object.assign({}, config[key], overrides[key]);
}
delete overrides[key];
}
});
const unsupportedKeys = Object.keys(overrides);
if (unsupportedKeys.length) {
const isOverridingSetupFile =
unsupportedKeys.indexOf("setupFilesAfterEnv") > -1;
console.error(
chalk.red(
"\nOut of the box, serverless-bundle only supports overriding " +
"these Jest options:\n\n" +
supportedKeys.map(key => chalk.bold(" \u2022 " + key)).join("\n") +
".\n\n" +
"These options in your package.json Jest configuration " +
"are not currently supported by serverless-bundle:\n\n" +
unsupportedKeys
.map(key => chalk.bold(" \u2022 " + key))
.join("\n") +
"\n\nIf you wish to override other Jest options, " +
"consider using serverless-webpack directly instead.\n"
)
);
process.exit(1);
}
}
// Include dotenv env variables
require("dotenv").config({
path: "./.env"
});
return config;
};