From 8ffbcbbcae8ec1c3b8a5044851516308659077db Mon Sep 17 00:00:00 2001 From: fisker Cheung Date: Thu, 2 Dec 2021 10:19:32 +0800 Subject: [PATCH] Refactor integration test files to use ES Module (#11891) --- .eslintrc.js | 17 +++++++-- cspell.json | 2 +- jest.config.mjs | 28 +------------- package.json | 12 +++--- tests/integration/__tests__/arg-parsing.js | 6 +-- tests/integration/__tests__/bundle.js | 38 +++++++++++-------- tests/integration/__tests__/check.js | 4 +- tests/integration/__tests__/cli.js | 5 +-- tests/integration/__tests__/config-invalid.js | 7 ++-- .../__tests__/config-resolution.js | 13 ++++--- tests/integration/__tests__/cursor-offset.js | 4 +- tests/integration/__tests__/debug-api.js | 6 +-- tests/integration/__tests__/debug-check.js | 4 +- .../integration/__tests__/debug-print-ast.js | 4 +- .../__tests__/debug-print-comments.js | 4 +- .../integration/__tests__/debug-print-doc.js | 4 +- tests/integration/__tests__/doc-builders.js | 4 +- .../integration/__tests__/doc-mark-as-root.js | 4 +- tests/integration/__tests__/doc-trim.js | 4 +- .../__tests__/doc-utils-clean-doc.js | 4 +- tests/integration/__tests__/early-exit.js | 6 +-- .../__tests__/error-on-unmatched-pattern.js | 4 +- tests/integration/__tests__/file-info.js | 22 +++++------ tests/integration/__tests__/format.js | 6 +-- tests/integration/__tests__/help-options.js | 12 +++--- .../__tests__/ignore-absolute-path.js | 7 ++-- tests/integration/__tests__/ignore-emoji.js | 7 ++-- .../__tests__/ignore-in-subdirectories.js | 7 ++-- tests/integration/__tests__/ignore-path.js | 9 +++-- .../__tests__/ignore-relative-path.js | 7 ++-- tests/integration/__tests__/ignore-unknown.js | 4 +- .../integration/__tests__/ignore-vcs-files.js | 7 ++-- tests/integration/__tests__/infer-parser.js | 7 ++-- tests/integration/__tests__/invalid-ignore.js | 12 +++--- .../__tests__/line-suffix-boundary.js | 7 +--- tests/integration/__tests__/list-different.js | 4 +- tests/integration/__tests__/load-toml.js | 4 +- tests/integration/__tests__/loglevel.js | 6 +-- tests/integration/__tests__/normalize-doc.js | 4 +- tests/integration/__tests__/package.json | 3 ++ tests/integration/__tests__/parser-api.js | 6 +-- tests/integration/__tests__/patterns-dirs.js | 14 ++++--- tests/integration/__tests__/patterns-glob.js | 7 ++-- tests/integration/__tests__/patterns.js | 7 ++-- tests/integration/__tests__/piped-output.js | 4 +- .../__tests__/plugin-default-options.js | 4 +- .../__tests__/plugin-extensions.js | 4 +- .../__tests__/plugin-flush-line-suffix.js | 4 +- .../__tests__/plugin-options-string.js | 6 +-- tests/integration/__tests__/plugin-options.js | 6 +-- .../__tests__/plugin-precedence.js | 4 +- .../__tests__/plugin-preprocess.js | 4 +- .../__tests__/plugin-resolution.js | 4 +- .../__tests__/plugin-virtual-directory.js | 4 +- .../__tests__/resolve-config-file.js | 8 ++-- tests/integration/__tests__/schema.js | 6 +-- tests/integration/__tests__/skip-folders.js | 7 ++-- tests/integration/__tests__/stdin-filepath.js | 6 +-- tests/integration/__tests__/support-info.js | 6 +-- tests/integration/__tests__/syntax-error.js | 4 +- tests/integration/__tests__/third-party.js | 10 +++-- tests/integration/__tests__/util-shared.js | 4 +- .../__tests__/with-config-precedence.js | 4 +- .../__tests__/with-node-modules.js | 7 ++-- .../__tests__/with-parser-inference.js | 6 +-- tests/integration/__tests__/with-shebang.js | 4 +- tests/integration/__tests__/write.js | 4 +- website/playground/Playground.js | 2 +- .../{codeSamples.js => codeSamples.mjs} | 0 yarn.lock | 4 +- 70 files changed, 197 insertions(+), 282 deletions(-) create mode 100644 tests/integration/__tests__/package.json rename website/playground/{codeSamples.js => codeSamples.mjs} (100%) diff --git a/.eslintrc.js b/.eslintrc.js index b012f8e21..3647f0dbd 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -18,7 +18,7 @@ module.exports = { curly: "error", "dot-notation": "error", eqeqeq: "error", - "no-console": isCI ? "error" : "off", + "no-console": isCI ? "error" : "warn", "no-else-return": [ "error", { @@ -94,7 +94,7 @@ module.exports = { "import/no-extraneous-dependencies": [ "error", { - devDependencies: ["jest.config.mjs", "tests*/**", "scripts/**"], + devDependencies: ["jest.config.mjs", "tests/**", "scripts/**"], }, ], "import/order": "error", @@ -147,7 +147,11 @@ module.exports = { }, }, { - files: ["**/*.mjs", "scripts/release/**/*.js"], + files: [ + "**/*.mjs", + "scripts/release/**/*.js", + "tests/integration/__tests__/*.js", + ], parserOptions: { sourceType: "module", }, @@ -156,6 +160,13 @@ module.exports = { "unicorn/prefer-node-protocol": "error", }, }, + // There is a empty package.json in that directory + { + files: ["tests/integration/__tests__/*.js"], + rules: { + "import/no-extraneous-dependencies": "off", + }, + }, { files: [ "tests/format/**/jsfmt.spec.js", diff --git a/cspell.json b/cspell.json index ee9e50603..cebc04589 100644 --- a/cspell.json +++ b/cspell.json @@ -399,7 +399,7 @@ "test*.*", "website/data/users.yml", "website/build/**", - "website/playground/codeSamples.js", + "website/playground/codeSamples.mjs", "website/pages/googlefe164a33bda4034b.html", "website/static/lib/**", "website/static/playground.js" diff --git a/jest.config.mjs b/jest.config.mjs index f80024e76..ad415f09d 100644 --- a/jest.config.mjs +++ b/jest.config.mjs @@ -17,34 +17,10 @@ if (INSTALL_PACKAGE || (isProduction && !TEST_STANDALONE)) { process.env.PRETTIER_DIR = PRETTIER_DIR; const testPathIgnorePatterns = []; -let transform = {}; if (TEST_STANDALONE) { testPathIgnorePatterns.push("/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 { +if (!isProduction) { // Only test bundles for production testPathIgnorePatterns.push( "/tests/integration/__tests__/bundle.js" @@ -75,7 +51,7 @@ const config = { "/website", "/scripts/release", ], - transform, + transform: {}, watchPlugins: [ "jest-watch-typeahead/filename", "jest-watch-typeahead/testname", diff --git a/package.json b/package.json index 828ea59aa..bb85dfcee 100644 --- a/package.json +++ b/package.json @@ -92,6 +92,7 @@ "@babel/preset-env": "7.16.4", "@babel/types": "7.16.0", "@glimmer/reference": "0.83.1", + "@jest/globals": "27.4.2", "@rollup/plugin-alias": "3.1.8", "@rollup/plugin-babel": "5.3.0", "@rollup/plugin-commonjs": "21.0.1", @@ -100,7 +101,6 @@ "@rollup/plugin-replace": "3.0.0", "@types/estree": "0.0.50", "@types/jest": "27.0.3", - "babel-jest": "27.4.2", "babel-loader": "8.2.3", "benchmark": "2.1.4", "builtin-modules": "3.2.0", @@ -140,11 +140,11 @@ "scripts": { "prepublishOnly": "echo \"Error: must publish from dist/\" && exit 1", "prepare-release": "yarn && yarn build && yarn test:dist", - "test": "jest", - "test:dev-package": "cross-env INSTALL_PACKAGE=1 jest", - "test:dist": "cross-env NODE_ENV=production jest", - "test:dist-standalone": "cross-env NODE_ENV=production TEST_STANDALONE=1 jest", - "test:integration": "jest tests/integration", + "test": "cross-env NODE_OPTIONS=--experimental-vm-modules jest", + "test:dev-package": "cross-env INSTALL_PACKAGE=1 NODE_OPTIONS=--experimental-vm-modules jest", + "test:dist": "cross-env NODE_ENV=production NODE_OPTIONS=--experimental-vm-modules jest", + "test:dist-standalone": "cross-env NODE_ENV=production TEST_STANDALONE=1 NODE_OPTIONS=--experimental-vm-modules jest", + "test:integration": "cross-env NODE_OPTIONS=--experimental-vm-modules jest tests/integration", "perf:repeat": "yarn && yarn build && cross-env NODE_ENV=production node ./dist/bin-prettier.js --debug-repeat ${PERF_REPEAT:-1000} --loglevel debug ${PERF_FILE:-./index.js} > /dev/null", "perf:repeat-inspect": "yarn && yarn build && cross-env NODE_ENV=production node --inspect-brk ./dist/bin-prettier.js --debug-repeat ${PERF_REPEAT:-1000} --loglevel debug ${PERF_FILE:-./index.js} > /dev/null", "perf:benchmark": "yarn && yarn build && cross-env NODE_ENV=production node ./dist/bin-prettier.js --debug-benchmark --loglevel debug ${PERF_FILE:-./index.js} > /dev/null", diff --git a/tests/integration/__tests__/arg-parsing.js b/tests/integration/__tests__/arg-parsing.js index cf03ce754..2873a2daf 100644 --- a/tests/integration/__tests__/arg-parsing.js +++ b/tests/integration/__tests__/arg-parsing.js @@ -1,7 +1,7 @@ -"use strict"; +import runPrettier from "../runPrettier.js"; +import jestPathSerializer from "../path-serializer.js"; -const runPrettier = require("../runPrettier.js"); -expect.addSnapshotSerializer(require("../path-serializer.js")); +expect.addSnapshotSerializer(jestPathSerializer); describe("boolean flags do not swallow the next argument", () => { runPrettier("cli/arg-parsing", [ diff --git a/tests/integration/__tests__/bundle.js b/tests/integration/__tests__/bundle.js index 831a26cd2..0f12b81df 100644 --- a/tests/integration/__tests__/bundle.js +++ b/tests/integration/__tests__/bundle.js @@ -1,31 +1,39 @@ -"use strict"; +import path from "node:path"; +import globby from "globby"; +import createEsmUtils from "esm-utils"; +import { projectRoot } from "../env.js"; +import coreOptions from "../../../src/main/core-options.js"; +import codeSamples from "../../../website/playground/codeSamples.mjs"; +import jestPathSerializer from "../path-serializer.js"; -const path = require("path"); -const globby = require("globby"); -const { projectRoot } = require("../env.js"); -const coreOptions = require("../../../src/main/core-options.js"); -const codeSamples = - require("../../../website/playground/codeSamples.js").default; +const { require } = createEsmUtils(import.meta); + +expect.addSnapshotSerializer(jestPathSerializer); const parserNames = coreOptions.options.parser.choices.map( ({ value }) => value ); const distDirectory = path.join(projectRoot, "dist"); +let esmStandalone; +let esmPlugins; +beforeAll(async () => { + ({ default: esmStandalone } = await import( + path.join(distDirectory, "esm/standalone.mjs") + )); + esmPlugins = await Promise.all( + globby + .sync(["esm/parser-*.mjs"], { cwd: distDirectory, absolute: true }) + .map(async (file) => (await import(file)).default) + ); +}); + describe("standalone", () => { const standalone = require(path.join(distDirectory, "standalone.js")); const plugins = globby .sync(["parser-*.js"], { cwd: distDirectory, absolute: true }) .map((file) => require(file)); - const esmStandalone = require(path.join( - distDirectory, - "esm/standalone.mjs" - )).default; - const esmPlugins = globby - .sync(["esm/parser-*.mjs"], { cwd: distDirectory, absolute: true }) - .map((file) => require(file).default); - for (const parser of parserNames) { test(parser, () => { const input = codeSamples(parser); diff --git a/tests/integration/__tests__/check.js b/tests/integration/__tests__/check.js index e47eec277..fc30d93af 100644 --- a/tests/integration/__tests__/check.js +++ b/tests/integration/__tests__/check.js @@ -1,6 +1,4 @@ -"use strict"; - -const runPrettier = require("../runPrettier.js"); +import runPrettier from "../runPrettier.js"; describe("checks stdin with --check", () => { runPrettier("cli/with-shebang", ["--check", "--parser", "babel"], { diff --git a/tests/integration/__tests__/cli.js b/tests/integration/__tests__/cli.js index 362b4e5d2..c60790b54 100644 --- a/tests/integration/__tests__/cli.js +++ b/tests/integration/__tests__/cli.js @@ -1,6 +1,5 @@ -"use strict"; -const fs = require("fs"); -const { prettierCli } = require("../env.js"); +import fs from "node:fs"; +import { prettierCli } from "../env.js"; describe("CLI", () => { test("CLI should be executable.", () => { diff --git a/tests/integration/__tests__/config-invalid.js b/tests/integration/__tests__/config-invalid.js index d8acde855..e8c9e2cd8 100644 --- a/tests/integration/__tests__/config-invalid.js +++ b/tests/integration/__tests__/config-invalid.js @@ -1,8 +1,7 @@ -"use strict"; +import runPrettier from "../runPrettier.js"; +import jestPathSerializer from "../path-serializer.js"; -const runPrettier = require("../runPrettier.js"); - -expect.addSnapshotSerializer(require("../path-serializer.js")); +expect.addSnapshotSerializer(jestPathSerializer); describe("throw error for unsupported extension", () => { runPrettier("cli/config/invalid", [ diff --git a/tests/integration/__tests__/config-resolution.js b/tests/integration/__tests__/config-resolution.js index 7e39b7f8f..dd902686e 100644 --- a/tests/integration/__tests__/config-resolution.js +++ b/tests/integration/__tests__/config-resolution.js @@ -1,11 +1,12 @@ -"use strict"; +import path from "node:path"; +import prettier from "prettier-local"; +import createEsmUtils from "esm-utils"; +import runPrettier from "../runPrettier.js"; +import jestPathSerializer from "../path-serializer.js"; -const path = require("path"); +const { __dirname } = createEsmUtils(import.meta); -const prettier = require("prettier-local"); -const runPrettier = require("../runPrettier.js"); - -expect.addSnapshotSerializer(require("../path-serializer.js")); +expect.addSnapshotSerializer(jestPathSerializer); describe("resolves configuration from external files", () => { runPrettier("cli/config/", ["--end-of-line", "lf", "**/*.js"]).test({ diff --git a/tests/integration/__tests__/cursor-offset.js b/tests/integration/__tests__/cursor-offset.js index e8c4f375b..71e7859fe 100644 --- a/tests/integration/__tests__/cursor-offset.js +++ b/tests/integration/__tests__/cursor-offset.js @@ -1,6 +1,4 @@ -"use strict"; - -const runPrettier = require("../runPrettier.js"); +import runPrettier from "../runPrettier.js"; describe("write cursorOffset to stderr with --cursor-offset ", () => { runPrettier("cli", ["--cursor-offset", "2", "--parser", "babel"], { diff --git a/tests/integration/__tests__/debug-api.js b/tests/integration/__tests__/debug-api.js index 3cdcab017..74b2eab59 100644 --- a/tests/integration/__tests__/debug-api.js +++ b/tests/integration/__tests__/debug-api.js @@ -1,4 +1,5 @@ -"use strict"; +import prettier from "prettier-local"; +import { outdent } from "outdent"; const { __debug: { parse, formatAST, formatDoc, printToDoc, printDocToString }, @@ -6,8 +7,7 @@ const { builders, utils: { cleanDoc }, }, -} = require("prettier-local"); -const { outdent } = require("outdent"); +} = prettier; const code = outdent` const foo = 'bar' diff --git a/tests/integration/__tests__/debug-check.js b/tests/integration/__tests__/debug-check.js index 94a196d5f..c9c1f6ad4 100644 --- a/tests/integration/__tests__/debug-check.js +++ b/tests/integration/__tests__/debug-check.js @@ -1,6 +1,4 @@ -"use strict"; - -const runPrettier = require("../runPrettier.js"); +import runPrettier from "../runPrettier.js"; describe("doesn't crash when --debug-check is passed", () => { runPrettier("cli/with-shebang", ["issue1890.js", "--debug-check"]).test({ diff --git a/tests/integration/__tests__/debug-print-ast.js b/tests/integration/__tests__/debug-print-ast.js index 53022674e..4541f304e 100644 --- a/tests/integration/__tests__/debug-print-ast.js +++ b/tests/integration/__tests__/debug-print-ast.js @@ -1,6 +1,4 @@ -"use strict"; - -const runPrettier = require("../runPrettier.js"); +import runPrettier from "../runPrettier.js"; describe("prints information for debugging AST --debug-print-ast", () => { runPrettier("cli/with-shebang", ["--debug-print-ast", "--parser", "babel"], { diff --git a/tests/integration/__tests__/debug-print-comments.js b/tests/integration/__tests__/debug-print-comments.js index 5b10539f3..340cbcd6b 100644 --- a/tests/integration/__tests__/debug-print-comments.js +++ b/tests/integration/__tests__/debug-print-comments.js @@ -1,6 +1,4 @@ -"use strict"; - -const runPrettier = require("../runPrettier.js"); +import runPrettier from "../runPrettier.js"; describe("prints information for debugging comment attachment with --debug-print-comments", () => { runPrettier( diff --git a/tests/integration/__tests__/debug-print-doc.js b/tests/integration/__tests__/debug-print-doc.js index b165b6c93..a5b78f0f2 100644 --- a/tests/integration/__tests__/debug-print-doc.js +++ b/tests/integration/__tests__/debug-print-doc.js @@ -1,6 +1,4 @@ -"use strict"; - -const runPrettier = require("../runPrettier.js"); +import runPrettier from "../runPrettier.js"; describe("prints doc with --debug-print-doc", () => { runPrettier("cli/with-shebang", ["--debug-print-doc", "--parser", "babel"], { diff --git a/tests/integration/__tests__/doc-builders.js b/tests/integration/__tests__/doc-builders.js index 47f25516f..bfe0e395f 100644 --- a/tests/integration/__tests__/doc-builders.js +++ b/tests/integration/__tests__/doc-builders.js @@ -1,6 +1,4 @@ -"use strict"; - -const prettier = require("prettier-local"); +import prettier from "prettier-local"; const { concat, join, diff --git a/tests/integration/__tests__/doc-mark-as-root.js b/tests/integration/__tests__/doc-mark-as-root.js index 4f13688ac..fa1f6b340 100644 --- a/tests/integration/__tests__/doc-mark-as-root.js +++ b/tests/integration/__tests__/doc-mark-as-root.js @@ -1,6 +1,4 @@ -"use strict"; - -const prettier = require("prettier-local"); +import prettier from "prettier-local"; const docPrinter = prettier.doc.printer; const docBuilders = prettier.doc.builders; diff --git a/tests/integration/__tests__/doc-trim.js b/tests/integration/__tests__/doc-trim.js index 4f248f214..13a419e2c 100644 --- a/tests/integration/__tests__/doc-trim.js +++ b/tests/integration/__tests__/doc-trim.js @@ -1,6 +1,4 @@ -"use strict"; - -const prettier = require("prettier-local"); +import prettier from "prettier-local"; const docPrinter = prettier.doc.printer; const docBuilders = prettier.doc.builders; diff --git a/tests/integration/__tests__/doc-utils-clean-doc.js b/tests/integration/__tests__/doc-utils-clean-doc.js index 69f8e9b0a..447d80e83 100644 --- a/tests/integration/__tests__/doc-utils-clean-doc.js +++ b/tests/integration/__tests__/doc-utils-clean-doc.js @@ -1,6 +1,4 @@ -"use strict"; - -const prettier = require("prettier-local"); +import prettier from "prettier-local"; const docBuilders = prettier.doc.builders; const docUtils = prettier.doc.utils; diff --git a/tests/integration/__tests__/early-exit.js b/tests/integration/__tests__/early-exit.js index 96296b43e..68a156f8f 100644 --- a/tests/integration/__tests__/early-exit.js +++ b/tests/integration/__tests__/early-exit.js @@ -1,7 +1,5 @@ -"use strict"; - -const prettier = require("prettier-local"); -const runPrettier = require("../runPrettier.js"); +import prettier from "prettier-local"; +import runPrettier from "../runPrettier.js"; describe("show version with --version", () => { runPrettier("cli/with-shebang", ["--version"]).test({ diff --git a/tests/integration/__tests__/error-on-unmatched-pattern.js b/tests/integration/__tests__/error-on-unmatched-pattern.js index 0cea212d3..868312f78 100644 --- a/tests/integration/__tests__/error-on-unmatched-pattern.js +++ b/tests/integration/__tests__/error-on-unmatched-pattern.js @@ -1,6 +1,4 @@ -"use strict"; - -const runPrettier = require("../runPrettier.js"); +import runPrettier from "../runPrettier.js"; describe("no error on unmatched pattern", () => { runPrettier("cli/error-on-unmatched-pattern", [ diff --git a/tests/integration/__tests__/file-info.js b/tests/integration/__tests__/file-info.js index 009b36820..2e68b05d1 100644 --- a/tests/integration/__tests__/file-info.js +++ b/tests/integration/__tests__/file-info.js @@ -1,14 +1,14 @@ -"use strict"; +import path from "node:path"; +import fs from "node:fs"; +import tempy from "tempy"; +import prettier from "prettier-local"; +import createEsmUtils from "esm-utils"; +import runPrettier from "../runPrettier.js"; +import jestPathSerializer from "../path-serializer.js"; -const path = require("path"); -const fs = require("fs"); -const tempy = require("tempy"); -const fromPairs = require("lodash/fromPairs"); +const { __dirname } = createEsmUtils(import.meta); -const prettier = require("prettier-local"); -const runPrettier = require("../runPrettier.js"); - -expect.addSnapshotSerializer(require("../path-serializer.js")); +expect.addSnapshotSerializer(jestPathSerializer); describe("extracts file-info for a js file", () => { runPrettier("cli/", ["--file-info", "something.js"]).test({ @@ -161,7 +161,7 @@ test("API getFileInfo.sync with filepath only", () => { }); describe("API getFileInfo resolveConfig", () => { - const files = fromPairs( + const files = Object.fromEntries( ["foo", "js", "bar", "css"].map((ext) => [ ext, path.resolve( @@ -268,7 +268,7 @@ describe("API getFileInfo resolveConfig", () => { }); describe("API getFileInfo resolveConfig when no config is present", () => { - const files = fromPairs( + const files = Object.fromEntries( ["foo", "js"].map((ext) => [ ext, path.resolve(path.join(__dirname, `../cli/non-exists-dir/file.${ext}`)), diff --git a/tests/integration/__tests__/format.js b/tests/integration/__tests__/format.js index 50578fa4c..d01276adc 100644 --- a/tests/integration/__tests__/format.js +++ b/tests/integration/__tests__/format.js @@ -1,7 +1,5 @@ -"use strict"; - -const prettier = require("prettier-local"); -const fooPlugin = require("../plugins/defaultOptions/plugin.js"); +import prettier from "prettier-local"; +import fooPlugin from "../plugins/defaultOptions/plugin.js"; test("yaml parser should handle CRLF correctly", () => { const input = "a:\r\n 123\r\n"; diff --git a/tests/integration/__tests__/help-options.js b/tests/integration/__tests__/help-options.js index e8a616ee5..261a9636a 100644 --- a/tests/integration/__tests__/help-options.js +++ b/tests/integration/__tests__/help-options.js @@ -1,10 +1,8 @@ -"use strict"; - -const prettier = require("prettier-local"); -const runPrettier = require("../runPrettier.js"); -const constant = require("../../../src/cli/constant.js"); -const core = require("../../../src/cli/core.js"); -const arrayify = require("../../../src/utils/arrayify.js"); +import prettier from "prettier-local"; +import runPrettier from "../runPrettier.js"; +import constant from "../../../src/cli/constant.js"; +import core from "../../../src/cli/core.js"; +import arrayify from "../../../src/utils/arrayify.js"; for (const option of arrayify( { diff --git a/tests/integration/__tests__/ignore-absolute-path.js b/tests/integration/__tests__/ignore-absolute-path.js index 79fde347f..7611261f6 100644 --- a/tests/integration/__tests__/ignore-absolute-path.js +++ b/tests/integration/__tests__/ignore-absolute-path.js @@ -1,7 +1,8 @@ -"use strict"; +import path from "node:path"; +import createEsmUtils from "esm-utils"; +import runPrettier from "../runPrettier.js"; -const path = require("path"); -const runPrettier = require("../runPrettier.js"); +const { __dirname } = createEsmUtils(import.meta); describe("support absolute filename", () => { runPrettier("cli/ignore-absolute-path", [ diff --git a/tests/integration/__tests__/ignore-emoji.js b/tests/integration/__tests__/ignore-emoji.js index a18ff4e90..cdbab03a7 100644 --- a/tests/integration/__tests__/ignore-emoji.js +++ b/tests/integration/__tests__/ignore-emoji.js @@ -1,8 +1,7 @@ -"use strict"; +import runPrettier from "../runPrettier.js"; +import jestPathSerializer from "../path-serializer.js"; -const runPrettier = require("../runPrettier.js"); - -expect.addSnapshotSerializer(require("../path-serializer.js")); +expect.addSnapshotSerializer(jestPathSerializer); describe("ignores file name contains emoji", () => { runPrettier("cli/ignore-emoji", ["**/*.js", "-l"]).test({ diff --git a/tests/integration/__tests__/ignore-in-subdirectories.js b/tests/integration/__tests__/ignore-in-subdirectories.js index b30d361fe..0e469a097 100644 --- a/tests/integration/__tests__/ignore-in-subdirectories.js +++ b/tests/integration/__tests__/ignore-in-subdirectories.js @@ -1,8 +1,7 @@ -"use strict"; +import runPrettier from "../runPrettier.js"; +import jestPathSerializer from "../path-serializer.js"; -const runPrettier = require("../runPrettier.js"); - -expect.addSnapshotSerializer(require("../path-serializer.js")); +expect.addSnapshotSerializer(jestPathSerializer); describe("ignores files when executing in a subdirectory", () => { runPrettier("cli/ignore-in-subdirectories/web1", [ diff --git a/tests/integration/__tests__/ignore-path.js b/tests/integration/__tests__/ignore-path.js index b7877a1bd..980816a94 100644 --- a/tests/integration/__tests__/ignore-path.js +++ b/tests/integration/__tests__/ignore-path.js @@ -1,8 +1,9 @@ -"use strict"; +import path from "node:path"; +import fs from "node:fs"; +import createEsmUtils from "esm-utils"; +import runPrettier from "../runPrettier.js"; -const fs = require("fs"); -const path = require("path"); -const runPrettier = require("../runPrettier.js"); +const { __dirname } = createEsmUtils(import.meta); fs.writeFileSync( // This file is in `.gitignore`, just copy from `regular-module.js` diff --git a/tests/integration/__tests__/ignore-relative-path.js b/tests/integration/__tests__/ignore-relative-path.js index 85a0939cd..905175c68 100644 --- a/tests/integration/__tests__/ignore-relative-path.js +++ b/tests/integration/__tests__/ignore-relative-path.js @@ -1,8 +1,7 @@ -"use strict"; +import runPrettier from "../runPrettier.js"; +import jestPathSerializer from "../path-serializer.js"; -const runPrettier = require("../runPrettier.js"); - -expect.addSnapshotSerializer(require("../path-serializer.js")); +expect.addSnapshotSerializer(jestPathSerializer); describe("support relative paths", () => { runPrettier("cli/ignore-relative-path", [ diff --git a/tests/integration/__tests__/ignore-unknown.js b/tests/integration/__tests__/ignore-unknown.js index 13846a720..c53f1774f 100644 --- a/tests/integration/__tests__/ignore-unknown.js +++ b/tests/integration/__tests__/ignore-unknown.js @@ -1,6 +1,4 @@ -"use strict"; - -const runPrettier = require("../runPrettier.js"); +import runPrettier from "../runPrettier.js"; describe("ignore-unknown dir", () => { runPrettier("cli/ignore-unknown", [ diff --git a/tests/integration/__tests__/ignore-vcs-files.js b/tests/integration/__tests__/ignore-vcs-files.js index 058bd15f6..2b4644df6 100644 --- a/tests/integration/__tests__/ignore-vcs-files.js +++ b/tests/integration/__tests__/ignore-vcs-files.js @@ -1,8 +1,7 @@ -"use strict"; +import runPrettier from "../runPrettier.js"; +import jestPathSerializer from "../path-serializer.js"; -const runPrettier = require("../runPrettier.js"); - -expect.addSnapshotSerializer(require("../path-serializer.js")); +expect.addSnapshotSerializer(jestPathSerializer); describe("ignores files in version control systems", () => { runPrettier("cli/ignore-vcs-files", [ diff --git a/tests/integration/__tests__/infer-parser.js b/tests/integration/__tests__/infer-parser.js index bd98fa819..86023043b 100644 --- a/tests/integration/__tests__/infer-parser.js +++ b/tests/integration/__tests__/infer-parser.js @@ -1,7 +1,6 @@ -"use strict"; - -const prettier = require("prettier-local"); -const runPrettier = require("../runPrettier.js"); +import prettier from "prettier-local"; +import { jest } from "@jest/globals"; +import runPrettier from "../runPrettier.js"; describe("stdin no path and no parser", () => { describe("logs error and exits with 2", () => { diff --git a/tests/integration/__tests__/invalid-ignore.js b/tests/integration/__tests__/invalid-ignore.js index 55ed1cc7a..9569e5e8d 100644 --- a/tests/integration/__tests__/invalid-ignore.js +++ b/tests/integration/__tests__/invalid-ignore.js @@ -1,10 +1,12 @@ -"use strict"; +import path from "node:path"; +import prettier from "prettier-local"; +import createEsmUtils from "esm-utils"; +import runPrettier from "../runPrettier.js"; +import jestPathSerializer from "../path-serializer.js"; -const path = require("path"); -const prettier = require("prettier-local"); -const runPrettier = require("../runPrettier.js"); +const { __dirname } = createEsmUtils(import.meta); -expect.addSnapshotSerializer(require("../path-serializer.js")); +expect.addSnapshotSerializer(jestPathSerializer); describe("throw error with invalid ignore", () => { runPrettier("cli/invalid-ignore", ["something.js"]).test({ diff --git a/tests/integration/__tests__/line-suffix-boundary.js b/tests/integration/__tests__/line-suffix-boundary.js index 8e1cd7a03..665a099f4 100644 --- a/tests/integration/__tests__/line-suffix-boundary.js +++ b/tests/integration/__tests__/line-suffix-boundary.js @@ -1,13 +1,10 @@ -"use strict"; - /** @type {import('prettier')} */ -const prettier = require("prettier-local"); +import prettier from "prettier-local"; +import printDoc from "../printDoc.js"; const { group, indent, line, lineSuffix, lineSuffixBoundary, softline } = prettier.doc.builders; -const printDoc = require("../printDoc.js"); - describe("lineSuffixBoundary", () => { test("should be correctly treated as a potential line break in `fits`", () => { const doc = group([ diff --git a/tests/integration/__tests__/list-different.js b/tests/integration/__tests__/list-different.js index 2de416d56..084c5b6db 100644 --- a/tests/integration/__tests__/list-different.js +++ b/tests/integration/__tests__/list-different.js @@ -1,6 +1,4 @@ -"use strict"; - -const runPrettier = require("../runPrettier.js"); +import runPrettier from "../runPrettier.js"; describe("checks stdin with --list-different", () => { runPrettier("cli/with-shebang", ["--list-different", "--parser", "babel"], { diff --git a/tests/integration/__tests__/load-toml.js b/tests/integration/__tests__/load-toml.js index fb92b1cf9..879707c57 100644 --- a/tests/integration/__tests__/load-toml.js +++ b/tests/integration/__tests__/load-toml.js @@ -1,6 +1,4 @@ -"use strict"; - -const loadToml = require("../../../src/utils/load-toml.js"); +import loadToml from "../../../src/utils/load-toml.js"; describe("TOML", () => { const exampleFilePath = "example.toml"; diff --git a/tests/integration/__tests__/loglevel.js b/tests/integration/__tests__/loglevel.js index 752d2530f..5bbf1c587 100644 --- a/tests/integration/__tests__/loglevel.js +++ b/tests/integration/__tests__/loglevel.js @@ -1,7 +1,5 @@ -"use strict"; - -const stripAnsi = require("strip-ansi"); -const runPrettier = require("../runPrettier.js"); +import stripAnsi from "strip-ansi"; +import runPrettier from "../runPrettier.js"; test("do not show logs with --loglevel silent", async () => { await runPrettierWithLogLevel("silent", null); diff --git a/tests/integration/__tests__/normalize-doc.js b/tests/integration/__tests__/normalize-doc.js index 62342c62e..8f28646fe 100644 --- a/tests/integration/__tests__/normalize-doc.js +++ b/tests/integration/__tests__/normalize-doc.js @@ -1,6 +1,4 @@ -"use strict"; - -const prettier = require("prettier-local"); +import prettier from "prettier-local"; const docBuilders = prettier.doc.builders; const docUtils = prettier.doc.utils; diff --git a/tests/integration/__tests__/package.json b/tests/integration/__tests__/package.json new file mode 100644 index 000000000..3dbc1ca59 --- /dev/null +++ b/tests/integration/__tests__/package.json @@ -0,0 +1,3 @@ +{ + "type": "module" +} diff --git a/tests/integration/__tests__/parser-api.js b/tests/integration/__tests__/parser-api.js index 3d6920c31..1761753af 100644 --- a/tests/integration/__tests__/parser-api.js +++ b/tests/integration/__tests__/parser-api.js @@ -1,7 +1,5 @@ -"use strict"; - -const prettier = require("prettier-local"); -const runPrettier = require("../runPrettier.js"); +import prettier from "prettier-local"; +import runPrettier from "../runPrettier.js"; test("allows custom parser provided as object", () => { const output = prettier.format("1", { diff --git a/tests/integration/__tests__/patterns-dirs.js b/tests/integration/__tests__/patterns-dirs.js index 803b41377..554cd595b 100644 --- a/tests/integration/__tests__/patterns-dirs.js +++ b/tests/integration/__tests__/patterns-dirs.js @@ -1,11 +1,13 @@ -"use strict"; +import fs from "node:fs"; +import path from "node:path"; +import createEsmUtils from "esm-utils"; +import runPrettier from "../runPrettier.js"; +import jestPathSerializer from "../path-serializer.js"; +import { projectRoot } from "../env.js"; -const path = require("path"); -const fs = require("fs"); -const runPrettier = require("../runPrettier.js"); -const { projectRoot } = require("../env.js"); +const { __dirname } = createEsmUtils(import.meta); -expect.addSnapshotSerializer(require("../path-serializer.js")); +expect.addSnapshotSerializer(jestPathSerializer); // ESLint-like behavior // https://github.com/prettier/prettier/pull/6639#issuecomment-548949954 diff --git a/tests/integration/__tests__/patterns-glob.js b/tests/integration/__tests__/patterns-glob.js index 4bb648939..b34847789 100644 --- a/tests/integration/__tests__/patterns-glob.js +++ b/tests/integration/__tests__/patterns-glob.js @@ -1,8 +1,7 @@ -"use strict"; +import runPrettier from "../runPrettier.js"; +import jestPathSerializer from "../path-serializer.js"; -const runPrettier = require("../runPrettier.js"); - -expect.addSnapshotSerializer(require("../path-serializer.js")); +expect.addSnapshotSerializer(jestPathSerializer); /* fixtures-1/ diff --git a/tests/integration/__tests__/patterns.js b/tests/integration/__tests__/patterns.js index 455829833..5f7b73a36 100644 --- a/tests/integration/__tests__/patterns.js +++ b/tests/integration/__tests__/patterns.js @@ -1,8 +1,7 @@ -"use strict"; +import runPrettier from "../runPrettier.js"; +import jestPathSerializer from "../path-serializer.js"; -const runPrettier = require("../runPrettier.js"); - -expect.addSnapshotSerializer(require("../path-serializer.js")); +expect.addSnapshotSerializer(jestPathSerializer); describe("multiple patterns", () => { runPrettier("cli/patterns", [ diff --git a/tests/integration/__tests__/piped-output.js b/tests/integration/__tests__/piped-output.js index ad0cc248d..9385c2df5 100644 --- a/tests/integration/__tests__/piped-output.js +++ b/tests/integration/__tests__/piped-output.js @@ -1,6 +1,4 @@ -"use strict"; - -const runPrettier = require("../runPrettier.js"); +import runPrettier from "../runPrettier.js"; describe("output with --check + unformatted differs when piped", () => { const result0 = runPrettier( diff --git a/tests/integration/__tests__/plugin-default-options.js b/tests/integration/__tests__/plugin-default-options.js index 76c9f4002..668ddf921 100644 --- a/tests/integration/__tests__/plugin-default-options.js +++ b/tests/integration/__tests__/plugin-default-options.js @@ -1,6 +1,4 @@ -"use strict"; - -const runPrettier = require("../runPrettier.js"); +import runPrettier from "../runPrettier.js"; describe("plugin default options should work", () => { runPrettier( diff --git a/tests/integration/__tests__/plugin-extensions.js b/tests/integration/__tests__/plugin-extensions.js index 2bba45602..03a66ebe7 100644 --- a/tests/integration/__tests__/plugin-extensions.js +++ b/tests/integration/__tests__/plugin-extensions.js @@ -1,6 +1,4 @@ -"use strict"; - -const runPrettier = require("../runPrettier.js"); +import runPrettier from "../runPrettier.js"; const EOL = "\n"; describe("uses 'extensions' from languages to determine parser", () => { diff --git a/tests/integration/__tests__/plugin-flush-line-suffix.js b/tests/integration/__tests__/plugin-flush-line-suffix.js index 0ed261439..c87e8aeac 100644 --- a/tests/integration/__tests__/plugin-flush-line-suffix.js +++ b/tests/integration/__tests__/plugin-flush-line-suffix.js @@ -1,6 +1,4 @@ -"use strict"; - -const runPrettier = require("../runPrettier.js"); +import runPrettier from "../runPrettier.js"; describe("flush all line-suffix content", () => { runPrettier("plugins/flushLineSuffix", ["*.foo", "--plugin=./plugin"], { diff --git a/tests/integration/__tests__/plugin-options-string.js b/tests/integration/__tests__/plugin-options-string.js index 1dd3a4d88..684810564 100644 --- a/tests/integration/__tests__/plugin-options-string.js +++ b/tests/integration/__tests__/plugin-options-string.js @@ -1,7 +1,5 @@ -"use strict"; - -const snapshotDiff = require("snapshot-diff"); -const runPrettier = require("../runPrettier.js"); +import snapshotDiff from "snapshot-diff"; +import runPrettier from "../runPrettier.js"; test("show external options with `--help`", async () => { const originalStdout = await runPrettier("plugins/options-string", ["--help"]) diff --git a/tests/integration/__tests__/plugin-options.js b/tests/integration/__tests__/plugin-options.js index 22cafb738..a7fa0cf4d 100644 --- a/tests/integration/__tests__/plugin-options.js +++ b/tests/integration/__tests__/plugin-options.js @@ -1,7 +1,5 @@ -"use strict"; - -const snapshotDiff = require("snapshot-diff"); -const runPrettier = require("../runPrettier.js"); +import snapshotDiff from "snapshot-diff"; +import runPrettier from "../runPrettier.js"; test("show external options with `--help`", async () => { const originalStdout = await runPrettier("plugins/options", ["--help"]) diff --git a/tests/integration/__tests__/plugin-precedence.js b/tests/integration/__tests__/plugin-precedence.js index 0770ab4b5..e56f21199 100644 --- a/tests/integration/__tests__/plugin-precedence.js +++ b/tests/integration/__tests__/plugin-precedence.js @@ -1,6 +1,4 @@ -"use strict"; - -const runPrettier = require("../runPrettier.js"); +import runPrettier from "../runPrettier.js"; describe("json-stringify takes precedence over json for package.json", () => { runPrettier("plugins", ["--stdin-filepath=package.json"], { diff --git a/tests/integration/__tests__/plugin-preprocess.js b/tests/integration/__tests__/plugin-preprocess.js index 0c0452e42..d3ef78e65 100644 --- a/tests/integration/__tests__/plugin-preprocess.js +++ b/tests/integration/__tests__/plugin-preprocess.js @@ -1,6 +1,4 @@ -"use strict"; - -const runPrettier = require("../runPrettier.js"); +import runPrettier from "../runPrettier.js"; const EOL = "\n"; describe("parser preprocess function is used to reshape input text", () => { diff --git a/tests/integration/__tests__/plugin-resolution.js b/tests/integration/__tests__/plugin-resolution.js index 8b51b7866..024858fd3 100644 --- a/tests/integration/__tests__/plugin-resolution.js +++ b/tests/integration/__tests__/plugin-resolution.js @@ -1,6 +1,4 @@ -"use strict"; - -const runPrettier = require("../runPrettier.js"); +import runPrettier from "../runPrettier.js"; const EOL = "\n"; describe("automatically loads 'prettier-plugin-*'", () => { diff --git a/tests/integration/__tests__/plugin-virtual-directory.js b/tests/integration/__tests__/plugin-virtual-directory.js index 44c95f6c4..baa83637c 100644 --- a/tests/integration/__tests__/plugin-virtual-directory.js +++ b/tests/integration/__tests__/plugin-virtual-directory.js @@ -1,6 +1,4 @@ -"use strict"; - -const runPrettier = require("../runPrettier.js"); +import runPrettier from "../runPrettier.js"; describe("plugin search should not crash when prettier isn't inside a directory", () => { runPrettier( diff --git a/tests/integration/__tests__/resolve-config-file.js b/tests/integration/__tests__/resolve-config-file.js index 274cc7b12..5546e7184 100644 --- a/tests/integration/__tests__/resolve-config-file.js +++ b/tests/integration/__tests__/resolve-config-file.js @@ -1,8 +1,8 @@ -"use strict"; +import path from "node:path"; +import prettier from "prettier-local"; +import createEsmUtils from "esm-utils"; -const path = require("path"); - -const prettier = require("prettier-local"); +const { __dirname } = createEsmUtils(import.meta); test("API resolveConfigFile", async () => { const result = await prettier.resolveConfigFile(); diff --git a/tests/integration/__tests__/schema.js b/tests/integration/__tests__/schema.js index 2fdddde97..d5572cf5b 100644 --- a/tests/integration/__tests__/schema.js +++ b/tests/integration/__tests__/schema.js @@ -1,7 +1,5 @@ -"use strict"; - -const prettier = require("prettier-local"); -const generateSchema = require("../../../scripts/utils/generate-schema.js"); +import prettier from "prettier-local"; +import generateSchema from "../../../scripts/utils/generate-schema.js"; test("schema", () => { expect(generateSchema(prettier.getSupportInfo().options)).toMatchSnapshot(); diff --git a/tests/integration/__tests__/skip-folders.js b/tests/integration/__tests__/skip-folders.js index dd1ea822b..dfc1d15ee 100644 --- a/tests/integration/__tests__/skip-folders.js +++ b/tests/integration/__tests__/skip-folders.js @@ -1,8 +1,7 @@ -"use strict"; +import runPrettier from "../runPrettier.js"; +import jestPathSerializer from "../path-serializer.js"; -const runPrettier = require("../runPrettier.js"); - -expect.addSnapshotSerializer(require("../path-serializer.js")); +expect.addSnapshotSerializer(jestPathSerializer); describe("skips folders in glob", () => { runPrettier("cli/skip-folders", ["**/*", "-l"]).test({ diff --git a/tests/integration/__tests__/stdin-filepath.js b/tests/integration/__tests__/stdin-filepath.js index 53f53b8e1..1e50b1eda 100644 --- a/tests/integration/__tests__/stdin-filepath.js +++ b/tests/integration/__tests__/stdin-filepath.js @@ -1,7 +1,5 @@ -"use strict"; - -const { isCI } = require("ci-info"); -const runPrettier = require("../runPrettier.js"); +import { isCI } from "ci-info"; +import runPrettier from "../runPrettier.js"; describe("format correctly if stdin content compatible with stdin-filepath", () => { runPrettier( diff --git a/tests/integration/__tests__/support-info.js b/tests/integration/__tests__/support-info.js index 57cd9d7df..10b3f711c 100644 --- a/tests/integration/__tests__/support-info.js +++ b/tests/integration/__tests__/support-info.js @@ -1,7 +1,5 @@ -"use strict"; - -const prettier = require("prettier-local"); -const runPrettier = require("../runPrettier.js"); +import prettier from "prettier-local"; +import runPrettier from "../runPrettier.js"; test("API getSupportInfo()", () => { expect(getCoreInfo()).toMatchSnapshot(); diff --git a/tests/integration/__tests__/syntax-error.js b/tests/integration/__tests__/syntax-error.js index e33c23e5b..3053a7797 100644 --- a/tests/integration/__tests__/syntax-error.js +++ b/tests/integration/__tests__/syntax-error.js @@ -1,6 +1,4 @@ -"use strict"; - -const runPrettier = require("../runPrettier.js"); +import runPrettier from "../runPrettier.js"; describe("exits with non-zero code when input has a syntax error", () => { runPrettier("cli/with-shebang", ["--parser", "babel"], { diff --git a/tests/integration/__tests__/third-party.js b/tests/integration/__tests__/third-party.js index a93477d23..3ecfbf95b 100644 --- a/tests/integration/__tests__/third-party.js +++ b/tests/integration/__tests__/third-party.js @@ -1,10 +1,12 @@ -"use strict"; +import path from "node:path"; +import createEsmUtils from "esm-utils"; +import { thirdParty } from "../env.js"; +import jestPathSerializer from "../path-serializer.js"; -const path = require("path"); -const { thirdParty } = require("../env.js"); +const { require, __dirname } = createEsmUtils(import.meta); const { cosmiconfig, cosmiconfigSync, isCI } = require(thirdParty); -expect.addSnapshotSerializer(require("../path-serializer.js")); +expect.addSnapshotSerializer(jestPathSerializer); // This don't has to be the same result as `prettier.resolveConfig`, // Because we are testing with default `cosmiconfigOptions` diff --git a/tests/integration/__tests__/util-shared.js b/tests/integration/__tests__/util-shared.js index 05b75c4c8..6947373e5 100644 --- a/tests/integration/__tests__/util-shared.js +++ b/tests/integration/__tests__/util-shared.js @@ -1,6 +1,4 @@ -"use strict"; - -const sharedUtil = require("../../../src/common/util-shared.js"); +import sharedUtil from "../../../src/common/util-shared.js"; test("shared util has correct structure", () => { expect(typeof sharedUtil.getMaxContinuousCount).toBe("function"); diff --git a/tests/integration/__tests__/with-config-precedence.js b/tests/integration/__tests__/with-config-precedence.js index 39944e10f..d8548d3b1 100644 --- a/tests/integration/__tests__/with-config-precedence.js +++ b/tests/integration/__tests__/with-config-precedence.js @@ -1,6 +1,4 @@ -"use strict"; - -const runPrettier = require("../runPrettier.js"); +import runPrettier from "../runPrettier.js"; describe("CLI overrides take precedence without --config-precedence", () => { runPrettier("cli/config/", [ diff --git a/tests/integration/__tests__/with-node-modules.js b/tests/integration/__tests__/with-node-modules.js index 689b9eafa..872583b82 100644 --- a/tests/integration/__tests__/with-node-modules.js +++ b/tests/integration/__tests__/with-node-modules.js @@ -1,8 +1,7 @@ -"use strict"; +import runPrettier from "../runPrettier.js"; +import jestPathSerializer from "../path-serializer.js"; -const runPrettier = require("../runPrettier.js"); - -expect.addSnapshotSerializer(require("../path-serializer.js")); +expect.addSnapshotSerializer(jestPathSerializer); describe("ignores node_modules by default", () => { runPrettier("cli/with-node-modules", ["**/*.js", "-l"]).test({ diff --git a/tests/integration/__tests__/with-parser-inference.js b/tests/integration/__tests__/with-parser-inference.js index caacb5d48..b45dae8ed 100644 --- a/tests/integration/__tests__/with-parser-inference.js +++ b/tests/integration/__tests__/with-parser-inference.js @@ -1,7 +1,5 @@ -"use strict"; - -const prettier = require("prettier-local"); -const runPrettier = require("../runPrettier.js"); +import prettier from "prettier-local"; +import runPrettier from "../runPrettier.js"; describe("infers postcss parser", () => { runPrettier("cli/with-parser-inference", ["--end-of-line", "lf", "*"]).test({ diff --git a/tests/integration/__tests__/with-shebang.js b/tests/integration/__tests__/with-shebang.js index 7d9e7bae7..36441733e 100644 --- a/tests/integration/__tests__/with-shebang.js +++ b/tests/integration/__tests__/with-shebang.js @@ -1,6 +1,4 @@ -"use strict"; - -const runPrettier = require("../runPrettier.js"); +import runPrettier from "../runPrettier.js"; describe("preserves shebang", () => { runPrettier("cli/with-shebang", ["--end-of-line", "lf", "issue1890.js"]).test( diff --git a/tests/integration/__tests__/write.js b/tests/integration/__tests__/write.js index a649af391..cb3f343c9 100644 --- a/tests/integration/__tests__/write.js +++ b/tests/integration/__tests__/write.js @@ -1,6 +1,4 @@ -"use strict"; - -const runPrettier = require("../runPrettier.js"); +import runPrettier from "../runPrettier.js"; describe("write file with --write + unformatted file", () => { runPrettier("cli/write", ["--write", "unformatted.js"]).test({ diff --git a/website/playground/Playground.js b/website/playground/Playground.js index 222896080..c3a88885f 100644 --- a/website/playground/Playground.js +++ b/website/playground/Playground.js @@ -8,7 +8,7 @@ import { shallowEqual } from "./helpers.js"; import * as urlHash from "./urlHash.js"; import formatMarkdown from "./markdown.js"; import * as util from "./util.js"; -import getCodeSample from "./codeSamples.js"; +import getCodeSample from "./codeSamples.mjs"; import { Sidebar, SidebarCategory } from "./sidebar/components.js"; import SidebarOptions from "./sidebar/SidebarOptions.js"; diff --git a/website/playground/codeSamples.js b/website/playground/codeSamples.mjs similarity index 100% rename from website/playground/codeSamples.js rename to website/playground/codeSamples.mjs diff --git a/yarn.lock b/yarn.lock index 7b8a5c8c1..c3448e0a4 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1338,7 +1338,7 @@ jest-mock "^27.4.2" jest-util "^27.4.2" -"@jest/globals@^27.4.2": +"@jest/globals@27.4.2", "@jest/globals@^27.4.2": version "27.4.2" resolved "https://registry.yarnpkg.com/@jest/globals/-/globals-27.4.2.tgz#56a402c5ebf22eba1d34e900772147f5126ea2d8" integrity sha512-KkfaHEttlGpXYAQTZHgrESiEPx2q/DKAFLGLFda1uGVrqc17snd3YVPhOxlXOHIzVPs+lQ/SDB2EIvxyGzb3Ew== @@ -1989,7 +1989,7 @@ asynckit@^0.4.0: resolved "https://registry.yarnpkg.com/asynckit/-/asynckit-0.4.0.tgz#c79ed97f7f34cb8f2ba1bc9790bcc366474b4b79" integrity sha1-x57Zf380y48robyXkLzDZkdLS3k= -babel-jest@27.4.2, babel-jest@^27.4.2: +babel-jest@^27.4.2: version "27.4.2" resolved "https://registry.yarnpkg.com/babel-jest/-/babel-jest-27.4.2.tgz#6edf80971045cfd44f3f10b6eda6007d95f62742" integrity sha512-MADrjb3KBO2eyZCAc6QaJg6RT5u+6oEdDyHO5HEalnpwQ6LrhTsQF2Kj1Wnz2t6UPXIXPk18dSXXOT0wF5yTxA==