forked from prettier/prettier
-
Notifications
You must be signed in to change notification settings - Fork 0
/
jest.config.js
97 lines (91 loc) · 2.66 KB
/
jest.config.js
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
"use strict";
const path = require("path");
const installPrettier = require("./tests/config/install-prettier.js");
const PROJECT_ROOT = __dirname;
const isProduction = process.env.NODE_ENV === "production";
const ENABLE_CODE_COVERAGE = Boolean(process.env.ENABLE_CODE_COVERAGE);
const TEST_STANDALONE = Boolean(process.env.TEST_STANDALONE);
const INSTALL_PACKAGE = Boolean(process.env.INSTALL_PACKAGE);
const SKIP_TESTS_WITH_NEW_SYNTAX =
process.versions.node.startsWith("10.") ||
process.versions.node.startsWith("12.");
let PRETTIER_DIR = isProduction
? path.join(PROJECT_ROOT, "dist")
: PROJECT_ROOT;
if (INSTALL_PACKAGE || (isProduction && !TEST_STANDALONE)) {
PRETTIER_DIR = installPrettier(PRETTIER_DIR);
}
process.env.PRETTIER_DIR = PRETTIER_DIR;
const testPathIgnorePatterns = [];
let transform = {};
if (TEST_STANDALONE) {
testPathIgnorePatterns.push("<rootDir>/tests/integration/");
}
if (isProduction) {
// `esm` bundles need transform
transform = {
"(?:\\.mjs|codeSamples\\.js)$": [
"babel-jest",
{
presets: [
[
"@babel/env",
{
targets: { node: "current" },
exclude: [
"transform-async-to-generator",
"transform-classes",
"proposal-async-generator-functions",
"transform-regenerator",
],
},
],
],
},
],
};
} else {
// Only test bundles for production
testPathIgnorePatterns.push(
"<rootDir>/tests/integration/__tests__/bundle.js"
);
}
if (SKIP_TESTS_WITH_NEW_SYNTAX) {
testPathIgnorePatterns.push(
"<rootDir>/tests/integration/__tests__/help-options.js"
);
}
module.exports = {
setupFiles: ["<rootDir>/tests/config/setup.js"],
snapshotSerializers: [
"jest-snapshot-serializer-raw",
"jest-snapshot-serializer-ansi",
],
snapshotFormat: {
escapeString: false,
printBasicPrototype: false,
},
testRegex: "jsfmt\\.spec\\.js$|__tests__/.*\\.js$",
testPathIgnorePatterns,
collectCoverage: ENABLE_CODE_COVERAGE,
collectCoverageFrom: ["<rootDir>/src/**/*.js", "<rootDir>/bin/**/*.js"],
coveragePathIgnorePatterns: [
"<rootDir>/src/standalone.js",
"<rootDir>/src/document/doc-debug.js",
],
coverageReporters: ["text", "lcov"],
moduleNameMapper: {
"prettier-local": "<rootDir>/tests/config/require-prettier.js",
"prettier-standalone": "<rootDir>/tests/config/require-standalone.js",
},
modulePathIgnorePatterns: [
"<rootDir>/dist",
"<rootDir>/website",
"<rootDir>/scripts/release",
],
transform,
watchPlugins: [
"jest-watch-typeahead/filename",
"jest-watch-typeahead/testname",
],
};