From fb948bb15f31ade3b35e66b720f8d44260de45f8 Mon Sep 17 00:00:00 2001 From: fisker Cheung Date: Tue, 11 Apr 2023 08:44:23 +0800 Subject: [PATCH] Integration test: Rename `runPrettier` to `runCli` (#14687) --- .eslintrc.cjs | 2 +- .../await-cli-tests.js | 7 +- .../test.js | 18 +-- tests/integration/__tests__/arg-parsing.js | 22 ++-- tests/integration/__tests__/cache.js | 120 +++++++----------- tests/integration/__tests__/check.js | 10 +- tests/integration/__tests__/config-invalid.js | 29 ++--- .../__tests__/config-resolution.js | 18 +-- tests/integration/__tests__/cursor-offset.js | 4 +- tests/integration/__tests__/debug-check.js | 20 ++- .../integration/__tests__/debug-print-ast.js | 2 +- .../__tests__/debug-print-comments.js | 8 +- .../integration/__tests__/debug-print-doc.js | 2 +- tests/integration/__tests__/doc-trim.js | 2 +- tests/integration/__tests__/early-exit.js | 24 ++-- .../__tests__/error-on-unmatched-pattern.js | 8 +- tests/integration/__tests__/file-info.js | 30 ++--- tests/integration/__tests__/help-options.js | 2 +- .../__tests__/ignore-absolute-path.js | 2 +- tests/integration/__tests__/ignore-emoji.js | 10 +- .../__tests__/ignore-in-subdirectories.js | 12 +- tests/integration/__tests__/ignore-path.js | 10 +- .../__tests__/ignore-relative-path.js | 2 +- tests/integration/__tests__/ignore-unknown.js | 19 ++- .../integration/__tests__/ignore-vcs-files.js | 2 +- tests/integration/__tests__/infer-parser.js | 51 ++++---- tests/integration/__tests__/invalid-ignore.js | 2 +- tests/integration/__tests__/list-different.js | 8 +- tests/integration/__tests__/log-level.js | 28 ++-- tests/integration/__tests__/patterns-dirs.js | 6 +- tests/integration/__tests__/patterns-glob.js | 26 ++-- tests/integration/__tests__/patterns.js | 24 ++-- .../__tests__/performance-flags.js | 10 +- tests/integration/__tests__/piped-output.js | 16 +-- .../__tests__/plugin-default-options.js | 4 +- .../__tests__/plugin-extensions.js | 2 +- .../__tests__/plugin-flush-line-suffix.js | 2 +- .../__tests__/plugin-options-string.js | 12 +- tests/integration/__tests__/plugin-options.js | 23 ++-- .../__tests__/plugin-precedence.js | 2 +- .../__tests__/plugin-preprocess.js | 2 +- .../__tests__/plugin-resolution.js | 46 +++---- .../__tests__/plugin-virtual-directory.js | 2 +- tests/integration/__tests__/skip-folders.js | 13 +- tests/integration/__tests__/stdin-filepath.js | 36 +++--- tests/integration/__tests__/support-info.js | 2 +- tests/integration/__tests__/syntax-error.js | 2 +- .../__tests__/with-config-precedence.js | 30 ++--- .../__tests__/with-node-modules.js | 10 +- .../__tests__/with-parser-inference.js | 6 +- tests/integration/__tests__/with-shebang.js | 8 +- tests/integration/__tests__/write.js | 8 +- tests/integration/integration-test-setup.js | 4 +- .../{run-prettier.js => run-cli.js} | 22 ++-- 54 files changed, 359 insertions(+), 433 deletions(-) rename tests/integration/{run-prettier.js => run-cli.js} (87%) diff --git a/.eslintrc.cjs b/.eslintrc.cjs index 1804dd6cd..ed1c04979 100644 --- a/.eslintrc.cjs +++ b/.eslintrc.cjs @@ -311,7 +311,7 @@ module.exports = { }, globals: { run_spec: "readonly", - runPrettier: "readonly", + runCli: "readonly", }, }, { diff --git a/scripts/tools/eslint-plugin-prettier-internal-rules/await-cli-tests.js b/scripts/tools/eslint-plugin-prettier-internal-rules/await-cli-tests.js index b066f1a07..7a932fcca 100644 --- a/scripts/tools/eslint-plugin-prettier-internal-rules/await-cli-tests.js +++ b/scripts/tools/eslint-plugin-prettier-internal-rules/await-cli-tests.js @@ -3,7 +3,7 @@ const selector = [ "CallExpression", '[callee.type="Identifier"]', - '[callee.name="runPrettier"]', + '[callee.name="runCli"]', ].join(""); const MESSAGE_ID_CALL = "await-cli-tests/call"; @@ -16,9 +16,8 @@ module.exports = { url: "https://github.com/prettier/prettier/blob/main/scripts/tools/eslint-plugin-prettier-internal-rules/await-cli-tests.js", }, messages: { - [MESSAGE_ID_CALL]: - "'runPrettier()' should be awaited or calling `.test()`.", - [MESSAGE_ID_GETTER]: "'runPrettier().{{property}}' should be awaited.", + [MESSAGE_ID_CALL]: "'runCli()' should be awaited or calling `.test()`.", + [MESSAGE_ID_GETTER]: "'runCli().{{property}}' should be awaited.", }, }, create(context) { diff --git a/scripts/tools/eslint-plugin-prettier-internal-rules/test.js b/scripts/tools/eslint-plugin-prettier-internal-rules/test.js index a42b6bd72..95f90d5d6 100644 --- a/scripts/tools/eslint-plugin-prettier-internal-rules/test.js +++ b/scripts/tools/eslint-plugin-prettier-internal-rules/test.js @@ -16,26 +16,26 @@ const test = (ruleId, tests) => { test("await-cli-tests", { valid: [ - "async () => await runPrettier()", - "runPrettier().test()", - "notRunPrettier()", - "async () => await runPrettier().stderr", + "async () => await runCli()", + "runCli().test()", + "notRunCli()", + "async () => await runCli().stderr", outdent` async () => { - const originalStdout = await runPrettier("plugins/options", ["--help"]).stdout; + const originalStdout = await runCli("plugins/options", ["--help"]).stdout; } `, ], invalid: [ { - code: "runPrettier()", + code: "runCli()", errors: [ - { message: "'runPrettier()' should be awaited or calling `.test()`." }, + { message: "'runCli()' should be awaited or calling `.test()`." }, ], }, { - code: "runPrettier().stderr", - errors: [{ message: "'runPrettier().stderr' should be awaited." }], + code: "runCli().stderr", + errors: [{ message: "'runCli().stderr' should be awaited." }], }, ], }); diff --git a/tests/integration/__tests__/arg-parsing.js b/tests/integration/__tests__/arg-parsing.js index 9d20d9b78..209e5dff1 100644 --- a/tests/integration/__tests__/arg-parsing.js +++ b/tests/integration/__tests__/arg-parsing.js @@ -1,5 +1,5 @@ describe("boolean flags do not swallow the next argument", () => { - runPrettier("cli/arg-parsing", [ + runCli("cli/arg-parsing", [ "--end-of-line", "lf", "--single-quote", @@ -10,7 +10,7 @@ describe("boolean flags do not swallow the next argument", () => { }); describe("negated options work", () => { - runPrettier("cli/arg-parsing", [ + runCli("cli/arg-parsing", [ "--end-of-line", "lf", "--no-semi", @@ -21,7 +21,7 @@ describe("negated options work", () => { }); describe("unknown options are warned", () => { - runPrettier("cli/arg-parsing", [ + runCli("cli/arg-parsing", [ "--end-of-line", "lf", "file.js", @@ -32,7 +32,7 @@ describe("unknown options are warned", () => { }); describe("unknown negated options are warned", () => { - runPrettier("cli/arg-parsing", [ + runCli("cli/arg-parsing", [ "--end-of-line", "lf", "file.js", @@ -43,14 +43,14 @@ describe("unknown negated options are warned", () => { }); describe("unknown options not suggestion `_`", () => { - runPrettier("cli/arg-parsing", ["file.js", "-a"]).test({ + runCli("cli/arg-parsing", ["file.js", "-a"]).test({ status: 0, write: [], }); }); describe("allow overriding flags", () => { - runPrettier( + runCli( "cli/arg-parsing", ["--tab-width=1", "--tab-width=3", "--parser=babel"], { input: "function a() { b }" } @@ -63,7 +63,7 @@ describe("allow overriding flags", () => { describe("number file/dir", () => { const patterns = ["1", "2.2", "3", "4.44"]; for (const pattern of patterns) { - runPrettier("cli/arg-parsing/number", [ + runCli("cli/arg-parsing/number", [ "--parser=babel", "--list-different", pattern, @@ -73,7 +73,7 @@ describe("number file/dir", () => { write: [], }); } - runPrettier("cli/arg-parsing/number", [ + runCli("cli/arg-parsing/number", [ "--parser=babel", "--list-different", ...patterns, @@ -85,7 +85,7 @@ describe("number file/dir", () => { }); describe("deprecated option values are warned", () => { - runPrettier("cli/arg-parsing", ["file.js", "--jsx-bracket-same-line"]).test({ + runCli("cli/arg-parsing", ["file.js", "--jsx-bracket-same-line"]).test({ status: 0, }); }); @@ -93,11 +93,11 @@ describe("deprecated option values are warned", () => { describe("options with `cliName` should not allow to pass directly", () => { // `filepath` can only pass through `--stdin-filepath` // `plugins` and `pluginSearchDirs` works the same - runPrettier("cli/arg-parsing", ["--stdin-filepath", "file.js"], { + runCli("cli/arg-parsing", ["--stdin-filepath", "file.js"], { isTTY: false, input: "prettier()", }).test({ status: 0, stderr: "", write: [] }); - runPrettier("cli/arg-parsing", ["--filepath", "file.js"], { + runCli("cli/arg-parsing", ["--filepath", "file.js"], { isTTY: false, input: "prettier()", }).test({ status: 2, write: [] }); diff --git a/tests/integration/__tests__/cache.js b/tests/integration/__tests__/cache.js index 5d242c31e..c2e526fbc 100644 --- a/tests/integration/__tests__/cache.js +++ b/tests/integration/__tests__/cache.js @@ -55,7 +55,7 @@ describe("--cache option", () => { afterAll(clean); it("throw error when cache-strategy is invalid", async () => { - const { stderr } = await runPrettier(dir, [ + const { stderr } = await runCli(dir, [ "--cache", "--cache-strategy", "invalid", @@ -67,7 +67,7 @@ describe("--cache option", () => { }); it("throws error when use with --stdin-filepath", async () => { - const { stderr } = await runPrettier( + const { stderr } = await runCli( dir, ["--cache", "--stdin-filepath", "foo.js"], { input: "const a = a;" } @@ -76,7 +76,7 @@ describe("--cache option", () => { }); it("throws error when use `--cache-strategy` without `--cache`.", async () => { - const { stderr } = await runPrettier( + const { stderr } = await runCli( dir, ["foo.js", "--cache-strategy", "content"], { @@ -89,7 +89,7 @@ describe("--cache option", () => { }); it("throws error when `--cache-location` is a directory.", async () => { - const { stderr } = await runPrettier(dir, [ + const { stderr } = await runCli(dir, [ "foo.js", "--cache", "--cache-location", @@ -108,17 +108,12 @@ describe("--cache option", () => { "code", "ENOENT" ); - await runPrettier(dir, [ - "--cache", - "--cache-strategy", - "metadata", - "*.js", - ]); + await runCli(dir, ["--cache", "--cache-strategy", "metadata", "*.js"]); await expect(fs.stat(defaultCacheFile)).resolves.not.toThrowError(); }); it("doesn't format when cache is available", async () => { - const { stdout: firstStdout } = await runPrettier(dir, [ + const { stdout: firstStdout } = await runCli(dir, [ "--cache", "--write", "--cache-strategy", @@ -132,7 +127,7 @@ describe("--cache option", () => { ]) ); - const { stdout: secondStdout } = await runPrettier(dir, [ + const { stdout: secondStdout } = await runCli(dir, [ "--cache", "--write", "--cache-strategy", @@ -155,7 +150,7 @@ describe("--cache option", () => { "metadata", "*.js", ]; - const { stdout: firstStdout } = await runPrettier(dir, cliArguments); + const { stdout: firstStdout } = await runCli(dir, cliArguments); expect(firstStdout.split("\n")).toEqual( expect.arrayContaining([ expect.stringMatching(/^a\.js .+ms$/), @@ -166,7 +161,7 @@ describe("--cache option", () => { // Update `a.js` await fs.writeFile(path.join(dir, "a.js"), "const a = `a`;"); - const { stdout: secondStdout } = await runPrettier(dir, cliArguments); + const { stdout: secondStdout } = await runCli(dir, cliArguments); expect(secondStdout.split("\n")).toEqual( // the cache of `b.js` is only available. expect.arrayContaining([ @@ -184,7 +179,7 @@ describe("--cache option", () => { "metadata", "*.js", ]; - const { stdout: firstStdout } = await runPrettier(dir, cliArguments); + const { stdout: firstStdout } = await runCli(dir, cliArguments); expect(firstStdout.split("\n")).toEqual( expect.arrayContaining([ expect.stringMatching(/^a\.js .+ms$/), @@ -196,7 +191,7 @@ describe("--cache option", () => { const time = new Date(); await fs.utimes(path.join(dir, "a.js"), time, time); - const { stdout: secondStdout } = await runPrettier(dir, cliArguments); + const { stdout: secondStdout } = await runCli(dir, cliArguments); expect(secondStdout.split("\n")).toEqual( // the cache of `b.js` is only available. expect.arrayContaining([ @@ -207,7 +202,7 @@ describe("--cache option", () => { }); it("re-formats when options has been updated.", async () => { - const { stdout: firstStdout } = await runPrettier(dir, [ + const { stdout: firstStdout } = await runCli(dir, [ "--cache", "--write", "--cache-strategy", @@ -221,7 +216,7 @@ describe("--cache option", () => { ]) ); - const { stdout: secondStdout } = await runPrettier(dir, [ + const { stdout: secondStdout } = await runCli(dir, [ "--cache", "--cache-strategy", "metadata", @@ -239,14 +234,9 @@ describe("--cache option", () => { }); it("re-formats after execution without write.", async () => { - await runPrettier(dir, [ - "--cache", - "--cache-strategy", - "metadata", - "*.js", - ]); + await runCli(dir, ["--cache", "--cache-strategy", "metadata", "*.js"]); - const { stdout: secondStdout } = await runPrettier(dir, [ + const { stdout: secondStdout } = await runCli(dir, [ "--write", "--cache", "--cache-strategy", @@ -269,7 +259,7 @@ describe("--cache option", () => { "metadata", "*.js", ]; - await runPrettier(dir, cliArguments); + await runCli(dir, cliArguments); // Update `a.js` to unformatted await fs.writeFile(path.join(dir, "a.js"), "const a = `a`; "); @@ -278,14 +268,9 @@ describe("--cache option", () => { const time = new Date(); await fs.utimes(path.join(dir, "b.js"), time, time); - await runPrettier(dir, [ - "--cache", - "--cache-strategy", - "metadata", - "*.js", - ]); + await runCli(dir, ["--cache", "--cache-strategy", "metadata", "*.js"]); - const { stdout: thirdStdout } = await runPrettier(dir, cliArguments); + const { stdout: thirdStdout } = await runCli(dir, cliArguments); expect(thirdStdout.split("\n")).toEqual( expect.arrayContaining([ expect.stringMatching(/^a\.js .+ms$/), @@ -299,7 +284,7 @@ describe("--cache option", () => { stdout: firstStdout, stderr: firstStderr, status: firstStatus, - } = await runPrettier( + } = await runCli( dir, ["--write", "--cache", "--cache-strategy", "metadata", "*.js"], { @@ -320,7 +305,7 @@ describe("--cache option", () => { ]) ); - const { stdout: secondStdout } = await runPrettier(dir, [ + const { stdout: secondStdout } = await runCli(dir, [ "--list-different", "--cache", "--cache-strategy", @@ -331,7 +316,7 @@ describe("--cache option", () => { }); it("removes cache file when run Prettier without `--cache` option", async () => { - await runPrettier(dir, [ + await runCli(dir, [ "--cache", "--write", "--cache-strategy", @@ -339,7 +324,7 @@ describe("--cache option", () => { "*.js", ]); await expect(fs.stat(defaultCacheFile)).resolves.not.toThrowError(); - await runPrettier(dir, ["--write", "*.js"]); + await runCli(dir, ["--write", "*.js"]); await expect(fs.stat(defaultCacheFile)).rejects.toThrowError(); }); }); @@ -350,12 +335,7 @@ describe("--cache option", () => { "code", "ENOENT" ); - await runPrettier(dir, [ - "--cache", - "--cache-strategy", - "content", - "*.js", - ]); + await runCli(dir, ["--cache", "--cache-strategy", "content", "*.js"]); await expect(fs.stat(defaultCacheFile)).resolves.not.toThrowError(); }); @@ -367,7 +347,7 @@ describe("--cache option", () => { "--write", "*.js", ]; - const { stdout: firstStdout } = await runPrettier(dir, cliArguments); + const { stdout: firstStdout } = await runCli(dir, cliArguments); expect(firstStdout.split("\n")).toEqual( expect.arrayContaining([ expect.stringMatching(/^a\.js .+ms$/), @@ -375,7 +355,7 @@ describe("--cache option", () => { ]) ); - const { stdout: secondStdout } = await runPrettier(dir, cliArguments); + const { stdout: secondStdout } = await runCli(dir, cliArguments); expect(secondStdout.split("\n")).toEqual( expect.arrayContaining([ expect.stringMatching(/^a\.js .+ms \(cached\)$/), @@ -392,7 +372,7 @@ describe("--cache option", () => { "--write", "*.js", ]; - const { stdout: firstStdout } = await runPrettier(dir, cliArguments); + const { stdout: firstStdout } = await runCli(dir, cliArguments); expect(firstStdout.split("\n")).toEqual( expect.arrayContaining([ expect.stringMatching(/^a\.js .+ms$/), @@ -403,7 +383,7 @@ describe("--cache option", () => { // Update `a.js` await fs.writeFile(path.join(dir, "a.js"), "const a = `a`;"); - const { stdout: secondStdout } = await runPrettier(dir, cliArguments); + const { stdout: secondStdout } = await runCli(dir, cliArguments); expect(secondStdout.split("\n")).toEqual( // the cache of `b.js` is only available. expect.arrayContaining([ @@ -421,7 +401,7 @@ describe("--cache option", () => { "--write", "*.js", ]; - const { stdout: firstStdout } = await runPrettier(dir, cliArguments); + const { stdout: firstStdout } = await runCli(dir, cliArguments); expect(firstStdout.split("\n")).toEqual( expect.arrayContaining([ expect.stringMatching(/^a\.js .+ms$/), @@ -433,7 +413,7 @@ describe("--cache option", () => { const time = new Date(); await fs.utimes(path.join(dir, "a.js"), time, time); - const { stdout: secondStdout } = await runPrettier(dir, cliArguments); + const { stdout: secondStdout } = await runCli(dir, cliArguments); expect(secondStdout.split("\n")).toEqual( expect.arrayContaining([ expect.stringMatching(/^a\.js .+ms \(cached\)$/), @@ -443,7 +423,7 @@ describe("--cache option", () => { }); it("re-formats when options has been updated.", async () => { - const { stdout: firstStdout } = await runPrettier(dir, [ + const { stdout: firstStdout } = await runCli(dir, [ "--cache", "--cache-strategy", "content", @@ -457,7 +437,7 @@ describe("--cache option", () => { ]) ); - const { stdout: secondStdout } = await runPrettier(dir, [ + const { stdout: secondStdout } = await runCli(dir, [ "--cache", "--write", "--cache-strategy", @@ -475,14 +455,9 @@ describe("--cache option", () => { }); it("re-formats after execution without write.", async () => { - await runPrettier(dir, [ - "--cache", - "--cache-strategy", - "content", - "*.js", - ]); + await runCli(dir, ["--cache", "--cache-strategy", "content", "*.js"]); - const { stdout: secondStdout } = await runPrettier(dir, [ + const { stdout: secondStdout } = await runCli(dir, [ "--write", "--cache", "--cache-strategy", @@ -505,7 +480,7 @@ describe("--cache option", () => { "content", "*.js", ]; - await runPrettier(dir, cliArguments); + await runCli(dir, cliArguments); // Update `a.js` to unformatted await fs.writeFile(path.join(dir, "a.js"), "const a = `a`; "); @@ -514,14 +489,9 @@ describe("--cache option", () => { const time = new Date(); await fs.utimes(path.join(dir, "b.js"), time, time); - await runPrettier(dir, [ - "--cache", - "--cache-strategy", - "content", - "*.js", - ]); + await runCli(dir, ["--cache", "--cache-strategy", "content", "*.js"]); - const { stdout: thirdStdout } = await runPrettier(dir, cliArguments); + const { stdout: thirdStdout } = await runCli(dir, cliArguments); expect(thirdStdout.split("\n")).toEqual( expect.arrayContaining([ expect.stringMatching(/^a\.js .+ms$/), @@ -535,7 +505,7 @@ describe("--cache option", () => { stdout: firstStdout, stderr: firstStderr, status: firstStatus, - } = await runPrettier( + } = await runCli( dir, ["--write", "--cache", "--cache-strategy", "content", "*.js"], { @@ -556,7 +526,7 @@ describe("--cache option", () => { ]) ); - const { stdout: secondStdout } = await runPrettier(dir, [ + const { stdout: secondStdout } = await runCli(dir, [ "--list-different", "--cache", "--cache-strategy", @@ -567,9 +537,9 @@ describe("--cache option", () => { }); it("removes cache file when run Prettier without `--cache` option", async () => { - await runPrettier(dir, ["--cache", "--write", "*.js"]); + await runCli(dir, ["--cache", "--write", "*.js"]); await expect(fs.stat(defaultCacheFile)).resolves.not.toThrowError(); - await runPrettier(dir, ["--write", "*.js"]); + await runCli(dir, ["--write", "*.js"]); await expect(fs.stat(defaultCacheFile)).rejects.toThrowError(); }); }); @@ -580,7 +550,7 @@ describe("--cache option", () => { "code", "ENOENT" ); - await runPrettier(dir, [ + await runCli(dir, [ "--cache", "--cache-location", nonDefaultCacheFileName, @@ -593,7 +563,7 @@ describe("--cache option", () => { }); it("throws error for invalid JSON file", async () => { - const { stderr } = await runPrettier(dir, [ + const { stderr } = await runCli(dir, [ "--cache", "--cache-location", "a.js", @@ -610,7 +580,7 @@ describe("--cache option", () => { "code", "ENOENT" ); - await runPrettier(dir, [ + await runCli(dir, [ "--cache", "--cache-location", nonDefaultCacheFileName, @@ -629,7 +599,7 @@ describe("--cache option", () => { nonDefaultCacheFileName, "*.js", ]; - const { stdout: firstStdout } = await runPrettier(dir, cliArguments); + const { stdout: firstStdout } = await runCli(dir, cliArguments); expect(firstStdout.split("\n")).toEqual( expect.arrayContaining([ expect.stringMatching(/^a\.js .+ms$/), @@ -637,7 +607,7 @@ describe("--cache option", () => { ]) ); - const { stdout: secondStdout } = await runPrettier(dir, cliArguments); + const { stdout: secondStdout } = await runCli(dir, cliArguments); expect(secondStdout.split("\n")).toEqual( expect.arrayContaining([ expect.stringMatching(/^a\.js .+ms \(cached\)$/), diff --git a/tests/integration/__tests__/check.js b/tests/integration/__tests__/check.js index bbca422e6..62a3b110f 100644 --- a/tests/integration/__tests__/check.js +++ b/tests/integration/__tests__/check.js @@ -1,5 +1,5 @@ describe("checks stdin with --check", () => { - runPrettier("cli/with-shebang", ["--check", "--parser", "babel"], { + runCli("cli/with-shebang", ["--check", "--parser", "babel"], { input: "0", }).test({ stdout: "(stdin)", @@ -9,7 +9,7 @@ describe("checks stdin with --check", () => { }); describe("checks stdin with -c (alias for --check)", () => { - runPrettier("cli/with-shebang", ["-c", "--parser", "babel"], { + runCli("cli/with-shebang", ["-c", "--parser", "babel"], { input: "0", }).test({ stdout: "(stdin)", @@ -19,7 +19,7 @@ describe("checks stdin with -c (alias for --check)", () => { }); describe("--checks works in CI just as in a non-TTY mode", () => { - const result0 = runPrettier( + const result0 = runCli( "cli/write", ["--check", "formatted.js", "unformatted.js"], { @@ -30,7 +30,7 @@ describe("--checks works in CI just as in a non-TTY mode", () => { status: 1, }); - const result1 = runPrettier( + const result1 = runCli( "cli/write", ["--check", "formatted.js", "unformatted.js"], { @@ -46,7 +46,7 @@ describe("--checks works in CI just as in a non-TTY mode", () => { }); describe("--checks should print the number of files that need formatting", () => { - runPrettier("cli/write", ["--check", "unformatted.js", "unformatted2.js"], { + runCli("cli/write", ["--check", "unformatted.js", "unformatted2.js"], { input: "0", }).test({ status: 1, diff --git a/tests/integration/__tests__/config-invalid.js b/tests/integration/__tests__/config-invalid.js index a921afc97..e67cc95a2 100644 --- a/tests/integration/__tests__/config-invalid.js +++ b/tests/integration/__tests__/config-invalid.js @@ -4,7 +4,7 @@ import jestPathSerializer from "../path-serializer.js"; expect.addSnapshotSerializer(jestPathSerializer); describe("throw error for unsupported extension", () => { - runPrettier("cli/config/invalid", [ + runCli("cli/config/invalid", [ "--config", "file/.prettierrc.unsupported", ]).test({ @@ -13,17 +13,14 @@ describe("throw error for unsupported extension", () => { }); describe("throw error with invalid config format", () => { - runPrettier("cli/config/invalid", ["--config", "file/.prettierrc"]).test({ + runCli("cli/config/invalid", ["--config", "file/.prettierrc"]).test({ status: "non-zero", stderr: expect.stringMatching(/Cannot find package '--invalid--'/), }); }); describe("throw error with invalid config format", () => { - runPrettier("cli/config/invalid", [ - "--config", - "type-error/.prettierrc", - ]).test({ + runCli("cli/config/invalid", ["--config", "type-error/.prettierrc"]).test({ status: "non-zero", stderr: expect.stringContaining( "Config is only allowed to be an object, but received number in" @@ -32,7 +29,7 @@ describe("throw error with invalid config format", () => { }); describe("throw error with invalid config target (directory)", () => { - runPrettier("cli/config/invalid", [ + runCli("cli/config/invalid", [ "--config", "folder/.prettierrc", // this is a directory ]).test({ @@ -41,19 +38,19 @@ describe("throw error with invalid config target (directory)", () => { }); describe("throw error with invalid config option (int)", () => { - runPrettier("cli/config/invalid", ["--config", "option/int"]).test({ + runCli("cli/config/invalid", ["--config", "option/int"]).test({ status: "non-zero", }); }); describe("throw error with invalid config option (trailingComma)", () => { - runPrettier("cli/config/invalid", ["--config", "option/trailingComma"]).test({ + runCli("cli/config/invalid", ["--config", "option/trailingComma"]).test({ status: "non-zero", }); }); describe("throw error with invalid config precedence option (configPrecedence)", () => { - runPrettier("cli/config/invalid", [ + runCli("cli/config/invalid", [ "--config-precedence", "option/configPrecedence", ]).test({ @@ -62,9 +59,7 @@ describe("throw error with invalid config precedence option (configPrecedence)", }); describe("resolves external configuration from package.json", () => { - runPrettier("cli/config-external-config-syntax-error", [ - "syntax-error.js", - ]).test({ + runCli("cli/config-external-config-syntax-error", ["syntax-error.js"]).test({ status: 2, }); }); @@ -72,7 +67,7 @@ describe("resolves external configuration from package.json", () => { // Tests below require --parser to prevent an error (no parser/filepath specified) describe("show warning with unknown option", () => { - runPrettier("cli/config/invalid", [ + runCli("cli/config/invalid", [ "--config", "option/unknown", "--parser", @@ -83,7 +78,7 @@ describe("show warning with unknown option", () => { }); describe("show warning with kebab-case option key", () => { - runPrettier("cli/config/invalid", [ + runCli("cli/config/invalid", [ "--config", "option/kebab-case", "--parser", @@ -95,7 +90,7 @@ describe("show warning with kebab-case option key", () => { // #8815, please make sure this error contains code frame describe("Invalid json file", () => { - runPrettier("cli/config/invalid", [ + runCli("cli/config/invalid", [ "--config", "broken-json/.prettierrc.json", "--parser", @@ -118,7 +113,7 @@ describe("Invalid json file", () => { }); describe("Invalid toml file", () => { - runPrettier("cli/config/invalid", [ + runCli("cli/config/invalid", [ "--config", "broken-toml/.prettierrc.toml", "--parser", diff --git a/tests/integration/__tests__/config-resolution.js b/tests/integration/__tests__/config-resolution.js index 291a9cd77..3ff37dc7c 100644 --- a/tests/integration/__tests__/config-resolution.js +++ b/tests/integration/__tests__/config-resolution.js @@ -18,13 +18,13 @@ test("resolves configuration from external files and overrides by extname", asyn }); describe("accepts configuration from --config", () => { - runPrettier("cli/config/", ["--config", ".prettierrc", "./js/file.js"]).test({ + runCli("cli/config/", ["--config", ".prettierrc", "./js/file.js"]).test({ status: 0, }); }); describe("resolves external configuration from package.json (cjs package)", () => { - runPrettier("cli/config/external-config/cjs-package", ["index.js"]).test({ + runCli("cli/config/external-config/cjs-package", ["index.js"]).test({ status: 0, stderr: "", write: [], @@ -32,7 +32,7 @@ describe("resolves external configuration from package.json (cjs package)", () = }); describe("resolves external configuration from package.json (esm package)", () => { - runPrettier("cli/config/external-config/esm-package", ["index.js"]).test({ + runCli("cli/config/external-config/esm-package", ["index.js"]).test({ status: 0, stderr: "", write: [], @@ -40,7 +40,7 @@ describe("resolves external configuration from package.json (esm package)", () = }); describe("resolves external configuration from package.json (esm file)", () => { - runPrettier("cli/config/external-config/esm-package", ["index.js"]).test({ + runCli("cli/config/external-config/esm-package", ["index.js"]).test({ status: 0, stderr: "", write: [], @@ -48,31 +48,31 @@ describe("resolves external configuration from package.json (esm file)", () => { }); describe("resolves configuration file with --find-config-path file", () => { - runPrettier("cli/config/", ["--find-config-path", "no-config/file.js"]).test({ + runCli("cli/config/", ["--find-config-path", "no-config/file.js"]).test({ status: 0, }); }); describe("resolves json configuration file with --find-config-path file", () => { - runPrettier("cli/config/", ["--find-config-path", "rc-json/file.js"]).test({ + runCli("cli/config/", ["--find-config-path", "rc-json/file.js"]).test({ status: 0, }); }); describe("resolves yaml configuration file with --find-config-path file", () => { - runPrettier("cli/config/", ["--find-config-path", "rc-yaml/file.js"]).test({ + runCli("cli/config/", ["--find-config-path", "rc-yaml/file.js"]).test({ status: 0, }); }); describe("resolves toml configuration file with --find-config-path file", () => { - runPrettier("cli/config/", ["--find-config-path", "rc-toml/file.js"]).test({ + runCli("cli/config/", ["--find-config-path", "rc-toml/file.js"]).test({ status: 0, }); }); describe("prints error message when no file found with --find-config-path", () => { - runPrettier("cli/config/", [ + runCli("cli/config/", [ "--end-of-line", "lf", "--find-config-path", diff --git a/tests/integration/__tests__/cursor-offset.js b/tests/integration/__tests__/cursor-offset.js index bd605d6f0..384014141 100644 --- a/tests/integration/__tests__/cursor-offset.js +++ b/tests/integration/__tests__/cursor-offset.js @@ -1,5 +1,5 @@ describe("write cursorOffset to stderr with --cursor-offset ", () => { - runPrettier("cli", ["--cursor-offset", "2", "--parser", "babel"], { + runCli("cli", ["--cursor-offset", "2", "--parser", "babel"], { input: " 1", }).test({ status: 0, @@ -7,7 +7,7 @@ describe("write cursorOffset to stderr with --cursor-offset ", () => { }); describe("cursorOffset should not be affected by full-width character", () => { - runPrettier("cli", ["--cursor-offset", "21", "--parser", "babel"], { + runCli("cli", ["--cursor-offset", "21", "--parser", "babel"], { input: 'const x = ["中文", "中文", "中文", "中文", "中文", "中文", "中文", "中文", "中文", "中文", "中文"];', // ^ offset = 21 ^ width = 80 diff --git a/tests/integration/__tests__/debug-check.js b/tests/integration/__tests__/debug-check.js index c4bc9a4b1..f67783bc0 100644 --- a/tests/integration/__tests__/debug-check.js +++ b/tests/integration/__tests__/debug-check.js @@ -1,5 +1,5 @@ describe("doesn't crash when --debug-check is passed", () => { - runPrettier("cli/with-shebang", ["issue1890.js", "--debug-check"]).test({ + runCli("cli/with-shebang", ["issue1890.js", "--debug-check"]).test({ stdout: "issue1890.js", stderr: "", status: 0, @@ -7,7 +7,7 @@ describe("doesn't crash when --debug-check is passed", () => { }); describe("checks stdin with --debug-check", () => { - runPrettier("cli/with-shebang", ["--debug-check", "--parser", "babel"], { + runCli("cli/with-shebang", ["--debug-check", "--parser", "babel"], { input: "0", }).test({ stdout: "(stdin)", @@ -17,7 +17,7 @@ describe("checks stdin with --debug-check", () => { }); describe("show diff for 2+ error files with --debug-check", () => { - runPrettier("cli/debug-check", [ + runCli("cli/debug-check", [ "--end-of-line", "lf", "*.debug-check", @@ -30,17 +30,15 @@ describe("show diff for 2+ error files with --debug-check", () => { }); describe("should not exit non-zero for already prettified code with --debug-check + --check", () => { - runPrettier("cli/debug-check", [ - "issue-4599.js", - "--debug-check", - "--check", - ]).test({ - status: 0, - }); + runCli("cli/debug-check", ["issue-4599.js", "--debug-check", "--check"]).test( + { + status: 0, + } + ); }); describe("should not exit non-zero for already prettified code with --debug-check + --list-different", () => { - runPrettier("cli/debug-check", [ + runCli("cli/debug-check", [ "issue-4599.js", "--debug-check", "--list-different", diff --git a/tests/integration/__tests__/debug-print-ast.js b/tests/integration/__tests__/debug-print-ast.js index 84a63146f..9bea76f64 100644 --- a/tests/integration/__tests__/debug-print-ast.js +++ b/tests/integration/__tests__/debug-print-ast.js @@ -1,5 +1,5 @@ describe("prints information for debugging AST --debug-print-ast", () => { - runPrettier("cli/with-shebang", ["--debug-print-ast", "--parser", "babel"], { + runCli("cli/with-shebang", ["--debug-print-ast", "--parser", "babel"], { input: "const foo = 'foo';", }).test({ stderr: "", diff --git a/tests/integration/__tests__/debug-print-comments.js b/tests/integration/__tests__/debug-print-comments.js index 015063b8a..6f31ca1d5 100644 --- a/tests/integration/__tests__/debug-print-comments.js +++ b/tests/integration/__tests__/debug-print-comments.js @@ -1,9 +1,7 @@ describe("prints information for debugging comment attachment with --debug-print-comments", () => { - runPrettier( - "cli/with-shebang", - ["--debug-print-comments", "--parser", "babel"], - { input: "/* 1 */\nconsole.log(foo /* 2 */); // 3" } - ).test({ + runCli("cli/with-shebang", ["--debug-print-comments", "--parser", "babel"], { + input: "/* 1 */\nconsole.log(foo /* 2 */); // 3", + }).test({ stderr: "", status: 0, }); diff --git a/tests/integration/__tests__/debug-print-doc.js b/tests/integration/__tests__/debug-print-doc.js index 8d5a5be55..359d38312 100644 --- a/tests/integration/__tests__/debug-print-doc.js +++ b/tests/integration/__tests__/debug-print-doc.js @@ -1,5 +1,5 @@ describe("prints doc with --debug-print-doc", () => { - runPrettier("cli/with-shebang", ["--debug-print-doc", "--parser", "babel"], { + runCli("cli/with-shebang", ["--debug-print-doc", "--parser", "babel"], { input: "0", }).test({ stdout: '["0", ";", hardline]', diff --git a/tests/integration/__tests__/doc-trim.js b/tests/integration/__tests__/doc-trim.js index eecc4da84..d3e1ab45f 100644 --- a/tests/integration/__tests__/doc-trim.js +++ b/tests/integration/__tests__/doc-trim.js @@ -7,7 +7,7 @@ const docBuilders = prettier.doc.builders; const { printDocToString } = docPrinter; const { line, trim, group, indent } = docBuilders; -// These tests don't use `runPrettier` because `trim` is not used by any +// These tests don't use `runCli` because `trim` is not used by any // bundled parser (only third-party plugins). describe("trim", () => { diff --git a/tests/integration/__tests__/early-exit.js b/tests/integration/__tests__/early-exit.js index 0dfb2b459..919423e3d 100644 --- a/tests/integration/__tests__/early-exit.js +++ b/tests/integration/__tests__/early-exit.js @@ -1,26 +1,26 @@ import prettier from "../../config/prettier-entry.js"; describe("show version with --version", () => { - runPrettier("cli/with-shebang", ["--version"]).test({ + runCli("cli/with-shebang", ["--version"]).test({ stdout: prettier.version, status: 0, }); }); describe("show usage with --help", () => { - runPrettier("cli", ["--help"]).test({ + runCli("cli", ["--help"]).test({ status: 0, }); }); describe("show detailed usage with --help l (alias)", () => { - runPrettier("cli", ["--help", "l"]).test({ + runCli("cli", ["--help", "l"]).test({ status: 0, }); }); describe("show detailed usage with plugin options (automatic resolution)", () => { - runPrettier("plugins/automatic", [ + runCli("plugins/automatic", [ "--help", "tab-width", "--parser=bar", @@ -31,7 +31,7 @@ describe("show detailed usage with plugin options (automatic resolution)", () => }); describe("show detailed usage with plugin options (manual resolution)", () => { - runPrettier("cli", [ + runCli("cli", [ "--help", "tab-width", "--plugin=../plugins/automatic/node_modules/prettier-plugin-bar/index.js", @@ -42,13 +42,13 @@ describe("show detailed usage with plugin options (manual resolution)", () => { }); describe("throw error with --help not-found", () => { - runPrettier("cli", ["--help", "not-found"]).test({ + runCli("cli", ["--help", "not-found"]).test({ status: 1, }); }); describe("show warning with --help not-found (typo)", () => { - runPrettier("cli", [ + runCli("cli", [ "--help", // cspell:disable-next-line "parserr", @@ -58,31 +58,31 @@ describe("show warning with --help not-found (typo)", () => { }); describe("throw error with --check + --list-different", () => { - runPrettier("cli", ["--check", "--list-different"]).test({ + runCli("cli", ["--check", "--list-different"]).test({ status: 1, }); }); describe("throw error with --write + --debug-check", () => { - runPrettier("cli", ["--write", "--debug-check"]).test({ + runCli("cli", ["--write", "--debug-check"]).test({ status: 1, }); }); describe("throw error with --find-config-path + multiple files", () => { - runPrettier("cli", ["--find-config-path", "abc.js", "def.js"]).test({ + runCli("cli", ["--find-config-path", "abc.js", "def.js"]).test({ status: 1, }); }); describe("throw error with --file-info + multiple files", () => { - runPrettier("cli", ["--file-info", "abc.js", "def.js"]).test({ + runCli("cli", ["--file-info", "abc.js", "def.js"]).test({ status: 1, }); }); describe("throw error and show usage with something unexpected", () => { - runPrettier("cli", [], { isTTY: true }).test({ + runCli("cli", [], { isTTY: true }).test({ status: "non-zero", }); }); diff --git a/tests/integration/__tests__/error-on-unmatched-pattern.js b/tests/integration/__tests__/error-on-unmatched-pattern.js index 1d29b9d36..9c9826217 100644 --- a/tests/integration/__tests__/error-on-unmatched-pattern.js +++ b/tests/integration/__tests__/error-on-unmatched-pattern.js @@ -1,5 +1,5 @@ describe("no error on unmatched pattern", () => { - runPrettier("cli/error-on-unmatched-pattern", [ + runCli("cli/error-on-unmatched-pattern", [ "--no-error-on-unmatched-pattern", "**/*.js", ]).test({ @@ -8,13 +8,13 @@ describe("no error on unmatched pattern", () => { }); describe("error on unmatched pattern", () => { - runPrettier("cli/error-on-unmatched-pattern", ["**/*.toml"]).test({ + runCli("cli/error-on-unmatched-pattern", ["**/*.toml"]).test({ status: 2, }); }); describe("no error on unmatched pattern when 2nd glob has no match", () => { - runPrettier("cli/error-on-unmatched-pattern", [ + runCli("cli/error-on-unmatched-pattern", [ "--no-error-on-unmatched-pattern", "**/*.{json,js,yml}", "**/*.toml", @@ -24,7 +24,7 @@ describe("no error on unmatched pattern when 2nd glob has no match", () => { }); describe("error on unmatched pattern when 2nd glob has no match", () => { - runPrettier("cli/error-on-unmatched-pattern", [ + runCli("cli/error-on-unmatched-pattern", [ "**/*.{json,js,yml}", "**/*.toml", ]).test({ diff --git a/tests/integration/__tests__/file-info.js b/tests/integration/__tests__/file-info.js index e288861b1..f056790f3 100644 --- a/tests/integration/__tests__/file-info.js +++ b/tests/integration/__tests__/file-info.js @@ -7,37 +7,37 @@ import prettier from "../../config/prettier-entry.js"; const { __dirname } = createEsmUtils(import.meta); describe("extracts file-info for a js file", () => { - runPrettier("cli/", ["--file-info", "something.js"]).test({ + runCli("cli/", ["--file-info", "something.js"]).test({ status: 0, }); }); describe("extracts file-info for a markdown file", () => { - runPrettier("cli/", ["--file-info", "README.md"]).test({ + runCli("cli/", ["--file-info", "README.md"]).test({ status: 0, }); }); describe("extracts file-info for a known markdown file with no extension", () => { - runPrettier("cli/", ["--file-info", "README"]).test({ + runCli("cli/", ["--file-info", "README"]).test({ status: 0, }); }); describe("extracts file-info with ignored=true for a file in .prettierignore", () => { - runPrettier("cli/ignore-path/", ["--file-info", "regular-module.js"]).test({ + runCli("cli/ignore-path/", ["--file-info", "regular-module.js"]).test({ status: 0, }); }); describe("file-info should try resolve config", () => { - runPrettier("cli/with-resolve-config/", ["--file-info", "file.js"]).test({ + runCli("cli/with-resolve-config/", ["--file-info", "file.js"]).test({ status: 0, }); }); describe("file-info should not try resolve config with --no-config", () => { - runPrettier("cli/with-resolve-config/", [ + runCli("cli/with-resolve-config/", [ "--file-info", "file.js", "--no-config", @@ -49,7 +49,7 @@ describe("file-info should not try resolve config with --no-config", () => { }); describe("extracts file-info with ignored=true for a file in a hand-picked .prettierignore", () => { - runPrettier("cli/", [ + runCli("cli/", [ "--file-info", "regular-module.js", "--ignore-path=ignore-path/.prettierignore", @@ -59,7 +59,7 @@ describe("extracts file-info with ignored=true for a file in a hand-picked .pret }); describe("non-exists ignore path", () => { - runPrettier("cli/", [ + runCli("cli/", [ "--file-info", "regular-module.js", "--ignore-path=ignore-path/non-exists/.prettierignore", @@ -69,7 +69,7 @@ describe("non-exists ignore path", () => { }); describe("extracts file-info for a file in not_node_modules", () => { - runPrettier("cli/with-node-modules/", [ + runCli("cli/with-node-modules/", [ "--file-info", "not_node_modules/file.js", ]).test({ @@ -78,7 +78,7 @@ describe("extracts file-info for a file in not_node_modules", () => { }); describe("extracts file-info with with ignored=true for a file in node_modules", () => { - runPrettier("cli/with-node-modules/", [ + runCli("cli/with-node-modules/", [ "--file-info", "node_modules/file.js", ]).test({ @@ -87,7 +87,7 @@ describe("extracts file-info with with ignored=true for a file in node_modules", }); describe("extracts file-info with ignored=false for a file in node_modules when --with-node-modules provided", () => { - runPrettier("cli/with-node-modules/", [ + runCli("cli/with-node-modules/", [ "--file-info", "node_modules/file.js", "--with-node-modules", @@ -97,19 +97,19 @@ describe("extracts file-info with ignored=false for a file in node_modules when }); describe("extracts file-info with inferredParser=null for file.foo", () => { - runPrettier("cli/", ["--file-info", "file.foo"]).test({ + runCli("cli/", ["--file-info", "file.foo"]).test({ status: 0, }); }); describe("extracts file-info with inferredParser=foo when plugins are autoloaded", () => { - runPrettier("plugins/automatic/", ["--file-info", "file.foo"]).test({ + runCli("plugins/automatic/", ["--file-info", "file.foo"]).test({ status: 0, }); }); describe("extracts file-info with inferredParser=foo when plugins are loaded with --plugin-search-dir", () => { - runPrettier("cli/", [ + runCli("cli/", [ "--file-info", "file.foo", "--plugin-search-dir", @@ -120,7 +120,7 @@ describe("extracts file-info with inferredParser=foo when plugins are loaded wit }); describe("extracts file-info with inferredParser=foo when a plugin is hand-picked", () => { - runPrettier("cli/", [ + runCli("cli/", [ "--file-info", "file.foo", "--plugin", diff --git a/tests/integration/__tests__/help-options.js b/tests/integration/__tests__/help-options.js index 47f85ed56..30d373c64 100644 --- a/tests/integration/__tests__/help-options.js +++ b/tests/integration/__tests__/help-options.js @@ -10,7 +10,7 @@ for (const option of detailedOptions) { for (const optionName of optionNames) { describe(`show detailed usage with --help ${optionName}`, () => { - runPrettier("cli", ["--help", optionName]).test({ + runCli("cli", ["--help", optionName]).test({ status: 0, }); }); diff --git a/tests/integration/__tests__/ignore-absolute-path.js b/tests/integration/__tests__/ignore-absolute-path.js index 867b2717a..2209aa764 100644 --- a/tests/integration/__tests__/ignore-absolute-path.js +++ b/tests/integration/__tests__/ignore-absolute-path.js @@ -3,7 +3,7 @@ import createEsmUtils from "esm-utils"; const { __dirname } = createEsmUtils(import.meta); describe("support absolute filename", () => { - runPrettier("cli/ignore-absolute-path", [ + runCli("cli/ignore-absolute-path", [ path.resolve(__dirname, "../cli/ignore-absolute-path/ignored/module.js"), path.resolve(__dirname, "../cli/ignore-absolute-path/depth1/ignored/*.js"), path.resolve(__dirname, "../cli/ignore-absolute-path/regular-module.js"), diff --git a/tests/integration/__tests__/ignore-emoji.js b/tests/integration/__tests__/ignore-emoji.js index ab0d18281..ec353ccab 100644 --- a/tests/integration/__tests__/ignore-emoji.js +++ b/tests/integration/__tests__/ignore-emoji.js @@ -1,15 +1,13 @@ describe("ignores file name contains emoji", () => { - runPrettier("cli/ignore-emoji", ["**/*.js", "-l"]).test({ + runCli("cli/ignore-emoji", ["**/*.js", "-l"]).test({ status: 1, }); }); describe("stdin", () => { - runPrettier( - "cli/ignore-emoji", - ["--stdin-filepath", "ignored/我的样式.css"], - { input: ".name { display: none; }" } - ).test({ + runCli("cli/ignore-emoji", ["--stdin-filepath", "ignored/我的样式.css"], { + input: ".name { display: none; }", + }).test({ status: 0, }); }); diff --git a/tests/integration/__tests__/ignore-in-subdirectories.js b/tests/integration/__tests__/ignore-in-subdirectories.js index 3c1fa8323..6ac0425d1 100644 --- a/tests/integration/__tests__/ignore-in-subdirectories.js +++ b/tests/integration/__tests__/ignore-in-subdirectories.js @@ -1,5 +1,5 @@ describe("ignores files when executing in a subdirectory", () => { - runPrettier("cli/ignore-in-subdirectories/web1", [ + runCli("cli/ignore-in-subdirectories/web1", [ "ignore-me/should-ignore.js", "--ignore-path", "../.prettierignore", @@ -8,7 +8,7 @@ describe("ignores files when executing in a subdirectory", () => { status: 0, }); - runPrettier("cli/ignore-in-subdirectories/web1", [ + runCli("cli/ignore-in-subdirectories/web1", [ "ignore-me/subdirectory/should-ignore.js", "--ignore-path", "../.prettierignore", @@ -19,7 +19,7 @@ describe("ignores files when executing in a subdirectory", () => { }); describe("formats files when executing in a subdirectory", () => { - runPrettier("cli/ignore-in-subdirectories/web1", [ + runCli("cli/ignore-in-subdirectories/web1", [ "should-not-ignore.js", "--ignore-path", "../.prettierignore", @@ -28,7 +28,7 @@ describe("formats files when executing in a subdirectory", () => { status: 1, }); - runPrettier("cli/ignore-in-subdirectories/web2", [ + runCli("cli/ignore-in-subdirectories/web2", [ "should-not-ignore.js", "--ignore-path", "../.prettierignore", @@ -39,7 +39,7 @@ describe("formats files when executing in a subdirectory", () => { }); describe("ignore files when executing in a subdirectory and using stdin", () => { - runPrettier( + runCli( "cli/ignore-in-subdirectories/web1", [ "--ignore-path", @@ -57,7 +57,7 @@ describe("ignore files when executing in a subdirectory and using stdin", () => }); describe("formats files when executing in a subdirectory and using stdin", () => { - runPrettier( + runCli( "cli/ignore-in-subdirectories/web1", ["--ignore-path", "../.prettierignore", "--stdin-filepath", "example.js"], { diff --git a/tests/integration/__tests__/ignore-path.js b/tests/integration/__tests__/ignore-path.js index c1cab33a1..abadcc92c 100644 --- a/tests/integration/__tests__/ignore-path.js +++ b/tests/integration/__tests__/ignore-path.js @@ -10,7 +10,7 @@ fs.writeFileSync( ); describe("ignore path", () => { - runPrettier("cli/ignore-path", [ + runCli("cli/ignore-path", [ "**/*.js", "--ignore-path", ".gitignore", @@ -23,7 +23,7 @@ describe("ignore path", () => { }); describe("support .prettierignore", () => { - runPrettier("cli/ignore-path", ["**/*.js", "-l"]).test({ + runCli("cli/ignore-path", ["**/*.js", "-l"]).test({ status: 1, stderr: "", write: [], @@ -31,7 +31,7 @@ describe("support .prettierignore", () => { }); describe("ignore file when using --debug-check", () => { - runPrettier("cli/ignore-path", ["**/*.js", "--debug-check"]).test({ + runCli("cli/ignore-path", ["**/*.js", "--debug-check"]).test({ status: 0, stderr: "", write: [], @@ -39,7 +39,7 @@ describe("ignore file when using --debug-check", () => { }); describe("outputs files as-is if no --write", () => { - runPrettier("cli/ignore-path", ["regular-module.js"], { + runCli("cli/ignore-path", ["regular-module.js"], { ignoreLineEndings: true, }).test({ status: 0, @@ -49,7 +49,7 @@ describe("outputs files as-is if no --write", () => { }); describe("multiple `--ignore-path`", () => { - runPrettier("cli/ignore-path", [ + runCli("cli/ignore-path", [ "**/*.js", "--debug-check", "--ignore-path", diff --git a/tests/integration/__tests__/ignore-relative-path.js b/tests/integration/__tests__/ignore-relative-path.js index 74233df45..e08cc7700 100644 --- a/tests/integration/__tests__/ignore-relative-path.js +++ b/tests/integration/__tests__/ignore-relative-path.js @@ -1,5 +1,5 @@ describe("support relative paths", () => { - runPrettier("cli/ignore-relative-path", [ + runCli("cli/ignore-relative-path", [ "./shouldNotBeIgnored.js", "./level1/level2/level3/shouldNotBeFormat.js", "level1-glob/level2-glob/level3-glob/shouldNotBeFormat.js", diff --git a/tests/integration/__tests__/ignore-unknown.js b/tests/integration/__tests__/ignore-unknown.js index 65d2a192a..1fe9762fd 100644 --- a/tests/integration/__tests__/ignore-unknown.js +++ b/tests/integration/__tests__/ignore-unknown.js @@ -1,5 +1,5 @@ describe("ignore-unknown dir", () => { - runPrettier("cli/ignore-unknown", [ + runCli("cli/ignore-unknown", [ ".", "--ignore-unknown", "--list-different", @@ -11,7 +11,7 @@ describe("ignore-unknown dir", () => { }); describe("ignore-unknown alias", () => { - runPrettier("cli/ignore-unknown", [".", "-u", "--list-different"]).test({ + runCli("cli/ignore-unknown", [".", "-u", "--list-different"]).test({ status: "non-zero", stderr: "", write: [], @@ -19,7 +19,7 @@ describe("ignore-unknown alias", () => { }); describe("ignore-unknown pattern", () => { - runPrettier("cli/ignore-unknown", [ + runCli("cli/ignore-unknown", [ "*", "--ignore-unknown", "--list-different", @@ -31,7 +31,7 @@ describe("ignore-unknown pattern", () => { }); describe("ignore-unknown write", () => { - runPrettier("cli/ignore-unknown", [ + runCli("cli/ignore-unknown", [ ".", "--ignore-unknown", "--write", @@ -43,22 +43,19 @@ describe("ignore-unknown write", () => { }); describe("ignore-unknown check", () => { - runPrettier("cli/ignore-unknown", [".", "--ignore-unknown", "--check"]).test({ + runCli("cli/ignore-unknown", [".", "--ignore-unknown", "--check"]).test({ status: 1, }); }); describe("None exist file", () => { - runPrettier("cli/ignore-unknown", [ - "non-exist-file", - "--ignore-unknown", - ]).test({ + runCli("cli/ignore-unknown", ["non-exist-file", "--ignore-unknown"]).test({ status: 2, }); }); describe("Not matching pattern", () => { - runPrettier("cli/ignore-unknown", [ + runCli("cli/ignore-unknown", [ "*.non-exist-pattern", "--ignore-unknown", ]).test({ @@ -67,7 +64,7 @@ describe("Not matching pattern", () => { }); describe("Ignored file", () => { - runPrettier("cli/ignore-unknown", ["ignored.js", "--ignore-unknown"]).test({ + runCli("cli/ignore-unknown", ["ignored.js", "--ignore-unknown"]).test({ status: 0, }); }); diff --git a/tests/integration/__tests__/ignore-vcs-files.js b/tests/integration/__tests__/ignore-vcs-files.js index e0f5e2692..c74f17633 100644 --- a/tests/integration/__tests__/ignore-vcs-files.js +++ b/tests/integration/__tests__/ignore-vcs-files.js @@ -1,5 +1,5 @@ describe("ignores files in version control systems", () => { - runPrettier("cli/ignore-vcs-files", [ + runCli("cli/ignore-vcs-files", [ ".svn/file.js", ".hg/file.js", "file.js", diff --git a/tests/integration/__tests__/infer-parser.js b/tests/integration/__tests__/infer-parser.js index d728b61ab..7a53e2c11 100644 --- a/tests/integration/__tests__/infer-parser.js +++ b/tests/integration/__tests__/infer-parser.js @@ -5,7 +5,7 @@ expect.addSnapshotSerializer(jestPathSerializer); describe("stdin no path and no parser", () => { describe("logs error and exits with 2", () => { - runPrettier("cli/infer-parser/", [], { input: "foo" }).test({ + runCli("cli/infer-parser/", [], { input: "foo" }).test({ status: 2, stdout: "", write: [], @@ -13,7 +13,7 @@ describe("stdin no path and no parser", () => { }); describe("--check logs error but exits with 0", () => { - runPrettier("cli/infer-parser/", ["--check"], { + runCli("cli/infer-parser/", ["--check"], { input: "foo", }).test({ status: 0, @@ -23,7 +23,7 @@ describe("stdin no path and no parser", () => { }); describe("--list-different logs error but exits with 0", () => { - runPrettier("cli/infer-parser/", ["--list-different"], { + runCli("cli/infer-parser/", ["--list-different"], { input: "foo", }).test({ status: 0, @@ -35,7 +35,7 @@ describe("stdin no path and no parser", () => { describe("stdin with unknown path and no parser", () => { describe("logs error and exits with 2", () => { - runPrettier("cli/infer-parser/", ["--stdin-filepath", "foo"], { + runCli("cli/infer-parser/", ["--stdin-filepath", "foo"], { input: "foo", }).test({ status: 2, @@ -45,7 +45,7 @@ describe("stdin with unknown path and no parser", () => { }); describe("--check logs error but exits with 0", () => { - runPrettier("cli/infer-parser/", ["--check", "--stdin-filepath", "foo"], { + runCli("cli/infer-parser/", ["--check", "--stdin-filepath", "foo"], { input: "foo", }).test({ status: 0, @@ -55,7 +55,7 @@ describe("stdin with unknown path and no parser", () => { }); describe("--list-different logs error but exits with 0", () => { - runPrettier( + runCli( "cli/infer-parser/", ["--list-different", "--stdin-filepath", "foo"], { input: "foo" } @@ -69,7 +69,7 @@ describe("stdin with unknown path and no parser", () => { describe("unknown path and no parser", () => { describe("specific file", () => { - runPrettier("cli/infer-parser/", ["--end-of-line", "lf", "FOO"]).test({ + runCli("cli/infer-parser/", ["--end-of-line", "lf", "FOO"]).test({ status: 2, stdout: "", write: [], @@ -77,7 +77,7 @@ describe("unknown path and no parser", () => { }); describe("multiple files", () => { - runPrettier("cli/infer-parser/", ["--end-of-line", "lf", "*"]).test({ + runCli("cli/infer-parser/", ["--end-of-line", "lf", "*"]).test({ status: 2, write: [], }); @@ -86,14 +86,14 @@ describe("unknown path and no parser", () => { describe("--check with unknown path and no parser", () => { describe("specific file", () => { - runPrettier("cli/infer-parser/", ["--check", "FOO"]).test({ + runCli("cli/infer-parser/", ["--check", "FOO"]).test({ status: 0, write: [], }); }); describe("multiple files", () => { - runPrettier("cli/infer-parser/", ["--check", "*"]).test({ + runCli("cli/infer-parser/", ["--check", "*"]).test({ status: 1, write: [], }); @@ -102,7 +102,7 @@ describe("--check with unknown path and no parser", () => { describe("--list-different with unknown path and no parser", () => { describe("specific file", () => { - runPrettier("cli/infer-parser/", ["--list-different", "FOO"]).test({ + runCli("cli/infer-parser/", ["--list-different", "FOO"]).test({ status: 0, stdout: "", write: [], @@ -110,7 +110,7 @@ describe("--list-different with unknown path and no parser", () => { }); describe("multiple files", () => { - runPrettier("cli/infer-parser/", ["--list-different", "*"]).test({ + runCli("cli/infer-parser/", ["--list-different", "*"]).test({ status: 1, stdout: "foo.js", write: [], @@ -120,7 +120,7 @@ describe("--list-different with unknown path and no parser", () => { describe("--write with unknown path and no parser", () => { describe("specific file", () => { - runPrettier("cli/infer-parser/", ["--write", "FOO"]).test({ + runCli("cli/infer-parser/", ["--write", "FOO"]).test({ status: 2, stdout: "", write: [], @@ -128,7 +128,7 @@ describe("--write with unknown path and no parser", () => { }); describe("multiple files", () => { - runPrettier("cli/infer-parser/", ["--write", "*"]).test({ + runCli("cli/infer-parser/", ["--write", "*"]).test({ status: 2, }); }); @@ -136,14 +136,14 @@ describe("--write with unknown path and no parser", () => { describe("--write and --check with unknown path and no parser", () => { describe("specific file", () => { - runPrettier("cli/infer-parser/", ["--check", "--write", "FOO"]).test({ + runCli("cli/infer-parser/", ["--check", "--write", "FOO"]).test({ status: 0, write: [], }); }); describe("multiple files", () => { - runPrettier("cli/infer-parser/", ["--check", "--write", "*"]).test({ + runCli("cli/infer-parser/", ["--check", "--write", "*"]).test({ status: 0, }); }); @@ -151,11 +151,7 @@ describe("--write and --check with unknown path and no parser", () => { describe("--write and --list-different with unknown path and no parser", () => { describe("specific file", () => { - runPrettier("cli/infer-parser/", [ - "--list-different", - "--write", - "FOO", - ]).test({ + runCli("cli/infer-parser/", ["--list-different", "--write", "FOO"]).test({ status: 0, stdout: "", write: [], @@ -163,9 +159,9 @@ describe("--write and --list-different with unknown path and no parser", () => { }); describe("multiple files", () => { - runPrettier("cli/infer-parser/", ["--list-different", "--write", "*"]).test( - { status: 0 } - ); + runCli("cli/infer-parser/", ["--list-different", "--write", "*"]).test({ + status: 0, + }); }); }); @@ -202,7 +198,7 @@ describe("API with no path and no parser", () => { }); describe("Known/Unknown", () => { - runPrettier("cli/infer-parser/known-unknown", [ + runCli("cli/infer-parser/known-unknown", [ "--end-of-line", "lf", "--list-different", @@ -215,10 +211,7 @@ describe("Known/Unknown", () => { }); describe("Interpreters", () => { - runPrettier("cli/infer-parser/interpreters", [ - "--file-info", - "zx-script", - ]).test({ + runCli("cli/infer-parser/interpreters", ["--file-info", "zx-script"]).test({ status: 0, stderr: "", write: [], diff --git a/tests/integration/__tests__/invalid-ignore.js b/tests/integration/__tests__/invalid-ignore.js index 039fc7c2c..c70bf8829 100644 --- a/tests/integration/__tests__/invalid-ignore.js +++ b/tests/integration/__tests__/invalid-ignore.js @@ -5,7 +5,7 @@ import prettier from "../../config/prettier-entry.js"; const { __dirname } = createEsmUtils(import.meta); describe("throw error with invalid ignore", () => { - runPrettier("cli/invalid-ignore", ["something.js"]).test({ + runCli("cli/invalid-ignore", ["something.js"]).test({ status: "non-zero", }); diff --git a/tests/integration/__tests__/list-different.js b/tests/integration/__tests__/list-different.js index 34d9ad896..6117dc962 100644 --- a/tests/integration/__tests__/list-different.js +++ b/tests/integration/__tests__/list-different.js @@ -1,5 +1,5 @@ describe("checks stdin with --list-different", () => { - runPrettier("cli/with-shebang", ["--list-different", "--parser", "babel"], { + runCli("cli/with-shebang", ["--list-different", "--parser", "babel"], { input: "0", }).test({ stdout: "(stdin)", @@ -9,7 +9,7 @@ describe("checks stdin with --list-different", () => { }); describe("checks stdin with -l (alias for --list-different)", () => { - runPrettier("cli/with-shebang", ["-l", "--parser", "babel"], { + runCli("cli/with-shebang", ["-l", "--parser", "babel"], { input: "0", }).test({ stdout: "(stdin)", @@ -19,7 +19,7 @@ describe("checks stdin with -l (alias for --list-different)", () => { }); describe("--list-different works in CI just as in a non-TTY mode", () => { - const result0 = runPrettier( + const result0 = runCli( "cli/write", ["--list-different", "formatted.js", "unformatted.js"], { @@ -30,7 +30,7 @@ describe("--list-different works in CI just as in a non-TTY mode", () => { status: 1, }); - const result1 = runPrettier( + const result1 = runCli( "cli/write", ["--list-different", "formatted.js", "unformatted.js"], { diff --git a/tests/integration/__tests__/log-level.js b/tests/integration/__tests__/log-level.js index 9b7f32084..90bc54d48 100644 --- a/tests/integration/__tests__/log-level.js +++ b/tests/integration/__tests__/log-level.js @@ -1,31 +1,29 @@ test("do not show logs with --log-level silent", async () => { - await runPrettierWithLogLevel("silent", null); + await runCliWithLogLevel("silent", null); }); test("do not show warnings with --log-level error", async () => { - await runPrettierWithLogLevel("error", ["[error]"]); + await runCliWithLogLevel("error", ["[error]"]); }); test("show errors and warnings with --log-level warn", async () => { - await runPrettierWithLogLevel("warn", ["[error]", "[warn]"]); + await runCliWithLogLevel("warn", ["[error]", "[warn]"]); }); test("show all logs with --log-level debug", async () => { - await runPrettierWithLogLevel("debug", ["[error]", "[warn]", "[debug]"]); + await runCliWithLogLevel("debug", ["[error]", "[warn]", "[debug]"]); }); describe("--write with --log-level=silent doesn't log filenames", () => { - runPrettier("cli/write", [ - "--write", - "unformatted.js", - "--log-level=silent", - ]).test({ - status: 0, - }); + runCli("cli/write", ["--write", "unformatted.js", "--log-level=silent"]).test( + { + status: 0, + } + ); }); describe("Should use default level logger to log `--log-level` error", () => { - runPrettier("cli/log-level", ["--log-level", "a-unknown-log-level"]).test({ + runCli("cli/log-level", ["--log-level", "a-unknown-log-level"]).test({ status: "non-zero", write: [], stdout: "", @@ -99,7 +97,7 @@ describe("log-level should not effect information print", () => { assertOptions: { stdout: "foo;" }, }, ]) { - runPrettier("cli/log-level", ["--log-level", "silent", ...argv], { + runCli("cli/log-level", ["--log-level", "silent", ...argv], { ...runOptions, title: argv.join(" "), }).test({ @@ -111,8 +109,8 @@ describe("log-level should not effect information print", () => { } }); -async function runPrettierWithLogLevel(logLevel, patterns) { - const result = await runPrettier("cli/log-level", [ +async function runCliWithLogLevel(logLevel, patterns) { + const result = await runCli("cli/log-level", [ "--log-level", logLevel, "--unknown-option", diff --git a/tests/integration/__tests__/patterns-dirs.js b/tests/integration/__tests__/patterns-dirs.js index 5358cecee..5f74bc591 100644 --- a/tests/integration/__tests__/patterns-dirs.js +++ b/tests/integration/__tests__/patterns-dirs.js @@ -97,7 +97,7 @@ const uppercaseRocksPlugin = path.join( "tests/config/prettier-plugins/prettier-plugin-uppercase-rocks/index.js" ); describe("plugins `.`", () => { - runPrettier("cli/dirs/plugins", [ + runCli("cli/dirs/plugins", [ ".", "-l", "--plugin", @@ -109,7 +109,7 @@ describe("plugins `.`", () => { }); }); describe("plugins `*`", () => { - runPrettier("cli/dirs/plugins", [ + runCli("cli/dirs/plugins", [ "*", "-l", "--plugin", @@ -166,7 +166,7 @@ function testPatterns( .join(" "); describe(testName, () => { - runPrettier(cwd, [...cliArgs, "-l"]).test({ + runCli(cwd, [...cliArgs, "-l"]).test({ write: [], ...(!("status" in expected) && { stderr: "", status: 1 }), ...expected, diff --git a/tests/integration/__tests__/patterns-glob.js b/tests/integration/__tests__/patterns-glob.js index f097a23f4..574d1b693 100644 --- a/tests/integration/__tests__/patterns-glob.js +++ b/tests/integration/__tests__/patterns-glob.js @@ -6,13 +6,13 @@ fixtures-1/ */ describe("fixtures-1: Should match all files", () => { - runPrettier("cli/patterns-glob/fixtures-1", ["*.js", "!file.js", "-l"]).test({ + runCli("cli/patterns-glob/fixtures-1", ["*.js", "!file.js", "-l"]).test({ status: 1, }); }); describe("fixtures-1: Should match files except `a.js`", () => { - runPrettier("cli/patterns-glob/fixtures-1", ["*.js", "!a.js", "-l"]).test({ + runCli("cli/patterns-glob/fixtures-1", ["*.js", "!a.js", "-l"]).test({ status: 1, }); }); @@ -27,19 +27,19 @@ fixtures-2/ */ describe("fixtures-2: Should match all js files and all supported files in the '!dir.js' directory", () => { - runPrettier("cli/patterns-glob/fixtures-2", ["*.js", "!dir.js", "-l"]).test({ + runCli("cli/patterns-glob/fixtures-2", ["*.js", "!dir.js", "-l"]).test({ status: 1, }); }); describe("fixtures-2: Should match `a.js` and `!b.js`", () => { - runPrettier("cli/patterns-glob/fixtures-2", ["*.js", "!b.js", "-l"]).test({ + runCli("cli/patterns-glob/fixtures-2", ["*.js", "!b.js", "-l"]).test({ status: 1, }); }); describe("fixtures-2: Should only match `!b.js`", () => { - runPrettier("cli/patterns-glob/fixtures-2", ["*.js", "!a.js", "-l"]).test({ + runCli("cli/patterns-glob/fixtures-2", ["*.js", "!a.js", "-l"]).test({ status: 1, }); }); @@ -56,7 +56,7 @@ fixtures-3/ */ describe("fixtures-3: Should match `outside.js`, `dir/inside.js` and `dir/node_modules/in-node_modules.js`", () => { - runPrettier("cli/patterns-glob/fixtures-3", [ + runCli("cli/patterns-glob/fixtures-3", [ "**/*.js", "-l", "--with-node-modules", @@ -66,14 +66,14 @@ describe("fixtures-3: Should match `outside.js`, `dir/inside.js` and `dir/node_m }); describe("fixtures-3: Should only match `outside.js` and `dir/inside.js`", () => { - runPrettier("cli/patterns-glob/fixtures-3", ["**/*.js", "-l"]).test({ + runCli("cli/patterns-glob/fixtures-3", ["**/*.js", "-l"]).test({ status: 1, }); }); describe("fixtures-3: Should exclude `.svn`", () => { describe("(existing)", () => { - runPrettier("cli/patterns-glob/fixtures-3", [ + runCli("cli/patterns-glob/fixtures-3", [ "*.js", "dir/.svn/in-svn.js", "-l", @@ -83,7 +83,7 @@ describe("fixtures-3: Should exclude `.svn`", () => { }); describe("(nonexisting)", () => { - runPrettier("cli/patterns-glob/fixtures-3", [ + runCli("cli/patterns-glob/fixtures-3", [ "*.js", ".svn/in-svn.js", "-l", @@ -105,13 +105,13 @@ fixtures-4/ */ describe("fixtures-4: Should match `level-1.js`", () => { - runPrettier("cli/patterns-glob/fixtures-4", ["./0/./level-1.js", "-l"]).test({ + runCli("cli/patterns-glob/fixtures-4", ["./0/./level-1.js", "-l"]).test({ status: 1, }); }); describe("fixtures-4: Should match `level-1.js` #2", () => { - runPrettier("cli/patterns-glob/fixtures-4", [ + runCli("cli/patterns-glob/fixtures-4", [ "./0/1/2/../../level-1.js", "-l", ]).test({ @@ -120,7 +120,7 @@ describe("fixtures-4: Should match `level-1.js` #2", () => { }); describe("fixtures-4: Should match `level-1.js` #3", () => { - runPrettier("cli/patterns-glob/fixtures-4", [ + runCli("cli/patterns-glob/fixtures-4", [ "./0/non-exists-dir/2/../../level-1.js", "-l", ]).test({ @@ -129,7 +129,7 @@ describe("fixtures-4: Should match `level-1.js` #3", () => { }); describe("should not ignore file paths contains object prototype keys", () => { - runPrettier("cli/patterns-glob/fixtures-5", [ + runCli("cli/patterns-glob/fixtures-5", [ "./constructor/should-be-formatted.js", "-l", ]).test({ status: 1 }); diff --git a/tests/integration/__tests__/patterns.js b/tests/integration/__tests__/patterns.js index be4564501..4d1b23ed0 100644 --- a/tests/integration/__tests__/patterns.js +++ b/tests/integration/__tests__/patterns.js @@ -1,5 +1,5 @@ describe("multiple patterns", () => { - runPrettier("cli/patterns", [ + runCli("cli/patterns", [ "directory/**/*.js", "other-directory/**/*.js", "-l", @@ -9,39 +9,31 @@ describe("multiple patterns", () => { }); describe("multiple patterns with non exists pattern", () => { - runPrettier("cli/patterns", [ - "directory/**/*.js", - "non-existent.js", - "-l", - ]).test({ + runCli("cli/patterns", ["directory/**/*.js", "non-existent.js", "-l"]).test({ status: 2, }); }); describe("multiple patterns with ignore nested directories pattern", () => { - runPrettier("cli/patterns", [ - "**/*.js", - "!**/nested-directory/**", - "-l", - ]).test({ + runCli("cli/patterns", ["**/*.js", "!**/nested-directory/**", "-l"]).test({ status: 1, }); }); describe("multiple patterns by with ignore pattern, ignores node_modules by default", () => { - runPrettier("cli/patterns", ["**/*.js", "!directory/**", "-l"]).test({ + runCli("cli/patterns", ["**/*.js", "!directory/**", "-l"]).test({ status: 1, }); }); describe("multiple patterns by with ignore pattern, ignores node_modules by with ./**/*.js", () => { - runPrettier("cli/patterns", ["./**/*.js", "!./directory/**", "-l"]).test({ + runCli("cli/patterns", ["./**/*.js", "!./directory/**", "-l"]).test({ status: 1, }); }); describe("multiple patterns by with ignore pattern, doesn't ignore node_modules with --with-node-modules flag", () => { - runPrettier("cli/patterns", [ + runCli("cli/patterns", [ "**/*.js", "!directory/**", "-l", @@ -53,13 +45,13 @@ describe("multiple patterns by with ignore pattern, doesn't ignore node_modules describe("no errors on empty patterns", () => { // --parser is mandatory if no filepath is passed - runPrettier("cli/patterns", ["--parser", "babel"]).test({ + runCli("cli/patterns", ["--parser", "babel"]).test({ status: 0, }); }); describe("multiple patterns, throw error and exit with non zero code on non existing files", () => { - runPrettier("cli/patterns", [ + runCli("cli/patterns", [ "non-existent.js", "other-non-existent.js", "-l", diff --git a/tests/integration/__tests__/performance-flags.js b/tests/integration/__tests__/performance-flags.js index 008eb27a0..3ddf0e337 100644 --- a/tests/integration/__tests__/performance-flags.js +++ b/tests/integration/__tests__/performance-flags.js @@ -8,7 +8,7 @@ describe("should not write file or print code when `--debug-benchmark` or `--deb }; // Can't test `--debug-benchmark`, since it requires `benchmark` package - runPrettier( + runCli( "cli/performance-flags", ["--debug-repeat", "2", "--parser", "babel"], { input: "foo( bar )" } @@ -21,7 +21,7 @@ describe("should not write file or print code when `--debug-benchmark` or `--deb // The log level is always `debug` for (const logLevel of ["warn", "error", "debug", "log"]) { - runPrettier( + runCli( "cli/performance-flags", ["--debug-repeat", "2", "--parser", "babel", "--log-level", logLevel], { input: "foo( bar )" } @@ -33,7 +33,7 @@ describe("should not write file or print code when `--debug-benchmark` or `--deb }); } - runPrettier("cli/performance-flags", [ + runCli("cli/performance-flags", [ "fixture.js", "--debug-repeat", "2", @@ -46,7 +46,7 @@ describe("should not write file or print code when `--debug-benchmark` or `--deb write: [], }); - runPrettier("cli/performance-flags", [ + runCli("cli/performance-flags", [ "fixture.js", "--debug-repeat", "2", @@ -60,7 +60,7 @@ describe("should not write file or print code when `--debug-benchmark` or `--deb write: [], }); - runPrettier("cli/performance-flags", [ + runCli("cli/performance-flags", [ "fixture.js", "--debug-repeat", "2", diff --git a/tests/integration/__tests__/piped-output.js b/tests/integration/__tests__/piped-output.js index 84fa3e3f4..767406801 100644 --- a/tests/integration/__tests__/piped-output.js +++ b/tests/integration/__tests__/piped-output.js @@ -1,5 +1,5 @@ describe("output with --check + unformatted differs when piped", () => { - const cli0 = runPrettier( + const cli0 = runCli( "cli/write", ["--write", "--check", "--no-color", "unformatted.js"], { stdoutIsTTY: true } @@ -7,7 +7,7 @@ describe("output with --check + unformatted differs when piped", () => { status: 0, }); - const cli1 = runPrettier( + const cli1 = runCli( "cli/write", ["--write", "--check", "--no-color", "unformatted.js"], { stdoutIsTTY: false } @@ -25,7 +25,7 @@ describe("output with --check + unformatted differs when piped", () => { }); describe("no file diffs with --check + formatted file", () => { - const cli0 = runPrettier( + const cli0 = runCli( "cli/write", ["--write", "--check", "--no-color", "formatted.js"], { stdoutIsTTY: true } @@ -33,7 +33,7 @@ describe("no file diffs with --check + formatted file", () => { status: 0, }); - const cli1 = runPrettier( + const cli1 = runCli( "cli/write", ["--write", "--check", "--no-color", "formatted.js"], { stdoutIsTTY: false } @@ -52,7 +52,7 @@ describe("no file diffs with --check + formatted file", () => { }); describe("output with --list-different + unformatted differs when piped", () => { - const cli0 = runPrettier( + const cli0 = runCli( "cli/write", ["--write", "--list-different", "--no-color", "unformatted.js"], { stdoutIsTTY: true } @@ -60,7 +60,7 @@ describe("output with --list-different + unformatted differs when piped", () => status: 0, }); - const cli1 = runPrettier( + const cli1 = runCli( "cli/write", ["--write", "--list-different", "--no-color", "unformatted.js"], { stdoutIsTTY: false } @@ -78,7 +78,7 @@ describe("output with --list-different + unformatted differs when piped", () => }); describe("no file diffs with --list-different + formatted file", () => { - const cli0 = runPrettier( + const cli0 = runCli( "cli/write", ["--write", "--list-different", "--no-color", "formatted.js"], { stdoutIsTTY: true } @@ -86,7 +86,7 @@ describe("no file diffs with --list-different + formatted file", () => { status: 0, }); - const cli1 = runPrettier( + const cli1 = runCli( "cli/write", ["--write", "--list-different", "--no-color", "formatted.js"], { stdoutIsTTY: false } diff --git a/tests/integration/__tests__/plugin-default-options.js b/tests/integration/__tests__/plugin-default-options.js index 4013d51ca..5c80a76ab 100644 --- a/tests/integration/__tests__/plugin-default-options.js +++ b/tests/integration/__tests__/plugin-default-options.js @@ -1,5 +1,5 @@ describe("plugin default options should work", () => { - runPrettier( + runCli( "plugins/defaultOptions", [ "--stdin-filepath", @@ -20,7 +20,7 @@ describe("plugin default options should work", () => { }); describe("overriding plugin default options should work", () => { - runPrettier( + runCli( "plugins/defaultOptions", [ "--stdin-filepath", diff --git a/tests/integration/__tests__/plugin-extensions.js b/tests/integration/__tests__/plugin-extensions.js index fc98c9545..34ac94d3b 100644 --- a/tests/integration/__tests__/plugin-extensions.js +++ b/tests/integration/__tests__/plugin-extensions.js @@ -1,5 +1,5 @@ describe("uses 'extensions' from languages to determine parser", () => { - runPrettier("plugins/extensions", ["*.foo", "--plugin=./plugin.cjs"], { + runCli("plugins/extensions", ["*.foo", "--plugin=./plugin.cjs"], { ignoreLineEndings: true, }).test({ stdout: "!contents", diff --git a/tests/integration/__tests__/plugin-flush-line-suffix.js b/tests/integration/__tests__/plugin-flush-line-suffix.js index 9e27ca228..183a1f0c9 100644 --- a/tests/integration/__tests__/plugin-flush-line-suffix.js +++ b/tests/integration/__tests__/plugin-flush-line-suffix.js @@ -1,5 +1,5 @@ describe("flush all line-suffix content", () => { - runPrettier("plugins/flushLineSuffix", ["*.foo", "--plugin=./plugin.cjs"], { + runCli("plugins/flushLineSuffix", ["*.foo", "--plugin=./plugin.cjs"], { ignoreLineEndings: true, }).test({ stdout: "contents", diff --git a/tests/integration/__tests__/plugin-options-string.js b/tests/integration/__tests__/plugin-options-string.js index 97749613f..d09d77fee 100644 --- a/tests/integration/__tests__/plugin-options-string.js +++ b/tests/integration/__tests__/plugin-options-string.js @@ -1,8 +1,8 @@ import snapshotDiff from "snapshot-diff"; test("show external options with `--help`", async () => { - const originalStdout = await runPrettier("plugins/options-string", ["--help"]) + const originalStdout = await runCli("plugins/options-string", ["--help"]) .stdout; - const pluggedStdout = await runPrettier("plugins/options-string", [ + const pluggedStdout = await runCli("plugins/options-string", [ "--help", "--plugin=./plugin.cjs", ]).stdout; @@ -10,7 +10,7 @@ test("show external options with `--help`", async () => { }); describe("show detailed external option with `--help foo-string`", () => { - runPrettier("plugins/options-string", [ + runCli("plugins/options-string", [ "--plugin=./plugin.cjs", "--help", "foo-string", @@ -20,7 +20,7 @@ describe("show detailed external option with `--help foo-string`", () => { }); describe("external options from CLI should work", () => { - runPrettier( + runCli( "plugins/options-string", [ "--plugin=./plugin.cjs", @@ -39,7 +39,7 @@ describe("external options from CLI should work", () => { }); describe("external options from config file should work", () => { - runPrettier( + runCli( "plugins/options-string", ["--config=./config.json", "--stdin-filepath", "example.foo"], { input: "hello-world" } @@ -52,7 +52,7 @@ describe("external options from config file should work", () => { }); describe("Non exists plugin", () => { - runPrettier( + runCli( "plugins/options-string", ["--plugin=--invalid--", "--stdin-filepath", "example.foo"], { input: "hello-world" } diff --git a/tests/integration/__tests__/plugin-options.js b/tests/integration/__tests__/plugin-options.js index 685d66561..2e90bf79c 100644 --- a/tests/integration/__tests__/plugin-options.js +++ b/tests/integration/__tests__/plugin-options.js @@ -1,8 +1,7 @@ import snapshotDiff from "snapshot-diff"; test("show external options with `--help`", async () => { - const originalStdout = await runPrettier("plugins/options", ["--help"]) - .stdout; - const pluggedStdout = await runPrettier("plugins/options", [ + const originalStdout = await runCli("plugins/options", ["--help"]).stdout; + const pluggedStdout = await runCli("plugins/options", [ "--help", "--plugin=./plugin.cjs", ]).stdout; @@ -11,7 +10,7 @@ test("show external options with `--help`", async () => { }); describe("show detailed external option with `--help foo-option`", () => { - runPrettier("plugins/options", [ + runCli("plugins/options", [ "--plugin=./plugin.cjs", "--help", "foo-option", @@ -21,17 +20,15 @@ describe("show detailed external option with `--help foo-option`", () => { }); describe("include plugin's parsers to the values of the `parser` option`", () => { - runPrettier("plugins/options", [ - "--plugin=./plugin.cjs", - "--help", - "parser", - ]).test({ - status: 0, - }); + runCli("plugins/options", ["--plugin=./plugin.cjs", "--help", "parser"]).test( + { + status: 0, + } + ); }); describe("external options from CLI should work", () => { - runPrettier( + runCli( "plugins/options", [ "--plugin=./plugin.cjs", @@ -50,7 +47,7 @@ describe("external options from CLI should work", () => { }); describe("external options from config file should work", () => { - runPrettier( + runCli( "plugins/options", ["--config=./config.json", "--stdin-filepath", "example.foo"], { input: "hello-world" } diff --git a/tests/integration/__tests__/plugin-precedence.js b/tests/integration/__tests__/plugin-precedence.js index af95d1548..570a9dd19 100644 --- a/tests/integration/__tests__/plugin-precedence.js +++ b/tests/integration/__tests__/plugin-precedence.js @@ -1,5 +1,5 @@ describe("json-stringify takes precedence over json for package.json", () => { - runPrettier("plugins", ["--stdin-filepath=package.json"], { + runCli("plugins", ["--stdin-filepath=package.json"], { input: '{ "a": "longlonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglong" }', }).test({ diff --git a/tests/integration/__tests__/plugin-preprocess.js b/tests/integration/__tests__/plugin-preprocess.js index f872da431..9affc78c6 100644 --- a/tests/integration/__tests__/plugin-preprocess.js +++ b/tests/integration/__tests__/plugin-preprocess.js @@ -1,5 +1,5 @@ describe("parser preprocess function is used to reshape input text", () => { - runPrettier("plugins/preprocess", ["*.foo", "--plugin=./plugin.cjs"], { + runCli("plugins/preprocess", ["*.foo", "--plugin=./plugin.cjs"], { ignoreLineEndings: true, }).test({ stdout: "preprocessed:contents", diff --git a/tests/integration/__tests__/plugin-resolution.js b/tests/integration/__tests__/plugin-resolution.js index d433899ea..c8e56dd7d 100644 --- a/tests/integration/__tests__/plugin-resolution.js +++ b/tests/integration/__tests__/plugin-resolution.js @@ -1,5 +1,5 @@ describe("automatically loads 'prettier-plugin-*'", () => { - runPrettier("plugins/automatic", ["file.txt", "--parser=bar"]).test({ + runCli("plugins/automatic", ["file.txt", "--parser=bar"]).test({ stdout: "content from `prettier-plugin-bar` package + contents", stderr: "", status: 0, @@ -8,7 +8,7 @@ describe("automatically loads 'prettier-plugin-*'", () => { }); describe("automatically loads '@prettier/plugin-*'", () => { - runPrettier("plugins/automatic", ["file.txt", "--parser=foo"]).test({ + runCli("plugins/automatic", ["file.txt", "--parser=foo"]).test({ stdout: "foo+contents", stderr: "", status: 0, @@ -17,7 +17,7 @@ describe("automatically loads '@prettier/plugin-*'", () => { }); describe("automatically loads '@/prettier-plugin-*'", () => { - runPrettier("plugins/automatic", ["file.txt", "--parser=foobar"]).test({ + runCli("plugins/automatic", ["file.txt", "--parser=foobar"]).test({ stdout: "foobar+contents", stderr: "", status: 0, @@ -26,7 +26,7 @@ describe("automatically loads '@/prettier-plugin-*'", () => { }); describe("automatically loads 'prettier-plugin-*' from --plugin-search-dir (same as autoload dir)", () => { - runPrettier("plugins/automatic", [ + runCli("plugins/automatic", [ "file.txt", "--parser=foo", "--plugin-search-dir=.", @@ -39,7 +39,7 @@ describe("automatically loads 'prettier-plugin-*' from --plugin-search-dir (same }); describe("automatically loads '@prettier/plugin-*' from --plugin-search-dir (same as autoload dir)", () => { - runPrettier("plugins/automatic", [ + runCli("plugins/automatic", [ "file.txt", "--parser=bar", "--plugin-search-dir=.", @@ -52,7 +52,7 @@ describe("automatically loads '@prettier/plugin-*' from --plugin-search-dir (sam }); describe("automatically loads '@/prettier-plugin-*' from --plugin-search-dir (same as autoload dir)", () => { - runPrettier("plugins/automatic", [ + runCli("plugins/automatic", [ "file.txt", "--parser=foobar", "--plugin-search-dir=.", @@ -65,7 +65,7 @@ describe("automatically loads '@/prettier-plugin-*' from --plugin-search-d }); describe("automatically loads 'prettier-plugin-*' from --plugin-search-dir (different to autoload dir)", () => { - runPrettier("plugins", [ + runCli("plugins", [ "automatic/file.txt", "--parser=foo", "--plugin-search-dir=automatic", @@ -78,7 +78,7 @@ describe("automatically loads 'prettier-plugin-*' from --plugin-search-dir (diff }); describe("automatically loads '@prettier/plugin-*' from --plugin-search-dir (different to autoload dir)", () => { - runPrettier("plugins", [ + runCli("plugins", [ "automatic/file.txt", "--parser=bar", "--plugin-search-dir=automatic", @@ -91,7 +91,7 @@ describe("automatically loads '@prettier/plugin-*' from --plugin-search-dir (dif }); describe("does not crash when --plugin-search-dir does not contain node_modules", () => { - runPrettier( + runCli( "plugins/extensions", [ "file.foo", @@ -110,7 +110,7 @@ describe("does not crash when --plugin-search-dir does not contain node_modules" }); describe("crashes when one of --plugin-search-dir does not exist", () => { - runPrettier("plugins/automatic", [ + runCli("plugins/automatic", [ "file.txt", "--parser=foo", "--plugin-search-dir=non-existing-dir", @@ -124,7 +124,7 @@ describe("crashes when one of --plugin-search-dir does not exist", () => { }); describe("loads --plugin by its relative path", () => { - runPrettier("plugins", [ + runCli("plugins", [ "automatic/file.txt", "--parser=bar", "--plugin=./automatic/node_modules/prettier-plugin-bar/index.js", @@ -137,7 +137,7 @@ describe("loads --plugin by its relative path", () => { }); describe("loads --plugin by its relative path without leading ./", () => { - runPrettier("plugins", [ + runCli("plugins", [ "automatic/file.txt", "--parser=bar", "--plugin=automatic/node_modules/prettier-plugin-bar/index.js", @@ -150,7 +150,7 @@ describe("loads --plugin by its relative path without leading ./", () => { }); describe("loads --plugin by package name", () => { - runPrettier("plugins/automatic", [ + runCli("plugins/automatic", [ "file.txt", "--parser=foobar", "--plugin=@user/prettier-plugin-foobar", @@ -163,7 +163,7 @@ describe("loads --plugin by package name", () => { }); describe("loads --plugin by filename without leading ./, should resolve to file, not package", () => { - runPrettier("plugins/automatic", [ + runCli("plugins/automatic", [ "file.txt", "--parser=baz", "--plugin=prettier-plugin-baz.js", @@ -177,7 +177,7 @@ describe("loads --plugin by filename without leading ./, should resolve to file, }); describe("loads --plugin by bespoke plugin name (assuming it is installed in cwd)", () => { - runPrettier("plugins/bespoke", [ + runCli("plugins/bespoke", [ "../automatic/file.txt", "--parser=bespoke", "--plugin=@company/prettier-plugin-bespoke/main.js", @@ -191,7 +191,7 @@ describe("loads --plugin by bespoke plugin name (assuming it is installed in cwd test("--no-plugin-search", async () => { async function getParser(args = []) { - const { stdout } = await runPrettier("plugins/automatic", [ + const { stdout } = await runCli("plugins/automatic", [ "--file-info=file.foo", ...args, ]); @@ -205,20 +205,20 @@ test("--no-plugin-search", async () => { test("--no-plugin-search still allow use --plugin", async () => { const args = ["file.txt", "--parser=baz"]; - const { stdout: stdoutWithoutPlugin } = await runPrettier( + const { stdout: stdoutWithoutPlugin } = await runCli( "plugins/automatic", args ); const argsWithPlugin = [...args, "--plugin=./prettier-plugin-baz.js"]; - const { stdout: stdoutWithPlugin } = await runPrettier( + const { stdout: stdoutWithPlugin } = await runCli( "plugins/automatic", argsWithPlugin ); - const { stdout: stdoutWithoutPluginAndNoPluginSearch } = await runPrettier( + const { stdout: stdoutWithoutPluginAndNoPluginSearch } = await runCli( "plugins/automatic", [...args, "--no-plugin-search"] ); - const { stdout: stdoutWithPluginButNoPluginSearch } = await runPrettier( + const { stdout: stdoutWithPluginButNoPluginSearch } = await runCli( "plugins/automatic", [...argsWithPlugin, "--no-plugin-search"] ); @@ -236,15 +236,15 @@ test("--no-plugin-search still allow use --plugin", async () => { }); test("--no-plugin-search together with --plugin-search-dir", async () => { - const result1 = await runPrettier("plugins/automatic", [ + const result1 = await runCli("plugins/automatic", [ "--no-plugin-search", "--plugin-search-dir", ]); - const result2 = await runPrettier("plugins/automatic", [ + const result2 = await runCli("plugins/automatic", [ "--no-plugin-search", "--plugin-search-dir=foo", ]); - const result3 = await runPrettier("plugins/automatic", [ + const result3 = await runCli("plugins/automatic", [ "--no-plugin-search", "--plugin-search-dir=foo", "--plugin-search-dir=bar", diff --git a/tests/integration/__tests__/plugin-virtual-directory.js b/tests/integration/__tests__/plugin-virtual-directory.js index 75b80e964..159a7d011 100644 --- a/tests/integration/__tests__/plugin-virtual-directory.js +++ b/tests/integration/__tests__/plugin-virtual-directory.js @@ -1,5 +1,5 @@ describe("plugin search should not crash when prettier isn't inside a directory", () => { - runPrettier( + runCli( "plugins/virtualDirectory", ["--stdin-filepath", "example.js", "--plugin-search-dir=."], { input: "" } diff --git a/tests/integration/__tests__/skip-folders.js b/tests/integration/__tests__/skip-folders.js index a58b68114..43d43fa07 100644 --- a/tests/integration/__tests__/skip-folders.js +++ b/tests/integration/__tests__/skip-folders.js @@ -1,16 +1,13 @@ describe("skips folders in glob", () => { - runPrettier("cli/skip-folders", ["**/*", "-l"]).test({ + runCli("cli/skip-folders", ["**/*", "-l"]).test({ status: 1, stderr: "", }); }); describe("skip folders passed specifically", () => { - runPrettier("cli/skip-folders", [ - "a", - "a/file.js", - "b", - "b/file.js", - "-l", - ]).test({ status: 1, stderr: "" }); + runCli("cli/skip-folders", ["a", "a/file.js", "b", "b/file.js", "-l"]).test({ + status: 1, + stderr: "", + }); }); diff --git a/tests/integration/__tests__/stdin-filepath.js b/tests/integration/__tests__/stdin-filepath.js index ff6c190e8..bee1d0ac7 100644 --- a/tests/integration/__tests__/stdin-filepath.js +++ b/tests/integration/__tests__/stdin-filepath.js @@ -1,7 +1,7 @@ import { isCI } from "ci-info"; import { outdent } from "outdent"; describe("format correctly if stdin content compatible with stdin-filepath", () => { - runPrettier( + runCli( "cli", ["--stdin-filepath", "abc.css"], { input: ".name { display: none; }" } // css @@ -11,7 +11,7 @@ describe("format correctly if stdin content compatible with stdin-filepath", () }); describe("throw error if stdin content incompatible with stdin-filepath", () => { - runPrettier( + runCli( "cli", ["--stdin-filepath", "abc.js"], { input: ".name { display: none; }" } // css @@ -21,7 +21,7 @@ describe("throw error if stdin content incompatible with stdin-filepath", () => }); describe("gracefully handle stdin-filepath with nonexistent directory", () => { - runPrettier( + runCli( "cli", ["--stdin-filepath", "definitely/nonexistent/path.css"], { input: ".name { display: none; }" } // css @@ -31,23 +31,19 @@ describe("gracefully handle stdin-filepath with nonexistent directory", () => { }); describe("apply editorconfig for stdin-filepath with nonexistent file", () => { - runPrettier( - "cli", - ["--stdin-filepath", "config/editorconfig/nonexistent.js"], - { - input: outdent` - function f() { - console.log("should be indented with a tab"); - } - `, // js - } - ).test({ + runCli("cli", ["--stdin-filepath", "config/editorconfig/nonexistent.js"], { + input: outdent` + function f() { + console.log("should be indented with a tab"); + } + `, // js + }).test({ status: 0, }); }); describe("apply editorconfig for stdin-filepath with nonexistent directory", () => { - runPrettier( + runCli( "cli", ["--stdin-filepath", "config/editorconfig/nonexistent/one/two/three.js"], { @@ -63,7 +59,7 @@ describe("apply editorconfig for stdin-filepath with nonexistent directory", () }); describe("apply editorconfig for stdin-filepath with a deep path", () => { - runPrettier( + runCli( "cli", ["--stdin-filepath", "config/editorconfig/" + "a/".repeat(30) + "three.js"], { @@ -85,7 +81,7 @@ if (isCI) { console.log("should be indented with a tab"); } `; - runPrettier("cli", ["--stdin-filepath", "/foo.js"], { + runCli("cli", ["--stdin-filepath", "/foo.js"], { input: code, // js }).test({ status: 0, @@ -97,7 +93,7 @@ if (isCI) { } describe("apply editorconfig for stdin-filepath with a deep path", () => { - runPrettier( + runCli( "cli", ["--stdin-filepath", "config/editorconfig/" + "a/".repeat(30) + "three.js"], { @@ -113,7 +109,7 @@ describe("apply editorconfig for stdin-filepath with a deep path", () => { }); describe("don’t apply editorconfig outside project for stdin-filepath with nonexistent directory", () => { - runPrettier( + runCli( "cli", [ "--stdin-filepath", @@ -132,7 +128,7 @@ describe("don’t apply editorconfig outside project for stdin-filepath with non }); describe("output file as-is if stdin-filepath matched patterns in ignore-path", () => { - runPrettier("cli/stdin-ignore", ["--stdin-filepath", "ignore/example.js"], { + runCli("cli/stdin-ignore", ["--stdin-filepath", "ignore/example.js"], { input: "hello_world( );", }).test({ stdout: "hello_world( );", diff --git a/tests/integration/__tests__/support-info.js b/tests/integration/__tests__/support-info.js index 49d186af7..ca48375af 100644 --- a/tests/integration/__tests__/support-info.js +++ b/tests/integration/__tests__/support-info.js @@ -5,7 +5,7 @@ test("API getSupportInfo()", async () => { }); describe("CLI --support-info", () => { - runPrettier("cli", "--support-info").test({ status: 0 }); + runCli("cli", "--support-info").test({ status: 0 }); }); async function getCoreInfo() { diff --git a/tests/integration/__tests__/syntax-error.js b/tests/integration/__tests__/syntax-error.js index 944feb63a..6ad67a770 100644 --- a/tests/integration/__tests__/syntax-error.js +++ b/tests/integration/__tests__/syntax-error.js @@ -1,5 +1,5 @@ describe("exits with non-zero code when input has a syntax error", () => { - runPrettier("cli/with-shebang", ["--parser", "babel"], { + runCli("cli/with-shebang", ["--parser", "babel"], { input: "a.2", }).test({ status: 2, diff --git a/tests/integration/__tests__/with-config-precedence.js b/tests/integration/__tests__/with-config-precedence.js index 668e043bc..eac92e8d8 100644 --- a/tests/integration/__tests__/with-config-precedence.js +++ b/tests/integration/__tests__/with-config-precedence.js @@ -12,12 +12,12 @@ const TAB_WIDTH_5_OUTPUT = outdent` `; test("CLI overrides take precedence --config-precedence", async () => { - const withoutFlag = await runPrettier("cli/config-precedence/valid-config", [ + const withoutFlag = await runCli("cli/config-precedence/valid-config", [ "foo.js", ]).stdout; expect(withoutFlag).toBe(TAB_WIDTH_3_OUTPUT); - const withFlag = await runPrettier("cli/config-precedence/valid-config", [ + const withFlag = await runCli("cli/config-precedence/valid-config", [ "--tab-width", "5", "foo.js", @@ -26,14 +26,14 @@ test("CLI overrides take precedence --config-precedence", async () => { }); test("CLI overrides take precedence with --config-precedence cli-override", async () => { - const withoutFlag = await runPrettier("cli/config-precedence/valid-config", [ + const withoutFlag = await runCli("cli/config-precedence/valid-config", [ "--config-precedence", "cli-override", "foo.js", ]).stdout; expect(withoutFlag).toBe(TAB_WIDTH_3_OUTPUT); - const withFlag = await runPrettier("cli/config-precedence/valid-config", [ + const withFlag = await runCli("cli/config-precedence/valid-config", [ "--config-precedence", "cli-override", "--tab-width", @@ -44,14 +44,14 @@ test("CLI overrides take precedence with --config-precedence cli-override", asyn }); test("CLI overrides take lower precedence with --config-precedence file-override", async () => { - const withoutFlag = await runPrettier("cli/config-precedence/valid-config", [ + const withoutFlag = await runCli("cli/config-precedence/valid-config", [ "--config-precedence", "file-override", "foo.js", ]).stdout; expect(withoutFlag).toBe(TAB_WIDTH_3_OUTPUT); - const withFlag = await runPrettier("cli/config-precedence/valid-config", [ + const withFlag = await runCli("cli/config-precedence/valid-config", [ "--config-precedence", "file-override", "--tab-width", @@ -62,7 +62,7 @@ test("CLI overrides take lower precedence with --config-precedence file-override }); describe("CLI overrides are still applied when no config is found with --config-precedence file-override", () => { - runPrettier("cli/config/no-config/", [ + runCli("cli/config/no-config/", [ "--end-of-line", "lf", "--tab-width", @@ -77,7 +77,7 @@ describe("CLI overrides are still applied when no config is found with --config- }); describe("CLI overrides gets ignored when config exists with --config-precedence prefer-file", () => { - runPrettier("cli/config/js/", [ + runCli("cli/config/js/", [ "--print-width", "1", "--tab-width", @@ -91,7 +91,7 @@ describe("CLI overrides gets ignored when config exists with --config-precedence }); describe("CLI overrides gets applied when no config exists with --config-precedence prefer-file", () => { - runPrettier("cli/config/no-config/", [ + runCli("cli/config/no-config/", [ "--end-of-line", "lf", "--print-width", @@ -108,7 +108,7 @@ describe("CLI overrides gets applied when no config exists with --config-precede }); describe("CLI validate options with --config-precedence cli-override", () => { - runPrettier("cli/config-precedence/invalid-config", [ + runCli("cli/config-precedence/invalid-config", [ "--config-precedence", "cli-override", ]).test({ @@ -117,7 +117,7 @@ describe("CLI validate options with --config-precedence cli-override", () => { }); describe("CLI validate options with --config-precedence file-override", () => { - runPrettier("cli/config-precedence/invalid-config", [ + runCli("cli/config-precedence/invalid-config", [ "--config-precedence", "file-override", ]).test({ @@ -126,7 +126,7 @@ describe("CLI validate options with --config-precedence file-override", () => { }); describe("CLI validate options with --config-precedence prefer-file", () => { - runPrettier("cli/config-precedence/invalid-config", [ + runCli("cli/config-precedence/invalid-config", [ "--config-precedence", "prefer-file", ]).test({ @@ -135,7 +135,7 @@ describe("CLI validate options with --config-precedence prefer-file", () => { }); describe("CLI --stdin-filepath works with --config-precedence prefer-file", () => { - runPrettier( + runCli( "cli/config-precedence/overrides", ["--stdin-filepath=abc.ts", "--no-semi", "--config-precedence=prefer-file"], { input: "let x: keyof Y = foo()" } // typescript @@ -146,7 +146,7 @@ describe("CLI --stdin-filepath works with --config-precedence prefer-file", () = }); describe("CLI --stdin-filepath works with --config-precedence file-override", () => { - runPrettier( + runCli( "cli/config-precedence/overrides", [ "--stdin-filepath=abc.ts", @@ -161,7 +161,7 @@ describe("CLI --stdin-filepath works with --config-precedence file-override", () }); describe("CLI --stdin-filepath works with --config-precedence cli-override", () => { - runPrettier( + runCli( "cli/config-precedence/overrides", [ "--stdin-filepath=abc.ts", diff --git a/tests/integration/__tests__/with-node-modules.js b/tests/integration/__tests__/with-node-modules.js index ef599379b..b1618df20 100644 --- a/tests/integration/__tests__/with-node-modules.js +++ b/tests/integration/__tests__/with-node-modules.js @@ -1,17 +1,17 @@ describe("ignores node_modules by default", () => { - runPrettier("cli/with-node-modules", ["**/*.js", "-l"]).test({ + runCli("cli/with-node-modules", ["**/*.js", "-l"]).test({ status: 1, }); }); describe("ignores node_modules by with ./**/*.js", () => { - runPrettier("cli/with-node-modules", ["./**/*.js", "-l"]).test({ + runCli("cli/with-node-modules", ["./**/*.js", "-l"]).test({ status: 1, }); }); describe("doesn't ignore node_modules with --with-node-modules flag", () => { - runPrettier("cli/with-node-modules", [ + runCli("cli/with-node-modules", [ "**/*.js", "-l", "--with-node-modules", @@ -21,7 +21,7 @@ describe("doesn't ignore node_modules with --with-node-modules flag", () => { }); describe("ignores node_modules by default for file list", () => { - runPrettier("cli/with-node-modules", [ + runCli("cli/with-node-modules", [ "node_modules/node-module.js", "not_node_modules/file.js", "nested/node_modules/node-module.js", @@ -33,7 +33,7 @@ describe("ignores node_modules by default for file list", () => { }); describe("doesn't ignore node_modules with --with-node-modules flag for file list", () => { - runPrettier("cli/with-node-modules", [ + runCli("cli/with-node-modules", [ "node_modules/node-module.js", "not_node_modules/file.js", "nested/node_modules/node-module.js", diff --git a/tests/integration/__tests__/with-parser-inference.js b/tests/integration/__tests__/with-parser-inference.js index b6d4a0615..5a5103010 100644 --- a/tests/integration/__tests__/with-parser-inference.js +++ b/tests/integration/__tests__/with-parser-inference.js @@ -2,19 +2,19 @@ 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({ + runCli("cli/with-parser-inference", ["--end-of-line", "lf", "*"]).test({ status: 0, }); }); describe("infers postcss parser with --check", () => { - runPrettier("cli/with-parser-inference", ["--check", "*"]).test({ + runCli("cli/with-parser-inference", ["--check", "*"]).test({ status: 0, }); }); describe("infers postcss parser with --list-different", () => { - runPrettier("cli/with-parser-inference", ["--list-different", "*"]).test({ + runCli("cli/with-parser-inference", ["--list-different", "*"]).test({ status: 0, }); }); diff --git a/tests/integration/__tests__/with-shebang.js b/tests/integration/__tests__/with-shebang.js index 288809da5..fffd23d6c 100644 --- a/tests/integration/__tests__/with-shebang.js +++ b/tests/integration/__tests__/with-shebang.js @@ -1,7 +1,5 @@ describe("preserves shebang", () => { - runPrettier("cli/with-shebang", ["--end-of-line", "lf", "issue1890.js"]).test( - { - status: 0, - } - ); + runCli("cli/with-shebang", ["--end-of-line", "lf", "issue1890.js"]).test({ + status: 0, + }); }); diff --git a/tests/integration/__tests__/write.js b/tests/integration/__tests__/write.js index 61b9ddbb4..fbc38818c 100644 --- a/tests/integration/__tests__/write.js +++ b/tests/integration/__tests__/write.js @@ -1,24 +1,24 @@ describe("write file with --write + unformatted file", () => { - runPrettier("cli/write", ["--write", "unformatted.js"]).test({ + runCli("cli/write", ["--write", "unformatted.js"]).test({ status: 0, }); }); describe("write file with -w + unformatted file", () => { - runPrettier("cli/write", ["-w", "unformatted.js"]).test({ + runCli("cli/write", ["-w", "unformatted.js"]).test({ status: 0, }); }); describe("do not write file with --write + formatted file", () => { - runPrettier("cli/write", ["--write", "formatted.js"]).test({ + runCli("cli/write", ["--write", "formatted.js"]).test({ write: [], status: 0, }); }); describe("do not write file with --write + invalid file", () => { - runPrettier("cli/write", ["--write", "invalid.js"]).test({ + runCli("cli/write", ["--write", "invalid.js"]).test({ write: [], status: "non-zero", }); diff --git a/tests/integration/integration-test-setup.js b/tests/integration/integration-test-setup.js index 0009cb720..19c2d2160 100644 --- a/tests/integration/integration-test-setup.js +++ b/tests/integration/integration-test-setup.js @@ -1,3 +1,3 @@ -import runPrettier from "./run-prettier.js"; +import runCli from "./run-cli.js"; -globalThis.runPrettier = runPrettier; +globalThis.runCli = runCli; diff --git a/tests/integration/run-prettier.js b/tests/integration/run-cli.js similarity index 87% rename from tests/integration/run-prettier.js rename to tests/integration/run-cli.js index 4399be52a..aa44d5731 100644 --- a/tests/integration/run-prettier.js +++ b/tests/integration/run-cli.js @@ -73,7 +73,7 @@ function runCliWorker(dir, args, options) { }); } -async function run(dir, args, options) { +async function runPrettierCli(dir, args, options) { dir = path.resolve(INTEGRATION_TEST_DIRECTORY, dir); args = Array.isArray(args) ? args : [args]; @@ -89,36 +89,36 @@ async function run(dir, args, options) { } let runningCli; -function runPrettier(dir, args = [], options = {}) { +function runCli(dir, args = [], options = {}) { let promise; const getters = { get status() { - return runCli().then(({ status }) => status); + return run().then(({ status }) => status); }, get stdout() { - return runCli().then(({ stdout }) => stdout); + return run().then(({ stdout }) => stdout); }, get stderr() { - return runCli().then(({ stderr }) => stderr); + return run().then(({ stderr }) => stderr); }, get write() { - return runCli().then(({ write }) => write); + return run().then(({ write }) => write); }, test: testResult, then(onFulfilled, onRejected) { - return runCli().then(onFulfilled, onRejected); + return run().then(onFulfilled, onRejected); }, }; return getters; - function runCli() { + function run() { if (runningCli) { throw new Error("Please wait for previous CLI to exit."); } if (!promise) { - promise = run(dir, args, options).finally(() => { + promise = runPrettierCli(dir, args, options).finally(() => { runningCli = undefined; }); runningCli = promise; @@ -129,7 +129,7 @@ function runPrettier(dir, args = [], options = {}) { function testResult(testOptions) { for (const name of ["status", "stdout", "stderr", "write"]) { test(`${options.title || ""}(${name})`, async () => { - const result = await runCli(); + const result = await run(); let value = result[name]; // \r is trimmed from jest snapshots by default; // manually replacing this character with /*CR*/ to test its true presence @@ -159,4 +159,4 @@ function runPrettier(dir, args = [], options = {}) { } } -export default runPrettier; +export default runCli;