forked from prettier/prettier
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjest.config.js
More file actions
126 lines (118 loc) · 4.32 KB
/
jest.config.js
File metadata and controls
126 lines (118 loc) · 4.32 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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
import path from "node:path";
import createEsmUtils from "esm-utils";
import installBrowser from "./tests/config/install-browser.js";
import installPrettier from "./tests/config/install-prettier.js";
const { dirname: PROJECT_ROOT } = createEsmUtils(import.meta);
const isProduction = process.env.NODE_ENV === "production";
// Disabled https://github.com/nicolo-ribaudo/jest-light-runner/pull/13
// 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 TEST_RUNTIME = process.env.TEST_RUNTIME ?? "nodejs";
// When debugging production test, this flag can skip installing package
const SKIP_PRODUCTION_INSTALL = Boolean(process.env.SKIP_PRODUCTION_INSTALL);
const nodejsMajorVersion = Number(process.versions.node.split(".")[0]);
let PRETTIER_DIR = isProduction
? path.join(PROJECT_ROOT, "dist/prettier")
: PROJECT_ROOT;
let PRETTIER_INSTALLED_DIR = "";
if (
INSTALL_PACKAGE ||
(isProduction &&
!TEST_STANDALONE &&
!SKIP_PRODUCTION_INSTALL &&
TEST_RUNTIME === "nodejs")
) {
PRETTIER_INSTALLED_DIR = installPrettier(PRETTIER_DIR);
PRETTIER_DIR = path.join(PRETTIER_INSTALLED_DIR, "node_modules/prettier");
}
if (TEST_RUNTIME === "browser") {
installBrowser();
}
process.env.PRETTIER_INSTALLED_DIR = PRETTIER_INSTALLED_DIR;
process.env.PRETTIER_DIR = PRETTIER_DIR;
const testPathIgnorePatterns = [];
if (TEST_STANDALONE || TEST_RUNTIME !== "nodejs") {
testPathIgnorePatterns.push("tests/integration/");
}
if (isProduction) {
// Only run unit test for development
testPathIgnorePatterns.push("tests/unit/");
} else {
// Only test bundles for production
testPathIgnorePatterns.push("tests/integration/__tests__/bundle.js");
}
// Currently can't load plugins in browser
if (TEST_RUNTIME === "browser") {
testPathIgnorePatterns.push(
"tests/format/misc/front-matter/with-plugins/format.test.js",
"tests/format/misc/plugins/embed-async-printer/format.test.js",
"tests/format/misc/_errors_/broken-plugin/format.test.js",
"tests/format/vue/with-plugins/format.test.js",
"tests/format/misc/plugins/async-printer/format.test.js",
"tests/format/handlebars/front-matter/toml/format.test.js",
"tests/format/markdown/broken-plugins/format.test.js",
"tests/format/vue/broken-plugins/format.test.js",
);
}
if (nodejsMajorVersion <= 18) {
// Uses import attributes and `Array#toSorted()`
testPathIgnorePatterns.push("tests/integration/__tests__/help-options.js");
}
if (nodejsMajorVersion <= 14) {
testPathIgnorePatterns.push(
"tests/integration/__tests__/plugin-parsers.js",
"tests/integration/__tests__/normalize-doc.js",
"tests/integration/__tests__/doc-utilities-clean-doc.js",
"tests/integration/__tests__/config-invalid.js",
// `@prettier/cli` uses `node:stream/consumers`, not available on Node.js v14
"tests/integration/__tests__/experimental-cli.js",
// Fails on Node.js v14
"tests/dts/unit/run.js",
);
}
const config = {
setupFiles: [
"<rootDir>/tests/config/format-test-setup.js",
"<rootDir>/tests/integration/integration-test-setup.js",
],
runner: "jest-light-runner/child-process",
testEnvironmentOptions: {
customExportConditions: ["development"],
},
snapshotSerializers: [
"jest-snapshot-serializer-raw",
"jest-snapshot-serializer-ansi",
],
testMatch: [
"<rootDir>/tests/format/**/format.test.js",
"<rootDir>/tests/integration/__tests__/**/*.js",
"<rootDir>/tests/unit/**/*.js",
"<rootDir>/tests/dts/unit/**/*.js",
],
testPathIgnorePatterns: testPathIgnorePatterns.map(
(file) => `<rootDir>/${file}`,
),
// collectCoverage: ENABLE_CODE_COVERAGE,
collectCoverageFrom: ["<rootDir>/src/**/*.js", "<rootDir>/bin/**/*.js"],
coveragePathIgnorePatterns: [
"<rootDir>/src/standalone.js",
"<rootDir>/src/document/debug.js",
],
coverageReporters: ["text", "lcov"],
moduleNameMapper: {
"prettier-local": "<rootDir>/tests/config/prettier-entry.js",
"prettier-standalone": "<rootDir>/tests/config/require-standalone.cjs",
},
modulePathIgnorePatterns: [
"<rootDir>/dist",
"<rootDir>/website",
"<rootDir>/scripts/release",
],
transform: {},
watchPlugins: [
"jest-watch-typeahead/filename",
"jest-watch-typeahead/testname",
],
};
export default config;