Files
test-repo/jest.config.js
T
Georgii Dolzhykov 23b4822e66 Disable Jest's default transformer (Babel) (#10454)
* Disable Jest's default transform (Babel)

https://jestjs.io/docs/en/next/code-transformation#defaults

Otherwise, I sometimes get this error because Babel tries to resolve Browserslist:

----
  ● plugin search should not crash when prettier isn't inside a directory › encountered a declaration exception

    ENOENT: no such file or directory, stat '/mnt/d/dev/prettier/tests_integration/mnt/d/dev/prettier/tests_integration/runPrettier.js'

      52 |   jest.spyOn(fs, "statSync").mockImplementation((filename) => {
      53 |     if (path.basename(filename) === "virtualDirectory") {
    > 54 |       return origStatSync(path.join(__dirname, __filename));
         |              ^
      55 |     }
      56 |     return origStatSync(filename);
      57 |   });

      at Object.<anonymous> (tests_integration/runPrettier.js:54:14)
      at isFile (node_modules/browserslist/node.js:38:42)
      at eachParent (node_modules/browserslist/node.js:46:13)
      at Object.getStat (node_modules/browserslist/node.js:197:15)
      at browserslist (node_modules/browserslist/index.js:433:19)
      at resolveTargets (node_modules/@babel/helper-compilation-targets/lib/index.js:174:46)
----
2021-03-01 13:55:20 +02:00

82 lines
2.3 KiB
JavaScript

"use strict";
const path = require("path");
const installPrettier = require("./scripts/install-prettier");
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);
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"
);
}
module.exports = {
setupFiles: ["<rootDir>/tests_config/setup.js"],
snapshotSerializers: [
"jest-snapshot-serializer-raw",
"jest-snapshot-serializer-ansi",
],
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/static/lib"],
testEnvironment: "node",
transform,
watchPlugins: [
"jest-watch-typeahead/filename",
"jest-watch-typeahead/testname",
],
};