2021-11-29 10:07:11 +08:00
|
|
|
import path from "node:path";
|
|
|
|
|
import createEsmUtils from "esm-utils";
|
2022-01-04 17:00:25 +08:00
|
|
|
import installPrettier from "./tests/config/install-prettier.js";
|
2020-04-18 01:24:22 +08:00
|
|
|
|
2021-11-29 10:07:11 +08:00
|
|
|
const { dirname: PROJECT_ROOT } = createEsmUtils(import.meta);
|
2020-09-17 01:08:44 +09:00
|
|
|
const isProduction = process.env.NODE_ENV === "production";
|
2021-02-01 13:14:04 +08:00
|
|
|
const ENABLE_CODE_COVERAGE = Boolean(process.env.ENABLE_CODE_COVERAGE);
|
2021-02-11 00:50:59 +08:00
|
|
|
const TEST_STANDALONE = Boolean(process.env.TEST_STANDALONE);
|
|
|
|
|
const INSTALL_PACKAGE = Boolean(process.env.INSTALL_PACKAGE);
|
2022-04-25 14:28:27 +08:00
|
|
|
const SKIP_TESTS_WITH_NEW_SYNTAX = process.versions.node.startsWith("12.");
|
2021-02-11 00:50:59 +08:00
|
|
|
|
|
|
|
|
let PRETTIER_DIR = isProduction
|
|
|
|
|
? path.join(PROJECT_ROOT, "dist")
|
|
|
|
|
: PROJECT_ROOT;
|
|
|
|
|
if (INSTALL_PACKAGE || (isProduction && !TEST_STANDALONE)) {
|
|
|
|
|
PRETTIER_DIR = installPrettier(PRETTIER_DIR);
|
2020-04-18 01:24:22 +08:00
|
|
|
}
|
2021-02-11 00:50:59 +08:00
|
|
|
process.env.PRETTIER_DIR = PRETTIER_DIR;
|
2017-07-16 21:49:37 +10:00
|
|
|
|
2020-09-17 01:08:44 +09:00
|
|
|
const testPathIgnorePatterns = [];
|
|
|
|
|
if (TEST_STANDALONE) {
|
|
|
|
|
testPathIgnorePatterns.push("<rootDir>/tests/integration/");
|
|
|
|
|
}
|
2021-12-02 10:19:32 +08:00
|
|
|
if (!isProduction) {
|
2020-09-17 01:08:44 +09:00
|
|
|
// Only test bundles for production
|
|
|
|
|
testPathIgnorePatterns.push(
|
|
|
|
|
"<rootDir>/tests/integration/__tests__/bundle.js"
|
|
|
|
|
);
|
|
|
|
|
}
|
2022-04-22 20:51:41 +08:00
|
|
|
if (SKIP_TESTS_WITH_NEW_SYNTAX) {
|
|
|
|
|
testPathIgnorePatterns.push(
|
2022-04-27 17:34:29 +08:00
|
|
|
"<rootDir>/tests/integration/__tests__/help-options.js",
|
|
|
|
|
"<rootDir>/tests/format/misc/empty/jsfmt.spec.js"
|
2022-04-22 20:51:41 +08:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-29 10:07:11 +08:00
|
|
|
const config = {
|
2022-01-12 08:47:55 +08:00
|
|
|
projects: [
|
|
|
|
|
"<rootDir>/jest-format-test.config.mjs",
|
2022-02-11 09:56:58 +08:00
|
|
|
isProduction && "<rootDir>/jest-integration-test.config.mjs",
|
|
|
|
|
].filter(Boolean),
|
2018-08-09 10:21:00 +08:00
|
|
|
snapshotSerializers: [
|
2018-09-01 12:11:19 +08:00
|
|
|
"jest-snapshot-serializer-raw",
|
|
|
|
|
"jest-snapshot-serializer-ansi",
|
2018-08-09 10:21:00 +08:00
|
|
|
],
|
2022-04-08 02:59:17 +02:00
|
|
|
snapshotFormat: {
|
|
|
|
|
escapeString: false,
|
2022-04-27 17:56:05 +08:00
|
|
|
printBasicPrototype: false,
|
2022-04-08 02:59:17 +02:00
|
|
|
},
|
2020-09-17 01:08:44 +09:00
|
|
|
testPathIgnorePatterns,
|
2018-12-18 08:16:32 +08:00
|
|
|
collectCoverage: ENABLE_CODE_COVERAGE,
|
2020-08-21 09:43:24 +08:00
|
|
|
collectCoverageFrom: ["<rootDir>/src/**/*.js", "<rootDir>/bin/**/*.js"],
|
2020-09-17 07:35:33 +08:00
|
|
|
coveragePathIgnorePatterns: [
|
|
|
|
|
"<rootDir>/src/standalone.js",
|
2022-04-29 14:04:17 +08:00
|
|
|
"<rootDir>/src/document/debug.js",
|
2020-09-17 07:35:33 +08:00
|
|
|
],
|
2020-03-23 17:56:02 +08:00
|
|
|
coverageReporters: ["text", "lcov"],
|
2018-01-05 21:09:51 +11:00
|
|
|
moduleNameMapper: {
|
2022-02-12 15:39:16 +08:00
|
|
|
"prettier-local": "<rootDir>/tests/config/prettier-entry.js",
|
2022-01-04 17:00:25 +08:00
|
|
|
"prettier-standalone": "<rootDir>/tests/config/require-standalone.cjs",
|
2018-01-05 21:09:51 +11:00
|
|
|
},
|
2021-09-07 14:53:45 +09:00
|
|
|
modulePathIgnorePatterns: [
|
|
|
|
|
"<rootDir>/dist",
|
|
|
|
|
"<rootDir>/website",
|
|
|
|
|
"<rootDir>/scripts/release",
|
|
|
|
|
],
|
2021-12-02 10:19:32 +08:00
|
|
|
transform: {},
|
2018-07-04 21:54:39 +02:00
|
|
|
watchPlugins: [
|
|
|
|
|
"jest-watch-typeahead/filename",
|
|
|
|
|
"jest-watch-typeahead/testname",
|
2018-07-07 12:11:04 -04:00
|
|
|
],
|
2017-07-16 21:49:37 +10:00
|
|
|
};
|
2021-11-29 10:07:11 +08:00
|
|
|
|
|
|
|
|
export default config;
|