Files
test-repo/jest.config.js
T

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

126 lines
4.3 KiB
JavaScript
Raw Normal View History

2021-11-29 10:07:11 +08:00
import path from "node:path";
import createEsmUtils from "esm-utils";
2025-12-24 22:57:02 +08:00
import installBrowser from "./tests/config/install-browser.js";
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";
2022-10-17 08:25:32 +08:00
// 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);
2025-12-24 22:57:02 +08:00
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(".", 1)[0]);
let PRETTIER_DIR = isProduction
2025-04-09 08:38:46 +08:00
? path.join(PROJECT_ROOT, "dist/prettier")
: PROJECT_ROOT;
2022-10-18 10:01:09 +08:00
let PRETTIER_INSTALLED_DIR = "";
if (
INSTALL_PACKAGE ||
2025-12-24 22:57:02 +08:00
(isProduction &&
!TEST_STANDALONE &&
!SKIP_PRODUCTION_INSTALL &&
TEST_RUNTIME === "nodejs")
) {
2022-10-18 10:01:09 +08:00
PRETTIER_INSTALLED_DIR = installPrettier(PRETTIER_DIR);
PRETTIER_DIR = path.join(PRETTIER_INSTALLED_DIR, "node_modules/prettier");
2020-04-18 01:24:22 +08:00
}
2025-12-24 22:57:02 +08:00
if (TEST_RUNTIME === "browser") {
installBrowser();
}
2022-10-18 10:01:09 +08:00
process.env.PRETTIER_INSTALLED_DIR = PRETTIER_INSTALLED_DIR;
process.env.PRETTIER_DIR = PRETTIER_DIR;
2017-07-16 21:49:37 +10:00
2020-09-17 01:08:44 +09:00
const testPathIgnorePatterns = [];
2025-12-24 22:57:02 +08:00
if (TEST_STANDALONE || TEST_RUNTIME !== "nodejs") {
testPathIgnorePatterns.push("tests/integration/");
2020-09-17 01:08:44 +09:00
}
2022-09-18 17:50:14 +08:00
if (isProduction) {
// Only run unit test for development
2025-12-24 22:57:02 +08:00
testPathIgnorePatterns.push("tests/unit/");
2022-09-18 17:50:14 +08:00
} else {
2020-09-17 01:08:44 +09:00
// Only test bundles for production
2025-12-24 22:57:02 +08:00
testPathIgnorePatterns.push("tests/integration/__tests__/bundle.js");
}
// Currently can't load plugins in browser
if (TEST_RUNTIME === "browser") {
2020-09-17 01:08:44 +09:00
testPathIgnorePatterns.push(
2025-12-24 22:57:02 +08:00
"tests/format/misc/front-matter/with-plugins/format.test.js",
"tests/format/misc/plugins/embed-async-printer/format.test.js",
2026-01-25 10:30:19 +08:00
"tests/format/misc/_errors_/broken-plugin/format.test.js",
2025-12-24 22:57:02 +08:00
"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",
2020-09-17 01:08:44 +09:00
);
}
2022-04-22 20:51:41 +08:00
2025-12-14 23:22:28 +08:00
if (nodejsMajorVersion <= 18) {
// Uses import attributes and `Array#toSorted()`
2025-12-24 22:57:02 +08:00
testPathIgnorePatterns.push("tests/integration/__tests__/help-options.js");
}
2025-05-06 10:34:05 +08:00
if (nodejsMajorVersion <= 14) {
testPathIgnorePatterns.push(
2025-12-24 22:57:02 +08:00
"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",
2025-05-06 10:34:05 +08:00
// `@prettier/cli` uses `node:stream/consumers`, not available on Node.js v14
2025-12-24 22:57:02 +08:00
"tests/integration/__tests__/experimental-cli.js",
// Fails on Node.js v14
2025-12-24 22:57:02 +08:00
"tests/dts/unit/run.js",
);
}
2021-11-29 10:07:11 +08:00
const config = {
2022-07-20 23:18:24 +08:00
setupFiles: [
"<rootDir>/tests/config/format-test-setup.js",
"<rootDir>/tests/integration/integration-test-setup.js",
],
2025-06-07 17:25:46 +08:00
runner: "jest-light-runner/child-process",
testEnvironmentOptions: {
customExportConditions: ["development"],
},
snapshotSerializers: [
"jest-snapshot-serializer-raw",
"jest-snapshot-serializer-ansi",
],
2022-08-05 21:58:54 +08:00
testMatch: [
"<rootDir>/tests/format/**/format.test.js",
"<rootDir>/tests/integration/__tests__/**/*.js",
"<rootDir>/tests/unit/**/*.js",
"<rootDir>/tests/dts/unit/**/*.js",
2022-08-05 21:58:54 +08:00
],
2025-12-24 22:57:02 +08:00
testPathIgnorePatterns: testPathIgnorePatterns.map(
(file) => `<rootDir>/${file}`,
),
2022-10-17 08:25: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",
"<rootDir>/src/document/debug.js",
2020-09-17 07:35:33 +08:00
],
2020-03-23 17:56:02 +08:00
coverageReporters: ["text", "lcov"],
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",
},
2021-09-07 14:53:45 +09:00
modulePathIgnorePatterns: [
"<rootDir>/dist",
"<rootDir>/website",
"<rootDir>/scripts/release",
],
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;