From 592f27ce0b71b98063c0ef2007ed6b1336713eec Mon Sep 17 00:00:00 2001 From: fisker Cheung Date: Wed, 20 Jul 2022 23:18:24 +0800 Subject: [PATCH] Fix integration test (#12859) --- .github/workflows/dev-package-test.yml | 2 +- .github/workflows/dev-test.yml | 46 +++++++------------ .github/workflows/prod-test.yml | 18 ++------ .prettierignore | 22 +++++++-- jest-format-test.config.mjs | 11 ----- jest-integration-test.config.mjs | 14 ------ jest.config.mjs | 10 ++-- package.json | 6 +-- tests/config/prettier-entry.common.cjs | 7 --- tests/integration/__tests__/bundle.js | 6 +-- .../__tests__/config-resolution.js | 2 +- tests/integration/__tests__/debug-api.js | 2 +- tests/integration/__tests__/doc-builders.js | 2 +- .../integration/__tests__/doc-mark-as-root.js | 2 +- tests/integration/__tests__/doc-trim.js | 2 +- .../__tests__/doc-utils-clean-doc.js | 2 +- tests/integration/__tests__/early-exit.js | 3 +- tests/integration/__tests__/file-info.js | 2 +- tests/integration/__tests__/format-ast.js | 2 +- tests/integration/__tests__/format.js | 2 +- tests/integration/__tests__/infer-parser.js | 21 ++++++--- tests/integration/__tests__/invalid-ignore.js | 2 +- .../__tests__/line-suffix-boundary.js | 4 +- tests/integration/__tests__/normalize-doc.js | 2 +- tests/integration/__tests__/parser-api.js | 3 +- .../__tests__/resolve-config-file.js | 2 +- tests/integration/__tests__/schema.js | 2 +- tests/integration/__tests__/support-info.js | 3 +- .../__tests__/with-parser-inference.js | 3 +- .../@prettier/plugin-foo/index.js | 23 ++++++---- .../@user/prettier-plugin-foobar/index.js | 23 ++++++---- .../node_modules/prettier-plugin-bar/index.js | 29 ++++++------ .../plugins/automatic/package.json | 4 +- .../plugins/automatic/prettier-plugin-bar.js | 33 +++++++------ .../@company/prettier-plugin-bespoke/main.js | 21 +++++---- .../plugins/defaultOptions/plugin.cjs | 20 ++++---- .../integration/plugins/extensions/plugin.cjs | 25 +++++----- .../plugins/flushLineSuffix/plugin.cjs | 25 +++++----- .../plugins/options-string/plugin.cjs | 20 ++++---- tests/integration/plugins/options/plugin.cjs | 26 +++++------ .../integration/plugins/preprocess/plugin.cjs | 18 ++++---- tests/integration/print-doc.js | 2 +- yarn.lock | 8 ++-- 43 files changed, 236 insertions(+), 246 deletions(-) delete mode 100644 jest-format-test.config.mjs delete mode 100644 jest-integration-test.config.mjs delete mode 100644 tests/config/prettier-entry.common.cjs diff --git a/.github/workflows/dev-package-test.yml b/.github/workflows/dev-package-test.yml index 9239d9d3d..e0c8b87b0 100644 --- a/.github/workflows/dev-package-test.yml +++ b/.github/workflows/dev-package-test.yml @@ -50,4 +50,4 @@ jobs: run: npm install --global pnpm - name: Run Tests - run: yarn test:dev-package --maxWorkers=2 + run: yarn test:dev-package diff --git a/.github/workflows/dev-test.yml b/.github/workflows/dev-test.yml index 74475fc74..51ee1b19e 100644 --- a/.github/workflows/dev-test.yml +++ b/.github/workflows/dev-test.yml @@ -53,27 +53,13 @@ jobs: - name: Install Dependencies run: yarn install --immutable - # - name: Run Integration Tests (macOS) - # if: ${{ matrix.os == 'macos-latest' }} - # run: yarn test:integration --maxWorkers=4 + - name: Run Tests + if: ${{ !matrix.ENABLE_CODE_COVERAGE }} + run: yarn test - # - name: Run Integration Tests (Linux and Windows) - # if: ${{ matrix.os != 'macos-latest' }} - # run: yarn test:integration --maxWorkers=2 - - # - name: Upload Coverage - # uses: codecov/codecov-action@v2.1.0 - # if: ${{ matrix.ENABLE_CODE_COVERAGE }} - # with: - # fail_ci_if_error: true - - - name: Run Format Tests (macOS) - if: ${{ matrix.os == 'macos-latest' }} - run: yarn test:format --maxWorkers=4 - - - name: Run Format Tests (Linux and Windows) - if: ${{ matrix.os != 'macos-latest' }} - run: yarn c8 yarn test:format --maxWorkers=2 + - name: Run Tests (coverage) + if: ${{ matrix.ENABLE_CODE_COVERAGE }} + run: yarn c8 yarn test - name: Upload Coverage uses: codecov/codecov-action@v3.1.0 @@ -81,14 +67,14 @@ jobs: with: fail_ci_if_error: true - # # #8073 test - # - name: Run Tests (PRETTIER_FALLBACK_RESOLVE) - # run: yarn test "tests/integration/__tests__/(config|plugin)" - # env: - # PRETTIER_FALLBACK_RESOLVE: true + # #8073 test + - name: Run Tests (PRETTIER_FALLBACK_RESOLVE) + run: yarn c8 yarn test "tests/integration/__tests__/(config|plugin)" + env: + PRETTIER_FALLBACK_RESOLVE: true - # - name: Upload Coverage (PRETTIER_FALLBACK_RESOLVE) - # uses: codecov/codecov-action@v3.1.0 - # if: ${{ matrix.ENABLE_CODE_COVERAGE }} - # with: - # fail_ci_if_error: true + - name: Upload Coverage (PRETTIER_FALLBACK_RESOLVE) + uses: codecov/codecov-action@v3.1.0 + if: ${{ matrix.ENABLE_CODE_COVERAGE }} + with: + fail_ci_if_error: true diff --git a/.github/workflows/prod-test.yml b/.github/workflows/prod-test.yml index 72861b7ed..81c6e7a28 100644 --- a/.github/workflows/prod-test.yml +++ b/.github/workflows/prod-test.yml @@ -104,21 +104,11 @@ jobs: name: dist path: dist - - name: Run Tests (macOS) - if: ${{ matrix.os == 'macos-latest' }} - run: yarn test:dist --maxWorkers=4 + - name: Run Tests + run: yarn test:dist - - name: Run Tests (Linux and Windows) - if: ${{ matrix.os != 'macos-latest' }} - run: yarn test:dist --maxWorkers=2 - - - name: Run Format Tests (standalone) (macOS) - if: ${{ matrix.os == 'macos-latest' }} - run: yarn test:dist-standalone --maxWorkers=4 - - - name: Run Format Tests (standalone) (Linux and Windows) - if: ${{ matrix.os != 'macos-latest' }} - run: yarn test:dist-standalone --maxWorkers=2 + - name: Run Format Tests (standalone) + run: yarn test:dist-standalone # #8073 test - name: Run Tests (PRETTIER_FALLBACK_RESOLVE) diff --git a/.prettierignore b/.prettierignore index f5cf666ce..dd8e27f65 100644 --- a/.prettierignore +++ b/.prettierignore @@ -1,13 +1,29 @@ .tmp -dist/ .cache/ coverage/ +.nyc_output/ +.yarn/ +dist/ +node_modules/ + /tests/format/**/*.* !/tests/format/**/jsfmt.spec.js /tests/integration/cli/ -/tests/integration/plugins/ +/tests/integration/plugins/**/*.* +!/tests/integration/plugins/automatic/node_modules/@prettier/plugin-foo/index.js +!/tests/integration/plugins/automatic/node_modules/@user/prettier-plugin-foobar/index.js +!/tests/integration/plugins/automatic/node_modules/prettier-plugin-bar/index.js +!/tests/integration/plugins/automatic/package.json +!/tests/integration/plugins/automatic/prettier-plugin-bar.js +!/tests/integration/plugins/bespoke/node_modules/@company/prettier-plugin-bespoke/main.js +!/tests/integration/plugins/defaultOptions/plugin.cjs +!/tests/integration/plugins/extensions/plugin.cjs +!/tests/integration/plugins/flushLineSuffix/plugin.cjs +!/tests/integration/plugins/options-string/plugin.cjs +!/tests/integration/plugins/options/plugin.cjs +!/tests/integration/plugins/preprocess/plugin.cjs /tests/integration/custom-parsers/ + /website/build/ /website/static/lib/ /website/static/playground.js -.nyc_output diff --git a/jest-format-test.config.mjs b/jest-format-test.config.mjs deleted file mode 100644 index d3bf7a508..000000000 --- a/jest-format-test.config.mjs +++ /dev/null @@ -1,11 +0,0 @@ -import baseConfig from "./jest.config.mjs"; - -const config = { - ...baseConfig, - runner: "jest-light-runner", - testRegex: "tests/format/.*/jsfmt\\.spec\\.js$", - setupFiles: ["/tests/config/format-test-setup.js"], - projects: [], -}; - -export default config; diff --git a/jest-integration-test.config.mjs b/jest-integration-test.config.mjs deleted file mode 100644 index 5e7ec0ea1..000000000 --- a/jest-integration-test.config.mjs +++ /dev/null @@ -1,14 +0,0 @@ -import baseConfig from "./jest.config.mjs"; - -const config = { - ...baseConfig, - testRegex: "tests/integration/__tests__/.*\\.js$", - setupFiles: ["/tests/integration/integration-test-setup.js"], - projects: [], - moduleNameMapper: { - ...baseConfig.moduleNameMapper, - "prettier-local": "/tests/config/prettier-entry.common.cjs", - }, -}; - -export default config; diff --git a/jest.config.mjs b/jest.config.mjs index 2f44888d4..6ed3b77d1 100644 --- a/jest.config.mjs +++ b/jest.config.mjs @@ -33,10 +33,11 @@ if (!isProduction) { } const config = { - projects: [ - "/jest-format-test.config.mjs", - isProduction && "/jest-integration-test.config.mjs", - ].filter(Boolean), + setupFiles: [ + "/tests/config/format-test-setup.js", + "/tests/integration/integration-test-setup.js", + ], + runner: "jest-light-runner", snapshotSerializers: [ "jest-snapshot-serializer-raw", "jest-snapshot-serializer-ansi", @@ -45,6 +46,7 @@ const config = { escapeString: false, printBasicPrototype: false, }, + testRegex: "jsfmt\\.spec\\.js$|__tests__/.*\\.js$", testPathIgnorePatterns, collectCoverage: ENABLE_CODE_COVERAGE, collectCoverageFrom: ["/src/**/*.js", "/bin/**/*.js"], diff --git a/package.json b/package.json index 72690a1df..76fc89e1c 100644 --- a/package.json +++ b/package.json @@ -123,7 +123,7 @@ "esm-utils": "4.0.0", "execa": "6.1.0", "jest": "28.1.0", - "jest-light-runner": "0.2.2", + "jest-light-runner": "fisker/jest-light-runner#b5e893d3a7d301bfb5d68ed81eebadbe2bb0577d", "jest-snapshot-serializer-ansi": "1.0.0", "jest-snapshot-serializer-raw": "1.2.0", "jest-watch-typeahead": "1.1.0", @@ -140,9 +140,7 @@ }, "scripts": { "prepublishOnly": "echo \"Error: must publish from dist/\" && exit 1", - "test": "cross-env NODE_OPTIONS=--experimental-vm-modules jest", - "test:integration": "echo \"Disabled temporary\" && exit 1", - "test:format": "yarn test --config=jest-format-test.config.mjs", + "test": "cross-env NODE_OPTIONS=--experimental-vm-modules jest --runInBand", "test:dev-package": "cross-env INSTALL_PACKAGE=1 yarn test", "test:dist": "cross-env NODE_ENV=production yarn test", "test:dist-standalone": "cross-env TEST_STANDALONE=1 yarn test:dist", diff --git a/tests/config/prettier-entry.common.cjs b/tests/config/prettier-entry.common.cjs deleted file mode 100644 index a5e403cf1..000000000 --- a/tests/config/prettier-entry.common.cjs +++ /dev/null @@ -1,7 +0,0 @@ -"use strict"; - -// This file exists because plugins for test use `require('prettier-local')` - -const path = require("path"); - -module.exports = require(path.join(process.env.PRETTIER_DIR, "index.js")); diff --git a/tests/integration/__tests__/bundle.js b/tests/integration/__tests__/bundle.js index fce578a09..3eef409b7 100644 --- a/tests/integration/__tests__/bundle.js +++ b/tests/integration/__tests__/bundle.js @@ -8,7 +8,7 @@ import * as coreOptions from "../../../src/main/core-options.js"; import codeSamples from "../../../website/playground/codeSamples.mjs"; import jestPathSerializer from "../path-serializer.js"; -const { require } = createEsmUtils(import.meta); +const { require, importModule } = createEsmUtils(import.meta); expect.addSnapshotSerializer(jestPathSerializer); @@ -41,13 +41,13 @@ describe("standalone", () => { let esmStandalone; let esmPlugins; beforeAll(async () => { - esmStandalone = await import( + esmStandalone = await importModule( path.join(distDirectory, "esm/standalone.mjs") ); esmPlugins = await Promise.all( fastGlob .sync(["esm/parser-*.mjs"], { cwd: distDirectory, absolute: true }) - .map(async (file) => (await import(file)).default) + .map(async (file) => (await importModule(file)).default) ); }); diff --git a/tests/integration/__tests__/config-resolution.js b/tests/integration/__tests__/config-resolution.js index b0ece3aeb..5fd7ba99a 100644 --- a/tests/integration/__tests__/config-resolution.js +++ b/tests/integration/__tests__/config-resolution.js @@ -1,6 +1,6 @@ import path from "node:path"; -import prettier from "prettier-local"; import createEsmUtils from "esm-utils"; +import prettier from "../../config/prettier-entry.js"; import runPrettier from "../run-prettier.js"; import jestPathSerializer from "../path-serializer.js"; diff --git a/tests/integration/__tests__/debug-api.js b/tests/integration/__tests__/debug-api.js index 2df0467dc..a620dbbe2 100644 --- a/tests/integration/__tests__/debug-api.js +++ b/tests/integration/__tests__/debug-api.js @@ -1,5 +1,5 @@ -import prettier from "prettier-local"; import { outdent } from "outdent"; +import prettier from "../../config/prettier-entry.js"; const { __debug: { parse, formatAST, formatDoc, printToDoc, printDocToString }, diff --git a/tests/integration/__tests__/doc-builders.js b/tests/integration/__tests__/doc-builders.js index bfe0e395f..3849bed3c 100644 --- a/tests/integration/__tests__/doc-builders.js +++ b/tests/integration/__tests__/doc-builders.js @@ -1,4 +1,4 @@ -import prettier from "prettier-local"; +import prettier from "../../config/prettier-entry.js"; const { concat, join, diff --git a/tests/integration/__tests__/doc-mark-as-root.js b/tests/integration/__tests__/doc-mark-as-root.js index fa1f6b340..5dfba24b3 100644 --- a/tests/integration/__tests__/doc-mark-as-root.js +++ b/tests/integration/__tests__/doc-mark-as-root.js @@ -1,4 +1,4 @@ -import prettier from "prettier-local"; +import prettier from "../../config/prettier-entry.js"; 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 59b13dc65..5a374ab8c 100644 --- a/tests/integration/__tests__/doc-trim.js +++ b/tests/integration/__tests__/doc-trim.js @@ -1,5 +1,5 @@ -import prettier from "prettier-local"; import { outdent } from "outdent"; +import prettier from "../../config/prettier-entry.js"; 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 447d80e83..ae1a4b443 100644 --- a/tests/integration/__tests__/doc-utils-clean-doc.js +++ b/tests/integration/__tests__/doc-utils-clean-doc.js @@ -1,4 +1,4 @@ -import prettier from "prettier-local"; +import prettier from "../../config/prettier-entry.js"; 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 870fa667c..c9eafc685 100644 --- a/tests/integration/__tests__/early-exit.js +++ b/tests/integration/__tests__/early-exit.js @@ -1,4 +1,5 @@ -import prettier from "prettier-local"; +import prettier from "../../config/prettier-entry.js"; + describe("show version with --version", () => { runPrettier("cli/with-shebang", ["--version"]).test({ stdout: prettier.version + "\n", diff --git a/tests/integration/__tests__/file-info.js b/tests/integration/__tests__/file-info.js index 4c615251e..15101bf01 100644 --- a/tests/integration/__tests__/file-info.js +++ b/tests/integration/__tests__/file-info.js @@ -1,8 +1,8 @@ import path from "node:path"; import fs from "node:fs"; import { temporaryDirectory as getTemporaryDirectory } from "tempy"; -import prettier from "prettier-local"; import createEsmUtils from "esm-utils"; +import prettier from "../../config/prettier-entry.js"; import runPrettier from "../run-prettier.js"; import jestPathSerializer from "../path-serializer.js"; diff --git a/tests/integration/__tests__/format-ast.js b/tests/integration/__tests__/format-ast.js index 29808d665..604a581c9 100644 --- a/tests/integration/__tests__/format-ast.js +++ b/tests/integration/__tests__/format-ast.js @@ -1,4 +1,4 @@ -import prettier from "prettier-local"; +import prettier from "../../config/prettier-entry.js"; const { formatAST } = prettier.__debug; describe("formatAST", () => { diff --git a/tests/integration/__tests__/format.js b/tests/integration/__tests__/format.js index 9d878e7fd..543d44d55 100644 --- a/tests/integration/__tests__/format.js +++ b/tests/integration/__tests__/format.js @@ -1,5 +1,5 @@ -import prettier from "prettier-local"; import { outdent } from "outdent"; +import prettier from "../../config/prettier-entry.js"; import fooPlugin from "../plugins/defaultOptions/plugin.cjs"; test("yaml parser should handle CRLF correctly", async () => { diff --git a/tests/integration/__tests__/infer-parser.js b/tests/integration/__tests__/infer-parser.js index 74add0d7b..736afb6ba 100644 --- a/tests/integration/__tests__/infer-parser.js +++ b/tests/integration/__tests__/infer-parser.js @@ -1,5 +1,4 @@ -import prettier from "prettier-local"; -const { jest } = import.meta; +import prettier from "../../config/prettier-entry.js"; describe("stdin no path and no parser", () => { describe("logs error and exits with 2", () => { @@ -169,25 +168,33 @@ describe("--write and --list-different with unknown path and no parser", () => { describe("API with no path and no parser", () => { const _console = global.console; + const result = { called: 0, arguments: [] }; beforeEach(() => { - global.console = { warn: jest.fn() }; + global.console = { + warn(...args) { + result.called += 1; + result.arguments = args; + }, + }; }); afterEach(() => { + result.called = 0; + result.arguments = []; global.console = _console; }); test("prettier.format", async () => { expect(await prettier.format(" foo ( )")).toBe("foo();\n"); - expect(global.console.warn).toHaveBeenCalledTimes(1); - expect(global.console.warn.mock.calls[0]).toMatchSnapshot(); + expect(result.called).toBe(1); + expect(result.arguments).toMatchSnapshot(); }); test("prettier.check", async () => { expect(await prettier.check(" foo ( )")).toBe(false); - expect(global.console.warn).toHaveBeenCalledTimes(1); - expect(global.console.warn.mock.calls[0]).toMatchSnapshot(); + expect(result.called).toBe(1); + expect(result.arguments).toMatchSnapshot(); }); }); diff --git a/tests/integration/__tests__/invalid-ignore.js b/tests/integration/__tests__/invalid-ignore.js index 2fc5b2a60..e46a73f46 100644 --- a/tests/integration/__tests__/invalid-ignore.js +++ b/tests/integration/__tests__/invalid-ignore.js @@ -1,6 +1,6 @@ import path from "node:path"; -import prettier from "prettier-local"; import createEsmUtils from "esm-utils"; +import prettier from "../../config/prettier-entry.js"; import runPrettier from "../run-prettier.js"; import jestPathSerializer from "../path-serializer.js"; diff --git a/tests/integration/__tests__/line-suffix-boundary.js b/tests/integration/__tests__/line-suffix-boundary.js index c1cf8773e..15ba37663 100644 --- a/tests/integration/__tests__/line-suffix-boundary.js +++ b/tests/integration/__tests__/line-suffix-boundary.js @@ -1,6 +1,6 @@ -/** @type {import('prettier')} */ -import prettier from "prettier-local"; import { outdent } from "outdent"; +/** @type {import('prettier')} */ +import prettier from "../../config/prettier-entry.js"; import printDoc from "../print-doc.js"; const { group, indent, line, lineSuffix, lineSuffixBoundary, softline } = diff --git a/tests/integration/__tests__/normalize-doc.js b/tests/integration/__tests__/normalize-doc.js index 8f28646fe..997c2cfff 100644 --- a/tests/integration/__tests__/normalize-doc.js +++ b/tests/integration/__tests__/normalize-doc.js @@ -1,4 +1,4 @@ -import prettier from "prettier-local"; +import prettier from "../../config/prettier-entry.js"; const docBuilders = prettier.doc.builders; const docUtils = prettier.doc.utils; diff --git a/tests/integration/__tests__/parser-api.js b/tests/integration/__tests__/parser-api.js index 9d2ac5034..5d84e8be3 100644 --- a/tests/integration/__tests__/parser-api.js +++ b/tests/integration/__tests__/parser-api.js @@ -1,4 +1,5 @@ -import prettier from "prettier-local"; +import prettier from "../../config/prettier-entry.js"; + test("allows custom parser provided as object", async () => { const output = await prettier.format("1", { parser(text) { diff --git a/tests/integration/__tests__/resolve-config-file.js b/tests/integration/__tests__/resolve-config-file.js index cab323d9c..075f70ee8 100644 --- a/tests/integration/__tests__/resolve-config-file.js +++ b/tests/integration/__tests__/resolve-config-file.js @@ -1,6 +1,6 @@ import path from "node:path"; -import prettier from "prettier-local"; import createEsmUtils from "esm-utils"; +import prettier from "../../config/prettier-entry.js"; const { __dirname } = createEsmUtils(import.meta); diff --git a/tests/integration/__tests__/schema.js b/tests/integration/__tests__/schema.js index d70ee3ac0..9ccb9b57d 100644 --- a/tests/integration/__tests__/schema.js +++ b/tests/integration/__tests__/schema.js @@ -1,4 +1,4 @@ -import prettier from "prettier-local"; +import prettier from "../../config/prettier-entry.js"; import generateSchema from "../../../scripts/utils/generate-schema.mjs"; test("schema", async () => { diff --git a/tests/integration/__tests__/support-info.js b/tests/integration/__tests__/support-info.js index 86cad768d..49d186af7 100644 --- a/tests/integration/__tests__/support-info.js +++ b/tests/integration/__tests__/support-info.js @@ -1,4 +1,5 @@ -import prettier from "prettier-local"; +import prettier from "../../config/prettier-entry.js"; + test("API getSupportInfo()", async () => { expect(await getCoreInfo()).toMatchSnapshot(); }); diff --git a/tests/integration/__tests__/with-parser-inference.js b/tests/integration/__tests__/with-parser-inference.js index a921837ee..b6d4a0615 100644 --- a/tests/integration/__tests__/with-parser-inference.js +++ b/tests/integration/__tests__/with-parser-inference.js @@ -1,5 +1,6 @@ -import prettier from "prettier-local"; import { outdent } from "outdent"; +import prettier from "../../config/prettier-entry.js"; + describe("infers postcss parser", () => { runPrettier("cli/with-parser-inference", ["--end-of-line", "lf", "*"]).test({ status: 0, diff --git a/tests/integration/plugins/automatic/node_modules/@prettier/plugin-foo/index.js b/tests/integration/plugins/automatic/node_modules/@prettier/plugin-foo/index.js index d67de5ee9..e556f0634 100644 --- a/tests/integration/plugins/automatic/node_modules/@prettier/plugin-foo/index.js +++ b/tests/integration/plugins/automatic/node_modules/@prettier/plugin-foo/index.js @@ -1,25 +1,28 @@ "use strict"; -const prettier = require('../../../../../../config/prettier-entry.common.cjs'); -const concat = prettier.doc.builders.concat; - module.exports = { languages: [ { name: "foo", parsers: ["foo"], - extensions: [".foo"] - } + extensions: [".foo"], + }, ], parsers: { foo: { parse: text => ({ text }), - astFormat: "foo" - } + astFormat: "foo", + }, }, printers: { foo: { - print: path => concat(["foo+", path.getValue().text]) - } - } + async print(path) { + const { default: prettier } = await import( + "../../../../../../config/prettier-entry.js" + ); + const { concat } = prettier.doc.builders; + return concat(["foo+", path.getValue().text]); + }, + }, + }, }; diff --git a/tests/integration/plugins/automatic/node_modules/@user/prettier-plugin-foobar/index.js b/tests/integration/plugins/automatic/node_modules/@user/prettier-plugin-foobar/index.js index 08668924b..c062a9799 100644 --- a/tests/integration/plugins/automatic/node_modules/@user/prettier-plugin-foobar/index.js +++ b/tests/integration/plugins/automatic/node_modules/@user/prettier-plugin-foobar/index.js @@ -1,25 +1,28 @@ "use strict"; -const prettier = require('../../../../../../config/prettier-entry.common.cjs'); -const concat = prettier.doc.builders.concat; - module.exports = { languages: [ { name: "foobar", parsers: ["foobar"], - extensions: [".foobar"] - } + extensions: [".foobar"], + }, ], parsers: { foobar: { parse: text => ({ text }), - astFormat: "foobar" - } + astFormat: "foobar", + }, }, printers: { foobar: { - print: path => concat(["foobar+", path.getValue().text]) - } - } + async print(path) { + const { default: prettier } = await import( + "../../../../../../config/prettier-entry.js" + ); + const { concat } = prettier.doc.builders; + return concat(["foobar+", path.getValue().text]); + }, + }, + }, }; diff --git a/tests/integration/plugins/automatic/node_modules/prettier-plugin-bar/index.js b/tests/integration/plugins/automatic/node_modules/prettier-plugin-bar/index.js index 432ff0a39..a49e9e4bc 100644 --- a/tests/integration/plugins/automatic/node_modules/prettier-plugin-bar/index.js +++ b/tests/integration/plugins/automatic/node_modules/prettier-plugin-bar/index.js @@ -1,31 +1,30 @@ "use strict"; -const prettier = require('../../../../../config/prettier-entry.common.cjs'); -const { concat } = prettier.doc.builders; - module.exports = { languages: [ { name: "bar", - parsers: ["bar"] - } + parsers: ["bar"], + }, ], parsers: { bar: { parse: text => ({ text }), - astFormat: "bar" - } + astFormat: "bar", + }, }, printers: { bar: { - print: path => - concat([ - "content from `prettier-plugin-bar` package + ", - path.getValue().text - ]) - } + async print(path) { + const { default: prettier } = await import( + "../../../../../config/prettier-entry.js" + ); + const { concat } = prettier.doc.builders; + return concat(["content from `prettier-plugin-bar` package + ", path.getValue().text]); + }, + }, }, defaultOptions: { - tabWidth: 4 - } + tabWidth: 4, + }, }; diff --git a/tests/integration/plugins/automatic/package.json b/tests/integration/plugins/automatic/package.json index b731bd61b..5bbefffba 100644 --- a/tests/integration/plugins/automatic/package.json +++ b/tests/integration/plugins/automatic/package.json @@ -1 +1,3 @@ -{"type": "commonjs"} +{ + "type": "commonjs" +} diff --git a/tests/integration/plugins/automatic/prettier-plugin-bar.js b/tests/integration/plugins/automatic/prettier-plugin-bar.js index 7c11b639a..ce32e6a9f 100644 --- a/tests/integration/plugins/automatic/prettier-plugin-bar.js +++ b/tests/integration/plugins/automatic/prettier-plugin-bar.js @@ -1,31 +1,34 @@ "use strict"; -const prettier = require("../../../config/prettier-entry.common.cjs"); -const { concat } = prettier.doc.builders; - module.exports = { languages: [ { name: "bar", - parsers: ["bar"] - } + parsers: ["bar"], + }, ], parsers: { bar: { - parse: text => ({ text }), - astFormat: "bar" - } + parse: (text) => ({ text }), + astFormat: "bar", + }, }, printers: { bar: { - print: path => - concat([ + async print(path) { + const { default: prettier } = await import( + "../../../config/prettier-entry.js" + ); + const { concat } = prettier.doc.builders; + + return concat([ "content from `prettier-plugin-bar.js` file + ", - path.getValue().text - ]) - } + path.getValue().text, + ]); + }, + }, }, defaultOptions: { - tabWidth: 4 - } + tabWidth: 4, + }, }; diff --git a/tests/integration/plugins/bespoke/node_modules/@company/prettier-plugin-bespoke/main.js b/tests/integration/plugins/bespoke/node_modules/@company/prettier-plugin-bespoke/main.js index 10e6f1e52..2b3ee9ec5 100644 --- a/tests/integration/plugins/bespoke/node_modules/@company/prettier-plugin-bespoke/main.js +++ b/tests/integration/plugins/bespoke/node_modules/@company/prettier-plugin-bespoke/main.js @@ -1,24 +1,27 @@ "use strict"; -const prettier = require('../../../../../../config/prettier-entry.common.cjs'); -const concat = prettier.doc.builders.concat; - module.exports = { languages: [ { name: "bespoke", - parsers: ["bespoke"] - } + parsers: ["bespoke"], + }, ], parsers: { bespoke: { parse: text => ({ text }), astFormat: "bespoke" - } + }, }, printers: { bespoke: { - print: path => concat(["bespoke+", path.getValue().text]) - } - } + async print(path) { + const { default: prettier } = await import( + "../../../../../../config/prettier-entry.js" + ); + const { concat } = prettier.doc.builders; + return concat(["bespoke+", path.getValue().text]); + }, + }, + }, }; diff --git a/tests/integration/plugins/defaultOptions/plugin.cjs b/tests/integration/plugins/defaultOptions/plugin.cjs index 1c72441cc..3f08e6fcf 100644 --- a/tests/integration/plugins/defaultOptions/plugin.cjs +++ b/tests/integration/plugins/defaultOptions/plugin.cjs @@ -5,26 +5,26 @@ module.exports = { { name: "foo", parsers: ["foo-parser"], - extensions: [".foo"] - } + extensions: [".foo"], + }, ], defaultOptions: { tabWidth: 8, - bracketSpacing: false + bracketSpacing: false, }, parsers: { "foo-parser": { - parse: text => ({ text }), - astFormat: "foo-ast" - } + parse: (text) => ({ text }), + astFormat: "foo-ast", + }, }, printers: { "foo-ast": { print: (path, options) => JSON.stringify({ tabWidth: options.tabWidth, - bracketSpacing: options.bracketSpacing - }) - } - } + bracketSpacing: options.bracketSpacing, + }), + }, + }, }; diff --git a/tests/integration/plugins/extensions/plugin.cjs b/tests/integration/plugins/extensions/plugin.cjs index 27e2fed90..0fd9cbd27 100644 --- a/tests/integration/plugins/extensions/plugin.cjs +++ b/tests/integration/plugins/extensions/plugin.cjs @@ -1,25 +1,28 @@ "use strict"; -const prettier = require("../../../config/prettier-entry.common.cjs"); -const { concat } = prettier.doc.builders; - module.exports = { languages: [ { name: "foo", parsers: ["foo-parser"], - extensions: [".foo"] - } + extensions: [".foo"], + }, ], parsers: { "foo-parser": { - parse: text => ({ text }), - astFormat: "foo-ast" - } + parse: (text) => ({ text }), + astFormat: "foo-ast", + }, }, printers: { "foo-ast": { - print: path => concat(["!", path.getValue().text]) - } - } + async print(path) { + const { default: prettier } = await import( + "../../../config/prettier-entry.js" + ); + const { concat } = prettier.doc.builders; + return concat(["!", path.getValue().text]); + }, + }, + }, }; diff --git a/tests/integration/plugins/flushLineSuffix/plugin.cjs b/tests/integration/plugins/flushLineSuffix/plugin.cjs index 709d9d257..fea833ac4 100644 --- a/tests/integration/plugins/flushLineSuffix/plugin.cjs +++ b/tests/integration/plugins/flushLineSuffix/plugin.cjs @@ -1,25 +1,28 @@ "use strict"; -const prettier = require("../../../config/prettier-entry.common.cjs"); -const { lineSuffix } = prettier.doc.builders; - module.exports = { languages: [ { name: "foo", parsers: ["foo-parser"], - extensions: [".foo"] - } + extensions: [".foo"], + }, ], parsers: { "foo-parser": { - parse: text => ({ text }), - astFormat: "foo-ast" - } + parse: (text) => ({ text }), + astFormat: "foo-ast", + }, }, printers: { "foo-ast": { - print: path => lineSuffix(path.getValue().text.trim()) - } - } + async print(path) { + const { default: prettier } = await import( + "../../../config/prettier-entry.js" + ); + const { lineSuffix } = prettier.doc.builders; + return lineSuffix(path.getValue().text.trim()); + }, + }, + }, }; diff --git a/tests/integration/plugins/options-string/plugin.cjs b/tests/integration/plugins/options-string/plugin.cjs index 110902001..85f5cc5c2 100644 --- a/tests/integration/plugins/options-string/plugin.cjs +++ b/tests/integration/plugins/options-string/plugin.cjs @@ -6,26 +6,26 @@ module.exports = { name: "foo", parsers: ["foo-parser"], extensions: [".foo"], - since: "1.0.0" - } + since: "1.0.0", + }, ], options: { fooString: { type: "string", default: "bar", - description: "foo description" - } + description: "foo description", + }, }, parsers: { "foo-parser": { - parse: text => ({ text }), - astFormat: "foo-ast" - } + parse: (text) => ({ text }), + astFormat: "foo-ast", + }, }, printers: { "foo-ast": { print: (path, options) => - options.fooString ? `foo:${options.fooString}` : path.getValue().text - } - } + options.fooString ? `foo:${options.fooString}` : path.getValue().text, + }, + }, }; diff --git a/tests/integration/plugins/options/plugin.cjs b/tests/integration/plugins/options/plugin.cjs index 2357369fb..2191f6994 100644 --- a/tests/integration/plugins/options/plugin.cjs +++ b/tests/integration/plugins/options/plugin.cjs @@ -6,8 +6,8 @@ module.exports = { name: "foo", parsers: ["foo-parser"], extensions: [".foo"], - since: "1.0.0" - } + since: "1.0.0", + }, ], options: { fooOption: { @@ -17,25 +17,25 @@ module.exports = { choices: [ { value: "bar", - description: "bar description" + description: "bar description", }, { value: "baz", - description: "baz description" - } - ] - } + description: "baz description", + }, + ], + }, }, parsers: { "foo-parser": { - parse: text => ({ text }), - astFormat: "foo-ast" - } + parse: (text) => ({ text }), + astFormat: "foo-ast", + }, }, printers: { "foo-ast": { print: (path, options) => - options.fooOption ? `foo:${options.fooOption}` : path.getValue().text - } - } + options.fooOption ? `foo:${options.fooOption}` : path.getValue().text, + }, + }, }; diff --git a/tests/integration/plugins/preprocess/plugin.cjs b/tests/integration/plugins/preprocess/plugin.cjs index 2405c6c12..0e11e2138 100644 --- a/tests/integration/plugins/preprocess/plugin.cjs +++ b/tests/integration/plugins/preprocess/plugin.cjs @@ -6,19 +6,19 @@ module.exports = { name: "foo", parsers: ["foo-parser"], extensions: [".foo"], - since: "1.0.0" - } + since: "1.0.0", + }, ], parsers: { "foo-parser": { - preprocess: text => `preprocessed:${text}`, - parse: text => ({ text }), - astFormat: "foo-ast" - } + preprocess: (text) => `preprocessed:${text}`, + parse: (text) => ({ text }), + astFormat: "foo-ast", + }, }, printers: { "foo-ast": { - print: path => path.getValue().text - } - } + print: (path) => path.getValue().text, + }, + }, }; diff --git a/tests/integration/print-doc.js b/tests/integration/print-doc.js index d6f1dd499..9ca0d5343 100644 --- a/tests/integration/print-doc.js +++ b/tests/integration/print-doc.js @@ -1,5 +1,5 @@ /** @type {import('prettier')} */ -import prettier from "prettier-local"; +import prettier from "../config/prettier-entry.js"; function printDoc(doc) { // This dummy plugin ignores the input and simply returns the given doc. diff --git a/yarn.lock b/yarn.lock index 50edef266..c281f218f 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5060,9 +5060,9 @@ __metadata: languageName: node linkType: hard -"jest-light-runner@npm:0.2.2": +"jest-light-runner@fisker/jest-light-runner#b5e893d3a7d301bfb5d68ed81eebadbe2bb0577d": version: 0.2.2 - resolution: "jest-light-runner@npm:0.2.2" + resolution: "jest-light-runner@https://github.com/fisker/jest-light-runner.git#commit=b5e893d3a7d301bfb5d68ed81eebadbe2bb0577d" dependencies: "@jest/expect": ^28.0.2 jest-circus: ^28.0.0 @@ -5073,7 +5073,7 @@ __metadata: supports-color: ^9.2.1 peerDependencies: jest: ^27.0.0 || ^28.0.0 - checksum: cf837fc1fbd1bb370dcf93f346d500118ba53b968594a36752cd67c1e57c0262334897919ccd188943b13b4262e5194502de5eca20c79c76f33c4ccabb01dd00 + checksum: 9eb43cacaad844853d1e53bf3205c5729fef6569e45407dd51cd39c18fa8491cfe981245dec49b0bbf4965cbd2e77730d41fba4836baf98b00b843a1b307e986 languageName: node linkType: hard @@ -6850,7 +6850,7 @@ __metadata: ignore: 5.2.0 jest: 28.1.0 jest-docblock: 28.1.1 - jest-light-runner: 0.2.2 + jest-light-runner: "fisker/jest-light-runner#b5e893d3a7d301bfb5d68ed81eebadbe2bb0577d" jest-snapshot-serializer-ansi: 1.0.0 jest-snapshot-serializer-raw: 1.2.0 jest-watch-typeahead: 1.1.0