Files
test-repo/jest.config.js
T

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

103 lines
3.4 KiB
JavaScript
Raw Normal View History

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";
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);
// When debugging production test, this flag can skip installing package
const SKIP_PRODUCTION_INSTALL = Boolean(process.env.SKIP_PRODUCTION_INSTALL);
2025-05-06 10:34:05 +08:00
const nodejsMajorVersion = Number(process.versions.node.split(".")[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 ||
(isProduction && !TEST_STANDALONE && !SKIP_PRODUCTION_INSTALL)
) {
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
}
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 = [];
if (TEST_STANDALONE) {
testPathIgnorePatterns.push("<rootDir>/tests/integration/");
}
2022-09-18 17:50:14 +08:00
if (isProduction) {
// Only run unit test for development
testPathIgnorePatterns.push("<rootDir>/tests/unit/");
} else {
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
2025-05-06 10:34:05 +08:00
if (nodejsMajorVersion <= 16) {
// Uses import attributes
testPathIgnorePatterns.push(
2023-01-18 10:58:25 +08:00
"<rootDir>/tests/integration/__tests__/help-options.js",
);
}
2025-05-06 10:34:05 +08:00
if (nodejsMajorVersion <= 14) {
testPathIgnorePatterns.push(
"<rootDir>/tests/integration/__tests__/plugin-parsers.js",
"<rootDir>/tests/integration/__tests__/normalize-doc.js",
"<rootDir>/tests/integration/__tests__/doc-utils-clean-doc.js",
"<rootDir>/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
"<rootDir>/tests/integration/__tests__/experimental-cli.js",
// Fails on Node.js v14
"<rootDir>/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-05-06 10:34:05 +08:00
runner: "jest-light-runner",
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
],
2020-09-17 01:08:44 +09:00
testPathIgnorePatterns,
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;