From f5f81683ca9f4bbdf68ba97e552ec018f9348dca Mon Sep 17 00:00:00 2001 From: Connor Peet Date: Sat, 6 Feb 2021 07:38:54 +0000 Subject: [PATCH] initial work in progress --- bin/prettier.js | 2 +- scripts/build/config.js | 11 ++ src/cli/expand-patterns.js | 16 +- src/cli/format-worker.js | 138 ++++++++++++++++++ src/cli/format.js | 134 ++++------------- src/cli/index.js | 6 +- tests_integration/__tests__/arg-parsing.js | 30 ++-- tests_integration/__tests__/check.js | 14 +- tests_integration/__tests__/config-invalid.js | 40 ++--- .../__tests__/config-resolution.js | 40 ++--- tests_integration/__tests__/cursor-offset.js | 8 +- tests_integration/__tests__/debug-check.js | 20 +-- .../__tests__/debug-print-comments.js | 4 +- .../__tests__/debug-print-doc.js | 4 +- tests_integration/__tests__/early-exit.js | 52 +++---- .../__tests__/error-on-unmatched-pattern.js | 16 +- tests_integration/__tests__/file-info.js | 60 ++++---- tests_integration/__tests__/help-options.js | 4 +- .../__tests__/ignore-absolute-path.js | 4 +- tests_integration/__tests__/ignore-emoji.js | 8 +- .../__tests__/ignore-in-subdirectories.js | 20 +-- tests_integration/__tests__/ignore-path.js | 16 +- .../__tests__/ignore-relative-path.js | 4 +- tests_integration/__tests__/ignore-unknown.js | 32 ++-- .../__tests__/ignore-vcs-files.js | 4 +- tests_integration/__tests__/infer-parser.js | 76 +++++----- tests_integration/__tests__/invalid-ignore.js | 4 +- tests_integration/__tests__/list-different.js | 14 +- tests_integration/__tests__/loglevel.js | 26 ++-- tests_integration/__tests__/parser-api.js | 4 +- tests_integration/__tests__/patterns-dirs.js | 12 +- tests_integration/__tests__/patterns-glob.js | 48 +++--- tests_integration/__tests__/patterns.js | 32 ++-- tests_integration/__tests__/piped-output.js | 24 +-- .../__tests__/plugin-default-options.js | 8 +- .../__tests__/plugin-extensions.js | 4 +- .../__tests__/plugin-flush-line-suffix.js | 4 +- .../__tests__/plugin-options-string.js | 22 +-- tests_integration/__tests__/plugin-options.js | 24 +-- .../__tests__/plugin-precedence.js | 4 +- .../__tests__/plugin-preprocess.js | 4 +- .../__tests__/plugin-resolution.js | 64 ++++---- .../__tests__/plugin-virtual-directory.js | 4 +- tests_integration/__tests__/skip-folders.js | 8 +- tests_integration/__tests__/stdin-filepath.js | 40 ++--- tests_integration/__tests__/support-info.js | 4 +- tests_integration/__tests__/syntax-error.js | 4 +- .../__tests__/with-config-precedence.js | 48 +++--- .../__tests__/with-node-modules.js | 20 +-- .../__tests__/with-parser-inference.js | 12 +- tests_integration/__tests__/with-shebang.js | 4 +- tests_integration/__tests__/write.js | 16 +- tests_integration/runPrettier.js | 34 ++--- 53 files changed, 665 insertions(+), 590 deletions(-) create mode 100644 src/cli/format-worker.js diff --git a/bin/prettier.js b/bin/prettier.js index 79fe9b23705a..7f3f91780b41 100755 --- a/bin/prettier.js +++ b/bin/prettier.js @@ -2,4 +2,4 @@ "use strict"; -require("../src/cli").run(process.argv.slice(2)); +module.exports = require("../src/cli").run(process.argv.slice(2)); diff --git a/scripts/build/config.js b/scripts/build/config.js index b99ecd2f1516..5bb4656d3d20 100644 --- a/scripts/build/config.js +++ b/scripts/build/config.js @@ -143,6 +143,17 @@ const coreBundles = [ type: "core", output: "bin-prettier.js", target: "node", + externals: [ + path.resolve("src/index.js"), + path.resolve("src/bin/format-worker.js"), + path.resolve("src/common/third-party.js"), + ], + }, + { + input: "src/bin/format-worker.js", + type: "core", + output: "format-worker.js", + target: "node", externals: [ path.resolve("src/index.js"), path.resolve("src/common/third-party.js"), diff --git a/src/cli/expand-patterns.js b/src/cli/expand-patterns.js index b840ce723f19..55dc25e9e3f6 100644 --- a/src/cli/expand-patterns.js +++ b/src/cli/expand-patterns.js @@ -10,12 +10,12 @@ const flat = require("lodash/flatten"); /** * @param {Context} context */ -function* expandPatterns(context) { +async function* expandPatterns(context) { const cwd = process.cwd(); const seen = new Set(); let noResults = true; - for (const pathOrError of expandPatternsInternal(context)) { + for await (const pathOrError of expandPatternsInternal(context)) { noResults = false; if (typeof pathOrError !== "string") { yield pathOrError; @@ -44,7 +44,7 @@ function* expandPatterns(context) { /** * @param {Context} context */ -function* expandPatternsInternal(context) { +async function* expandPatternsInternal(context) { // Ignores files in version control systems directories and `node_modules` const silentlyIgnoredDirs = { ".git": true, @@ -73,7 +73,7 @@ function* expandPatternsInternal(context) { continue; } - const stat = statSafeSync(absolutePath); + const stat = await statSafe(absolutePath); if (stat) { if (stat.isFile()) { entries.push({ @@ -107,7 +107,7 @@ function* expandPatternsInternal(context) { let result; try { - result = fastGlob.sync(glob, globOptions); + result = await fastGlob(glob, globOptions); } catch ({ message }) { /* istanbul ignore next */ yield { error: `${errorMessages.globError[type]}: ${input}\n${message}` }; @@ -176,11 +176,11 @@ function sortPaths(paths) { /** * Get stats of a given path. * @param {string} filePath The path to target file. - * @returns {fs.Stats | undefined} The stats. + * @returns {Promise} The stats. */ -function statSafeSync(filePath) { +async function statSafe(filePath) { try { - return fs.statSync(filePath); + return fs.promises.stat(filePath); } catch (error) { /* istanbul ignore next */ if (error.code !== "ENOENT") { diff --git a/src/cli/format-worker.js b/src/cli/format-worker.js new file mode 100644 index 000000000000..af4da2247099 --- /dev/null +++ b/src/cli/format-worker.js @@ -0,0 +1,138 @@ +"use strict"; + +const { parentPort, workerData } = require('worker_threads'); +const { promises: fs } = require("fs"); + +const chalk = require("chalk"); + +const { getOptionsForFile } = require("./option"); +const isTTY = require("./is-tty"); +const { format, handleError, writeOutput } = require('./format'); + + +/** @typedef {import('./context').Context} Context */ + +class ProxiedContext { + constructor(properties) { + Object.assign(this, properties); + + /** @type any */ + this.logger = new Proxy({}, { + get(_target, method) { + return (...args) => parentPort.postMessage(['log', method, args]); + } + }); + } +} + +/** @type Context */ +// @ts-ignore +const context = new ProxiedContext(workerData); + +/** + * @param {string} filename + * @param {boolean} fileIgnored + */ +async function processFile(filename, fileIgnored) { + const options = { + ...getOptionsForFile(context, filename), + filepath: filename, + }; + + if (isTTY()) { + context.logger.log(filename, { newline: false }); + } + + let input; + try { + input = await fs.readFile(filename, "utf8"); + } catch (error) { + // Add newline to split errors from filename line. + /* istanbul ignore next */ + context.logger.log(""); + + /* istanbul ignore next */ + context.logger.error( + `Unable to read file: ${filename}\n${error.message}` + ); + + // Don't exit the process if one file failed + /* istanbul ignore next */ + parentPort.postMessage(['setExitCode', 2]); + + /* istanbul ignore next */ + return; + } + + if (fileIgnored) { + writeOutput(context, { formatted: input }, options); + return; + } + + const start = Date.now(); + + let result; + let output; + + try { + result = format(context, input, options); + output = result.formatted; + } catch (error) { + handleError(context, filename, error); + return; + } + + const isDifferent = output !== input; + + if (isTTY()) { + // Remove previously printed filename to log it with duration. + parentPort.postMessage(['resetTTYLine']) + } + + if (context.argv.write) { + // Don't write the file if it won't change in order not to invalidate + // mtime based caches. + if (isDifferent) { + if (!context.argv.check && !context.argv["list-different"]) { + context.logger.log(`${filename} ${Date.now() - start}ms`); + } + + try { + await fs.writeFile(filename, output, "utf8"); + } catch (error) { + /* istanbul ignore next */ + context.logger.error( + `Unable to write file: ${filename}\n${error.message}` + ); + + // Don't exit the process if one file failed + /* istanbul ignore next */ + parentPort.postMessage(['setExitCode', 2]); + } + } else if (!context.argv.check && !context.argv["list-different"]) { + context.logger.log(`${chalk.grey(filename)} ${Date.now() - start}ms`); + } + } else if (context.argv["debug-check"]) { + /* istanbul ignore else */ + if (result.filepath) { + context.logger.log(result.filepath); + } else { + parentPort.postMessage(['setExitCode', 2]); + } + } else if (!context.argv.check && !context.argv["list-different"]) { + writeOutput(context, result, options); + } + + if (isDifferent) { + if (context.argv.check) { + context.logger.warn(filename); + } else if (context.argv["list-different"]) { + context.logger.log(filename); + } + parentPort.postMessage(['foundUnformatted']); + } +} + +parentPort.on('message', ([filename, ignored]) => { + processFile(filename, ignored).then(() => parentPort.postMessage(['doneWork'])); +}); diff --git a/src/cli/format.js b/src/cli/format.js index d9fcc8d12913..6f918a2e0850 100644 --- a/src/cli/format.js +++ b/src/cli/format.js @@ -1,10 +1,8 @@ "use strict"; -const fs = require("fs"); const readline = require("readline"); const path = require("path"); - -const chalk = require("chalk"); +const { Worker } = require("worker_threads"); // eslint-disable-next-line no-restricted-modules const prettier = require("../index"); @@ -266,7 +264,9 @@ function formatStdin(context) { }); } -function formatFiles(context) { +const formatChunkSize = 25; + +async function formatFiles(context) { // The ignorer will be used to filter file paths after the glob is checked, // before any files are actually written const ignorer = createIgnorerFromContextOrDie(context); @@ -277,7 +277,30 @@ function formatFiles(context) { context.logger.log("Checking formatting..."); } - for (const pathOrError of expandPatterns(context)) { + const worker = new Worker(path.join(__dirname, "format-worker.js")); + + worker.on('message', data => { + switch (data[0]) { + case 'foundUnformatted': + numberOfUnformattedFilesFound++; + break; + case 'log': + context.logger[data[1]](...data[2]); + break; + case 'resetTTYLine': + readline.clearLine(process.stdout, 0); + readline.cursorTo(process.stdout, 0, null); + break; + case 'setExitCode': + process.exitCode = data[1]; + break; + case 'doneWork': + // todo + break; + } + }); + + for await (const pathOrError of expandPatterns(context)) { if (typeof pathOrError === "object") { context.logger.error(pathOrError.error); // Don't exit, but set the exit code to 2 @@ -303,104 +326,7 @@ function formatFiles(context) { continue; } - const options = { - ...getOptionsForFile(context, filename), - filepath: filename, - }; - - if (isTTY()) { - context.logger.log(filename, { newline: false }); - } - - let input; - try { - input = fs.readFileSync(filename, "utf8"); - } catch (error) { - // Add newline to split errors from filename line. - /* istanbul ignore next */ - context.logger.log(""); - - /* istanbul ignore next */ - context.logger.error( - `Unable to read file: ${filename}\n${error.message}` - ); - - // Don't exit the process if one file failed - /* istanbul ignore next */ - process.exitCode = 2; - - /* istanbul ignore next */ - continue; - } - - if (fileIgnored) { - writeOutput(context, { formatted: input }, options); - continue; - } - - const start = Date.now(); - - let result; - let output; - - try { - result = format(context, input, options); - output = result.formatted; - } catch (error) { - handleError(context, filename, error); - continue; - } - - const isDifferent = output !== input; - - if (isTTY()) { - // Remove previously printed filename to log it with duration. - readline.clearLine(process.stdout, 0); - readline.cursorTo(process.stdout, 0, null); - } - - if (context.argv.write) { - // Don't write the file if it won't change in order not to invalidate - // mtime based caches. - if (isDifferent) { - if (!context.argv.check && !context.argv["list-different"]) { - context.logger.log(`${filename} ${Date.now() - start}ms`); - } - - try { - fs.writeFileSync(filename, output, "utf8"); - } catch (error) { - /* istanbul ignore next */ - context.logger.error( - `Unable to write file: ${filename}\n${error.message}` - ); - - // Don't exit the process if one file failed - /* istanbul ignore next */ - process.exitCode = 2; - } - } else if (!context.argv.check && !context.argv["list-different"]) { - context.logger.log(`${chalk.grey(filename)} ${Date.now() - start}ms`); - } - } else if (context.argv["debug-check"]) { - /* istanbul ignore else */ - if (result.filepath) { - context.logger.log(result.filepath); - } else { - process.exitCode = 2; - } - } else if (!context.argv.check && !context.argv["list-different"]) { - writeOutput(context, result, options); - } - - if (isDifferent) { - if (context.argv.check) { - context.logger.warn(filename); - } else if (context.argv["list-different"]) { - context.logger.log(filename); - } - numberOfUnformattedFilesFound += 1; - } + worker.postMessage(pathOrError, fileIgnored); } // Print check summary based on expected exit code @@ -427,4 +353,4 @@ function formatFiles(context) { } } -module.exports = { format, formatStdin, formatFiles }; +module.exports = { format, formatStdin, formatFiles, writeOutput, handleError }; diff --git a/src/cli/index.js b/src/cli/index.js index d1517ac9f200..12358195c45a 100644 --- a/src/cli/index.js +++ b/src/cli/index.js @@ -8,12 +8,12 @@ const stringify = require("fast-json-stable-stringify"); const prettier = require("../index"); const core = require("./core"); -function run(rawArguments) { +async function run(rawArguments) { const logLevel = core.parseArgvWithoutPlugins(rawArguments, "loglevel") .loglevel; const logger = core.createLogger(logLevel); try { - main(rawArguments, logger); + await main(rawArguments, logger); } catch (error) { logger.error(error.message); process.exitCode = 1; @@ -76,7 +76,7 @@ function main(rawArguments, logger) { } else if (useStdin) { core.formatStdin(context); } else if (hasFilePatterns) { - core.formatFiles(context); + await core.formatFiles(context); } else { logger.log(core.createUsage(context)); process.exitCode = 1; diff --git a/tests_integration/__tests__/arg-parsing.js b/tests_integration/__tests__/arg-parsing.js index 70a2dab382a4..5f5aee1c3eec 100644 --- a/tests_integration/__tests__/arg-parsing.js +++ b/tests_integration/__tests__/arg-parsing.js @@ -3,8 +3,8 @@ const runPrettier = require("../runPrettier"); expect.addSnapshotSerializer(require("../path-serializer")); -describe("boolean flags do not swallow the next argument", () => { - runPrettier("cli/arg-parsing", [ +test("boolean flags do not swallow the next argument", async () => { + await runPrettier("cli/arg-parsing", [ "--end-of-line", "lf", "--single-quote", @@ -14,8 +14,8 @@ describe("boolean flags do not swallow the next argument", () => { }); }); -describe("negated options work", () => { - runPrettier("cli/arg-parsing", [ +test("negated options work", async () => { + await runPrettier("cli/arg-parsing", [ "--end-of-line", "lf", "--no-semi", @@ -25,8 +25,8 @@ describe("negated options work", () => { }); }); -describe("unknown options are warned", () => { - runPrettier("cli/arg-parsing", [ +test("unknown options are warned", async () => { + await runPrettier("cli/arg-parsing", [ "--end-of-line", "lf", "file.js", @@ -36,8 +36,8 @@ describe("unknown options are warned", () => { }); }); -describe("unknown negated options are warned", () => { - runPrettier("cli/arg-parsing", [ +test("unknown negated options are warned", async () => { + await runPrettier("cli/arg-parsing", [ "--end-of-line", "lf", "file.js", @@ -47,15 +47,15 @@ describe("unknown negated options are warned", () => { }); }); -describe("unknown options not suggestion `_`", () => { - runPrettier("cli/arg-parsing", ["file.js", "-a"]).test({ +test("unknown options not suggestion `_`", async () => { + await runPrettier("cli/arg-parsing", ["file.js", "-a"]).test({ status: 0, write: [], }); }); -describe("allow overriding flags", () => { - runPrettier( +test("allow overriding flags", async () => { + await runPrettier( "cli/arg-parsing", ["--tab-width=1", "--tab-width=3", "--parser=babel"], { input: "function a() { b }" } @@ -65,10 +65,10 @@ describe("allow overriding flags", () => { }); }); -describe("number file/dir", () => { +test("number file/dir", async () => { const patterns = ["1", "2.2", "3", "4.44"]; for (const pattern of patterns) { - runPrettier("cli/arg-parsing/number", [ + await runPrettier("cli/arg-parsing/number", [ "--parser=babel", "--list-different", pattern, @@ -78,7 +78,7 @@ describe("number file/dir", () => { write: [], }); } - runPrettier("cli/arg-parsing/number", [ + await runPrettier("cli/arg-parsing/number", [ "--parser=babel", "--list-different", ...patterns, diff --git a/tests_integration/__tests__/check.js b/tests_integration/__tests__/check.js index 87773bff4ef0..34bb638bf85e 100644 --- a/tests_integration/__tests__/check.js +++ b/tests_integration/__tests__/check.js @@ -2,8 +2,8 @@ const runPrettier = require("../runPrettier"); -describe("checks stdin with --check", () => { - runPrettier("cli/with-shebang", ["--check", "--parser", "babel"], { +test("checks stdin with --check", async () => { + await runPrettier("cli/with-shebang", ["--check", "--parser", "babel"], { input: "0", }).test({ stdout: "(stdin)\n", @@ -12,8 +12,8 @@ describe("checks stdin with --check", () => { }); }); -describe("checks stdin with -c (alias for --check)", () => { - runPrettier("cli/with-shebang", ["-c", "--parser", "babel"], { +test("checks stdin with -c (alias for --check)", async () => { + await runPrettier("cli/with-shebang", ["-c", "--parser", "babel"], { input: "0", }).test({ stdout: "(stdin)\n", @@ -22,8 +22,8 @@ describe("checks stdin with -c (alias for --check)", () => { }); }); -describe("--checks works in CI just as in a non-TTY mode", () => { - const result0 = runPrettier( +test("--checks works in CI just as in a non-TTY mode", async () => { + const result0 = await runPrettier( "cli/write", ["--check", "formatted.js", "unformatted.js"], { @@ -34,7 +34,7 @@ describe("--checks works in CI just as in a non-TTY mode", () => { status: 1, }); - const result1 = runPrettier( + const result1 = await runPrettier( "cli/write", ["--check", "formatted.js", "unformatted.js"], { diff --git a/tests_integration/__tests__/config-invalid.js b/tests_integration/__tests__/config-invalid.js index c94fbe96e3d9..ab3d0632735f 100644 --- a/tests_integration/__tests__/config-invalid.js +++ b/tests_integration/__tests__/config-invalid.js @@ -4,8 +4,8 @@ const runPrettier = require("../runPrettier"); expect.addSnapshotSerializer(require("../path-serializer")); -describe("throw error for unsupported extension", () => { - runPrettier("cli/config/invalid", [ +test("throw error for unsupported extension", async () => { + await runPrettier("cli/config/invalid", [ "--config", "file/.prettierrc.unsupported", ]).test({ @@ -13,8 +13,8 @@ describe("throw error for unsupported extension", () => { }); }); -describe("throw error with invalid config format", () => { - runPrettier("cli/config/invalid", ["--config", "file/.prettierrc"]).test({ +test("throw error with invalid config format", async () => { + await runPrettier("cli/config/invalid", ["--config", "file/.prettierrc"]).test({ status: "non-zero", stderr: expect.stringMatching( /Cannot (?:resolve|find) module '--invalid--' from/ @@ -22,8 +22,8 @@ describe("throw error with invalid config format", () => { }); }); -describe("throw error with invalid config format", () => { - runPrettier("cli/config/invalid", [ +test("throw error with invalid config format", async () => { + await runPrettier("cli/config/invalid", [ "--config", "type-error/.prettierrc", ]).test({ @@ -34,8 +34,8 @@ describe("throw error with invalid config format", () => { }); }); -describe("throw error with invalid config target (directory)", () => { - runPrettier("cli/config/invalid", [ +test("throw error with invalid config target (directory)", async () => { + await runPrettier("cli/config/invalid", [ "--config", "folder/.prettierrc", // this is a directory ]).test({ @@ -43,20 +43,20 @@ describe("throw error with invalid config target (directory)", () => { }); }); -describe("throw error with invalid config option (int)", () => { - runPrettier("cli/config/invalid", ["--config", "option/int"]).test({ +test("throw error with invalid config option (int)", async () => { + await runPrettier("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({ +test("throw error with invalid config option (trailingComma)", async () => { + await runPrettier("cli/config/invalid", ["--config", "option/trailingComma"]).test({ status: "non-zero", }); }); -describe("throw error with invalid config precedence option (configPrecedence)", () => { - runPrettier("cli/config/invalid", [ +test("throw error with invalid config precedence option (configPrecedence)", async () => { + await runPrettier("cli/config/invalid", [ "--config-precedence", "option/configPrecedence", ]).test({ @@ -64,8 +64,8 @@ describe("throw error with invalid config precedence option (configPrecedence)", }); }); -describe("resolves external configuration from package.json", () => { - runPrettier("cli/config-external-config-syntax-error", [ +test("resolves external configuration from package.json", async () => { + await runPrettier("cli/config-external-config-syntax-error", [ "syntax-error.js", ]).test({ status: 2, @@ -74,8 +74,8 @@ 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", [ +test("show warning with unknown option", async () => { + await runPrettier("cli/config/invalid", [ "--config", "option/unknown", "--parser", @@ -85,8 +85,8 @@ describe("show warning with unknown option", () => { }); }); -describe("show warning with kebab-case option key", () => { - runPrettier("cli/config/invalid", [ +test("show warning with kebab-case option key", async () => { + await runPrettier("cli/config/invalid", [ "--config", "option/kebab-case", "--parser", diff --git a/tests_integration/__tests__/config-resolution.js b/tests_integration/__tests__/config-resolution.js index e126fc0f758f..f1aac503de58 100644 --- a/tests_integration/__tests__/config-resolution.js +++ b/tests_integration/__tests__/config-resolution.js @@ -7,56 +7,56 @@ const runPrettier = require("../runPrettier"); expect.addSnapshotSerializer(require("../path-serializer")); -describe("resolves configuration from external files", () => { - runPrettier("cli/config/", ["--end-of-line", "lf", "**/*.js"]).test({ +test("resolves configuration from external files", async () => { + await runPrettier("cli/config/", ["--end-of-line", "lf", "**/*.js"]).test({ status: 0, }); }); -describe("resolves configuration from external files and overrides by extname", () => { - runPrettier("cli/config/", ["--end-of-line", "lf", "**/*.ts"]).test({ +test("resolves configuration from external files and overrides by extname", async () => { + await runPrettier("cli/config/", ["--end-of-line", "lf", "**/*.ts"]).test({ status: 0, }); }); -describe("accepts configuration from --config", () => { - runPrettier("cli/config/", ["--config", ".prettierrc", "./js/file.js"]).test({ +test("accepts configuration from --config", async () => { + await runPrettier("cli/config/", ["--config", ".prettierrc", "./js/file.js"]).test({ status: 0, }); }); -describe("resolves external configuration from package.json", () => { - runPrettier("cli/config/", ["external-config/index.js"]).test({ +test("resolves external configuration from package.json", async () => { + await runPrettier("cli/config/", ["external-config/index.js"]).test({ status: 0, }); }); -describe("resolves configuration file with --find-config-path file", () => { - runPrettier("cli/config/", ["--find-config-path", "no-config/file.js"]).test({ +test("resolves configuration file with --find-config-path file", async () => { + await runPrettier("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({ +test("resolves json configuration file with --find-config-path file", async () => { + await runPrettier("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({ +test("resolves yaml configuration file with --find-config-path file", async () => { + await runPrettier("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({ +test("resolves toml configuration file with --find-config-path file", async () => { + await runPrettier("cli/config/", ["--find-config-path", "rc-toml/file.js"]).test({ status: 0, }); }); -describe("prints nothing when no file found with --find-config-path", () => { - runPrettier("cli/config/", [ +test("prints nothing when no file found with --find-config-path", async () => { + await runPrettier("cli/config/", [ "--end-of-line", "lf", "--find-config-path", @@ -67,8 +67,8 @@ describe("prints nothing when no file found with --find-config-path", () => { }); }); -describe("CLI overrides take precedence", () => { - runPrettier("cli/config/", [ +test("CLI overrides take precedence", async () => { + await runPrettier("cli/config/", [ "--end-of-line", "lf", "--print-width", diff --git a/tests_integration/__tests__/cursor-offset.js b/tests_integration/__tests__/cursor-offset.js index 172febb45f69..efb2610ca705 100644 --- a/tests_integration/__tests__/cursor-offset.js +++ b/tests_integration/__tests__/cursor-offset.js @@ -2,16 +2,16 @@ const runPrettier = require("../runPrettier"); -describe("write cursorOffset to stderr with --cursor-offset ", () => { - runPrettier("cli", ["--cursor-offset", "2", "--parser", "babel"], { +test("write cursorOffset to stderr with --cursor-offset ", async () => { + await runPrettier("cli", ["--cursor-offset", "2", "--parser", "babel"], { input: " 1", }).test({ status: 0, }); }); -describe("cursorOffset should not be affected by full-width character", () => { - runPrettier("cli", ["--cursor-offset", "21", "--parser", "babel"], { +test("cursorOffset should not be affected by full-width character", async () => { + await runPrettier("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 0e2a63c77854..4e3f834ec5b3 100644 --- a/tests_integration/__tests__/debug-check.js +++ b/tests_integration/__tests__/debug-check.js @@ -2,16 +2,16 @@ const runPrettier = require("../runPrettier"); -describe("doesn't crash when --debug-check is passed", () => { - runPrettier("cli/with-shebang", ["issue1890.js", "--debug-check"]).test({ +test("doesn't crash when --debug-check is passed", async () => { + await runPrettier("cli/with-shebang", ["issue1890.js", "--debug-check"]).test({ stdout: "issue1890.js\n", stderr: "", status: 0, }); }); -describe("checks stdin with --debug-check", () => { - runPrettier("cli/with-shebang", ["--debug-check", "--parser", "babel"], { +test("checks stdin with --debug-check", async () => { + await runPrettier("cli/with-shebang", ["--debug-check", "--parser", "babel"], { input: "0", }).test({ stdout: "(stdin)\n", @@ -20,8 +20,8 @@ describe("checks stdin with --debug-check", () => { }); }); -describe("show diff for 2+ error files with --debug-check", () => { - runPrettier("cli/debug-check", [ +test("show diff for 2+ error files with --debug-check", async () => { + await runPrettier("cli/debug-check", [ "--end-of-line", "lf", "*.debug-check", @@ -33,8 +33,8 @@ 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", [ +test("should not exit non-zero for already prettified code with --debug-check + --check", async () => { + await runPrettier("cli/debug-check", [ "issue-4599.js", "--debug-check", "--check", @@ -43,8 +43,8 @@ describe("should not exit non-zero for already prettified code with --debug-chec }); }); -describe("should not exit non-zero for already prettified code with --debug-check + --list-different", () => { - runPrettier("cli/debug-check", [ +test("should not exit non-zero for already prettified code with --debug-check + --list-different", async () => { + await runPrettier("cli/debug-check", [ "issue-4599.js", "--debug-check", "--list-different", diff --git a/tests_integration/__tests__/debug-print-comments.js b/tests_integration/__tests__/debug-print-comments.js index 73358ce268d5..e67303aae6aa 100644 --- a/tests_integration/__tests__/debug-print-comments.js +++ b/tests_integration/__tests__/debug-print-comments.js @@ -2,8 +2,8 @@ const runPrettier = require("../runPrettier"); -describe("prints information for debugging comment attachment with --debug-print-comments", () => { - runPrettier( +test("prints information for debugging comment attachment with --debug-print-comments", async () => { + await runPrettier( "cli/with-shebang", ["--debug-print-comments", "--parser", "babel"], { input: "/* 1 */\nconsole.log(foo /* 2 */); // 3" } diff --git a/tests_integration/__tests__/debug-print-doc.js b/tests_integration/__tests__/debug-print-doc.js index aa0995cdfcb5..b7667b6ea640 100644 --- a/tests_integration/__tests__/debug-print-doc.js +++ b/tests_integration/__tests__/debug-print-doc.js @@ -2,8 +2,8 @@ const runPrettier = require("../runPrettier"); -describe("prints doc with --debug-print-doc", () => { - runPrettier("cli/with-shebang", ["--debug-print-doc", "--parser", "babel"], { +test("prints doc with --debug-print-doc", async () => { + await runPrettier("cli/with-shebang", ["--debug-print-doc", "--parser", "babel"], { input: "0", }).test({ stdout: '["0", ";", hardline]\n', diff --git a/tests_integration/__tests__/early-exit.js b/tests_integration/__tests__/early-exit.js index 7b623828afc8..3c261c03da8e 100644 --- a/tests_integration/__tests__/early-exit.js +++ b/tests_integration/__tests__/early-exit.js @@ -3,27 +3,27 @@ const prettier = require("prettier-local"); const runPrettier = require("../runPrettier"); -describe("show version with --version", () => { - runPrettier("cli/with-shebang", ["--version"]).test({ +test("show version with --version", async () => { + await runPrettier("cli/with-shebang", ["--version"]).test({ stdout: prettier.version + "\n", status: 0, }); }); -describe("show usage with --help", () => { - runPrettier("cli", ["--help"]).test({ +test("show usage with --help", async () => { + await runPrettier("cli", ["--help"]).test({ status: 0, }); }); -describe("show detailed usage with --help l (alias)", () => { - runPrettier("cli", ["--help", "l"]).test({ +test("show detailed usage with --help l (alias)", async () => { + await runPrettier("cli", ["--help", "l"]).test({ status: 0, }); }); -describe("show detailed usage with plugin options (automatic resolution)", () => { - runPrettier("plugins/automatic", [ +test("show detailed usage with plugin options (automatic resolution)", async () => { + await runPrettier("plugins/automatic", [ "--help", "tab-width", "--parser=bar", @@ -33,8 +33,8 @@ describe("show detailed usage with plugin options (automatic resolution)", () => }); }); -describe("show detailed usage with plugin options (manual resolution)", () => { - runPrettier("cli", [ +test("show detailed usage with plugin options (manual resolution)", async () => { + await runPrettier("cli", [ "--help", "tab-width", "--plugin=../plugins/automatic/node_modules/prettier-plugin-bar", @@ -44,14 +44,14 @@ describe("show detailed usage with plugin options (manual resolution)", () => { }); }); -describe("throw error with --help not-found", () => { - runPrettier("cli", ["--help", "not-found"]).test({ +test("throw error with --help not-found", async () => { + await runPrettier("cli", ["--help", "not-found"]).test({ status: 1, }); }); -describe("show warning with --help not-found (typo)", () => { - runPrettier("cli", [ +test("show warning with --help not-found (typo)", async () => { + await runPrettier("cli", [ "--help", // cspell:disable-next-line "parserr", @@ -60,44 +60,44 @@ describe("show warning with --help not-found (typo)", () => { }); }); -describe("throw error with --check + --list-different", () => { - runPrettier("cli", ["--check", "--list-different"]).test({ +test("throw error with --check + --list-different", async () => { + await runPrettier("cli", ["--check", "--list-different"]).test({ status: 1, }); }); -describe("throw error with --write + --debug-check", () => { - runPrettier("cli", ["--write", "--debug-check"]).test({ +test("throw error with --write + --debug-check", async () => { + await runPrettier("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({ +test("throw error with --find-config-path + multiple files", async () => { + await runPrettier("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({ +test("throw error with --file-info + multiple files", async () => { + await runPrettier("cli", ["--file-info", "abc.js", "def.js"]).test({ status: 1, }); }); -describe("throw error and show usage with something unexpected", () => { - runPrettier("cli", [], { isTTY: true }).test({ +test("throw error and show usage with something unexpected", async () => { + await runPrettier("cli", [], { isTTY: true }).test({ status: "non-zero", }); }); -describe("node version error", () => { +test("node version error", async () => { const originalProcessVersion = process.version; try { Object.defineProperty(process, "version", { value: "v8.0.0", writable: false, }); - runPrettier("cli", ["--help"]).test({ status: 1 }); + await runPrettier("cli", ["--help"]).test({ status: 1 }); } finally { Object.defineProperty(process, "version", { value: originalProcessVersion, diff --git a/tests_integration/__tests__/error-on-unmatched-pattern.js b/tests_integration/__tests__/error-on-unmatched-pattern.js index 102f613265e3..d4a9a70c853f 100644 --- a/tests_integration/__tests__/error-on-unmatched-pattern.js +++ b/tests_integration/__tests__/error-on-unmatched-pattern.js @@ -2,8 +2,8 @@ const runPrettier = require("../runPrettier"); -describe("no error on unmatched pattern", () => { - runPrettier("cli/error-on-unmatched-pattern", [ +test("no error on unmatched pattern", async () => { + await runPrettier("cli/error-on-unmatched-pattern", [ "--no-error-on-unmatched-pattern", "**/*.js", ]).test({ @@ -11,14 +11,14 @@ describe("no error on unmatched pattern", () => { }); }); -describe("error on unmatched pattern", () => { - runPrettier("cli/error-on-unmatched-pattern", ["**/*.toml"]).test({ +test("error on unmatched pattern", async () => { + await runPrettier("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", [ +test("no error on unmatched pattern when 2nd glob has no match", async () => { + await runPrettier("cli/error-on-unmatched-pattern", [ "--no-error-on-unmatched-pattern", "**/*.{json,js,yml}", "**/*.toml", @@ -27,8 +27,8 @@ 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", [ +test("error on unmatched pattern when 2nd glob has no match", async () => { + await runPrettier("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 22807b658bad..72fbe9b28f5f 100644 --- a/tests_integration/__tests__/file-info.js +++ b/tests_integration/__tests__/file-info.js @@ -10,38 +10,38 @@ const runPrettier = require("../runPrettier"); expect.addSnapshotSerializer(require("../path-serializer")); -describe("extracts file-info for a js file", () => { - runPrettier("cli/", ["--file-info", "something.js"]).test({ +test("extracts file-info for a js file", async () => { + await runPrettier("cli/", ["--file-info", "something.js"]).test({ status: 0, }); }); -describe("extracts file-info for a markdown file", () => { - runPrettier("cli/", ["--file-info", "README.md"]).test({ +test("extracts file-info for a markdown file", async () => { + await runPrettier("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({ +test("extracts file-info for a known markdown file with no extension", async () => { + await runPrettier("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({ +test("extracts file-info with ignored=true for a file in .prettierignore", async () => { + await runPrettier("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({ +test("file-info should try resolve config", async () => { + await runPrettier("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/", [ +test("file-info should not try resolve config with --no-config", async () => { + await runPrettier("cli/with-resolve-config/", [ "--file-info", "file.js", "--no-config", @@ -52,8 +52,8 @@ 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/", [ +test("extracts file-info with ignored=true for a file in a hand-picked .prettierignore", async () => { + await runPrettier("cli/", [ "--file-info", "regular-module.js", "--ignore-path=ignore-path/.prettierignore", @@ -62,8 +62,8 @@ describe("extracts file-info with ignored=true for a file in a hand-picked .pret }); }); -describe("non-exists ignore path", () => { - runPrettier("cli/", [ +test("non-exists ignore path", async () => { + await runPrettier("cli/", [ "--file-info", "regular-module.js", "--ignore-path=ignore-path/non-exists/.prettierignore", @@ -72,8 +72,8 @@ describe("non-exists ignore path", () => { }); }); -describe("extracts file-info for a file in not_node_modules", () => { - runPrettier("cli/with-node-modules/", [ +test("extracts file-info for a file in not_node_modules", async () => { + await runPrettier("cli/with-node-modules/", [ "--file-info", "not_node_modules/file.js", ]).test({ @@ -81,8 +81,8 @@ 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/", [ +test("extracts file-info with with ignored=true for a file in node_modules", async () => { + await runPrettier("cli/with-node-modules/", [ "--file-info", "node_modules/file.js", ]).test({ @@ -90,8 +90,8 @@ 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/", [ +test("extracts file-info with ignored=false for a file in node_modules when --with-node-modules provided", async () => { + await runPrettier("cli/with-node-modules/", [ "--file-info", "node_modules/file.js", "--with-node-modules", @@ -100,20 +100,20 @@ 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({ +test("extracts file-info with inferredParser=null for file.foo", async () => { + await runPrettier("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({ +test("extracts file-info with inferredParser=foo when plugins are autoloaded", async () => { + await runPrettier("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/", [ +test("extracts file-info with inferredParser=foo when plugins are loaded with --plugin-search-dir", async () => { + await runPrettier("cli/", [ "--file-info", "file.foo", "--plugin-search-dir", @@ -123,8 +123,8 @@ 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/", [ +test("extracts file-info with inferredParser=foo when a plugin is hand-picked", async () => { + await runPrettier("cli/", [ "--file-info", "file.foo", "--plugin", diff --git a/tests_integration/__tests__/help-options.js b/tests_integration/__tests__/help-options.js index a4db9f040522..9a232e7b4fb1 100644 --- a/tests_integration/__tests__/help-options.js +++ b/tests_integration/__tests__/help-options.js @@ -25,8 +25,8 @@ for (const option of arrayify( ].filter(Boolean); for (const optionName of optionNames) { - describe(`show detailed usage with --help ${optionName}`, () => { - runPrettier("cli", ["--help", optionName]).test({ + test(`show detailed usage with --help ${optionName}`, async () => { + await runPrettier("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 5a7bdd6a6142..f573aadb29a5 100644 --- a/tests_integration/__tests__/ignore-absolute-path.js +++ b/tests_integration/__tests__/ignore-absolute-path.js @@ -3,8 +3,8 @@ const path = require("path"); const runPrettier = require("../runPrettier"); -describe("support absolute filename", () => { - runPrettier("cli/ignore-absolute-path", [ +test("support absolute filename", async () => { + await runPrettier("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 db25350a37cb..f96d8c5ce4b0 100644 --- a/tests_integration/__tests__/ignore-emoji.js +++ b/tests_integration/__tests__/ignore-emoji.js @@ -4,14 +4,14 @@ const runPrettier = require("../runPrettier"); expect.addSnapshotSerializer(require("../path-serializer")); -describe("ignores file name contains emoji", () => { - runPrettier("cli/ignore-emoji", ["**/*.js", "-l"]).test({ +test("ignores file name contains emoji", async () => { + await runPrettier("cli/ignore-emoji", ["**/*.js", "-l"]).test({ status: 1, }); }); -describe("stdin", () => { - runPrettier( +test("stdin", async () => { + await runPrettier( "cli/ignore-emoji", ["--stdin-filepath", "ignored/我的样式.css"], { input: ".name { display: none; }" } diff --git a/tests_integration/__tests__/ignore-in-subdirectories.js b/tests_integration/__tests__/ignore-in-subdirectories.js index 4b67ffb02163..6683336f1393 100644 --- a/tests_integration/__tests__/ignore-in-subdirectories.js +++ b/tests_integration/__tests__/ignore-in-subdirectories.js @@ -4,8 +4,8 @@ const runPrettier = require("../runPrettier"); expect.addSnapshotSerializer(require("../path-serializer")); -describe("ignores files when executing in a subdirectory", () => { - runPrettier("cli/ignore-in-subdirectories/web1", [ +test("ignores files when executing in a subdirectory", async () => { + await runPrettier("cli/ignore-in-subdirectories/web1", [ "ignore-me/should-ignore.js", "--ignore-path", "../.prettierignore", @@ -14,7 +14,7 @@ describe("ignores files when executing in a subdirectory", () => { status: 0, }); - runPrettier("cli/ignore-in-subdirectories/web1", [ + await runPrettier("cli/ignore-in-subdirectories/web1", [ "ignore-me/subdirectory/should-ignore.js", "--ignore-path", "../.prettierignore", @@ -24,8 +24,8 @@ describe("ignores files when executing in a subdirectory", () => { }); }); -describe("formats files when executing in a subdirectory", () => { - runPrettier("cli/ignore-in-subdirectories/web1", [ +test("formats files when executing in a subdirectory", async () => { + await runPrettier("cli/ignore-in-subdirectories/web1", [ "should-not-ignore.js", "--ignore-path", "../.prettierignore", @@ -34,7 +34,7 @@ describe("formats files when executing in a subdirectory", () => { status: 1, }); - runPrettier("cli/ignore-in-subdirectories/web2", [ + await runPrettier("cli/ignore-in-subdirectories/web2", [ "should-not-ignore.js", "--ignore-path", "../.prettierignore", @@ -44,8 +44,8 @@ describe("formats files when executing in a subdirectory", () => { }); }); -describe("ignore files when executing in a subdirectory and using stdin", () => { - runPrettier( +test("ignore files when executing in a subdirectory and using stdin", async () => { + await runPrettier( "cli/ignore-in-subdirectories/web1", [ "--ignore-path", @@ -62,8 +62,8 @@ describe("ignore files when executing in a subdirectory and using stdin", () => }); }); -describe("formats files when executing in a subdirectory and using stdin", () => { - runPrettier( +test("formats files when executing in a subdirectory and using stdin", async () => { + await runPrettier( "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 0ff89da833bc..827e87258e1a 100644 --- a/tests_integration/__tests__/ignore-path.js +++ b/tests_integration/__tests__/ignore-path.js @@ -2,8 +2,8 @@ const runPrettier = require("../runPrettier"); -describe("ignore path", () => { - runPrettier("cli/ignore-path", [ +test("ignore path", async () => { + await runPrettier("cli/ignore-path", [ "**/*.js", "--ignore-path", ".gitignore", @@ -13,20 +13,20 @@ describe("ignore path", () => { }); }); -describe("support .prettierignore", () => { - runPrettier("cli/ignore-path", ["**/*.js", "-l"]).test({ +test("support .prettierignore", async () => { + await runPrettier("cli/ignore-path", ["**/*.js", "-l"]).test({ status: 1, }); }); -describe("ignore file when using --debug-check", () => { - runPrettier("cli/ignore-path", ["**/*.js", "--debug-check"]).test({ +test("ignore file when using --debug-check", async () => { + await runPrettier("cli/ignore-path", ["**/*.js", "--debug-check"]).test({ status: 0, }); }); -describe("outputs files as-is if no --write", () => { - runPrettier("cli/ignore-path", ["regular-module.js"], { +test("outputs files as-is if no --write", async () => { + await runPrettier("cli/ignore-path", ["regular-module.js"], { ignoreLineEndings: true, }).test({ status: 0, diff --git a/tests_integration/__tests__/ignore-relative-path.js b/tests_integration/__tests__/ignore-relative-path.js index d48bd0b5d35d..78a821f3ea30 100644 --- a/tests_integration/__tests__/ignore-relative-path.js +++ b/tests_integration/__tests__/ignore-relative-path.js @@ -4,8 +4,8 @@ const runPrettier = require("../runPrettier"); expect.addSnapshotSerializer(require("../path-serializer")); -describe("support relative paths", () => { - runPrettier("cli/ignore-relative-path", [ +test("support relative paths", async () => { + await runPrettier("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 01b5581e23d3..fad187c3a7b2 100644 --- a/tests_integration/__tests__/ignore-unknown.js +++ b/tests_integration/__tests__/ignore-unknown.js @@ -2,8 +2,8 @@ const runPrettier = require("../runPrettier"); -describe("ignore-unknown dir", () => { - runPrettier("cli/ignore-unknown", [ +test("ignore-unknown dir", async () => { + await runPrettier("cli/ignore-unknown", [ ".", "--ignore-unknown", "--list-different", @@ -14,16 +14,16 @@ describe("ignore-unknown dir", () => { }); }); -describe("ignore-unknown alias", () => { - runPrettier("cli/ignore-unknown", [".", "-u", "--list-different"]).test({ +test("ignore-unknown alias", async () => { + await runPrettier("cli/ignore-unknown", [".", "-u", "--list-different"]).test({ status: "non-zero", stderr: "", write: [], }); }); -describe("ignore-unknown pattern", () => { - runPrettier("cli/ignore-unknown", [ +test("ignore-unknown pattern", async () => { + await runPrettier("cli/ignore-unknown", [ "*", "--ignore-unknown", "--list-different", @@ -34,8 +34,8 @@ describe("ignore-unknown pattern", () => { }); }); -describe("ignore-unknown write", () => { - runPrettier("cli/ignore-unknown", [ +test("ignore-unknown write", async () => { + await runPrettier("cli/ignore-unknown", [ ".", "--ignore-unknown", "--write", @@ -46,14 +46,14 @@ describe("ignore-unknown write", () => { }); }); -describe("ignore-unknown check", () => { - runPrettier("cli/ignore-unknown", [".", "--ignore-unknown", "--check"]).test({ +test("ignore-unknown check", async () => { + await runPrettier("cli/ignore-unknown", [".", "--ignore-unknown", "--check"]).test({ status: 1, }); }); -describe("None exist file", () => { - runPrettier("cli/ignore-unknown", [ +test("None exist file", async () => { + await runPrettier("cli/ignore-unknown", [ "non-exist-file", "--ignore-unknown", ]).test({ @@ -61,8 +61,8 @@ describe("None exist file", () => { }); }); -describe("Not matching pattern", () => { - runPrettier("cli/ignore-unknown", [ +test("Not matching pattern", async () => { + await runPrettier("cli/ignore-unknown", [ "*.non-exist-pattern", "--ignore-unknown", ]).test({ @@ -70,8 +70,8 @@ describe("Not matching pattern", () => { }); }); -describe("Ignored file", () => { - runPrettier("cli/ignore-unknown", ["ignored.js", "--ignore-unknown"]).test({ +test("Ignored file", async () => { + await runPrettier("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 064af6ec58d2..eb29963f2725 100644 --- a/tests_integration/__tests__/ignore-vcs-files.js +++ b/tests_integration/__tests__/ignore-vcs-files.js @@ -4,8 +4,8 @@ const runPrettier = require("../runPrettier"); expect.addSnapshotSerializer(require("../path-serializer")); -describe("ignores files in version control systems", () => { - runPrettier("cli/ignore-vcs-files", [ +test("ignores files in version control systems", async () => { + await runPrettier("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 5e27a6b09f84..35ea4714369c 100644 --- a/tests_integration/__tests__/infer-parser.js +++ b/tests_integration/__tests__/infer-parser.js @@ -4,16 +4,16 @@ const prettier = require("prettier-local"); const runPrettier = require("../runPrettier"); describe("stdin no path and no parser", () => { - describe("logs error and exits with 2", () => { - runPrettier("cli/infer-parser/", [], { input: "foo" }).test({ + test("logs error and exits with 2", async () => { + await runPrettier("cli/infer-parser/", [], { input: "foo" }).test({ status: 2, stdout: "", write: [], }); }); - describe("--check logs error but exits with 0", () => { - runPrettier("cli/infer-parser/", ["--check"], { + test("--check logs error but exits with 0", async () => { + await runPrettier("cli/infer-parser/", ["--check"], { input: "foo", }).test({ status: 0, @@ -22,8 +22,8 @@ describe("stdin no path and no parser", () => { }); }); - describe("--list-different logs error but exits with 0", () => { - runPrettier("cli/infer-parser/", ["--list-different"], { + test("--list-different logs error but exits with 0", async () => { + await runPrettier("cli/infer-parser/", ["--list-different"], { input: "foo", }).test({ status: 0, @@ -34,8 +34,8 @@ 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"], { + test("logs error and exits with 2", async () => { + await runPrettier("cli/infer-parser/", ["--stdin-filepath", "foo"], { input: "foo", }).test({ status: 2, @@ -44,8 +44,8 @@ describe("stdin with unknown path and no parser", () => { }); }); - describe("--check logs error but exits with 0", () => { - runPrettier("cli/infer-parser/", ["--check", "--stdin-filepath", "foo"], { + test("--check logs error but exits with 0", async () => { + await runPrettier("cli/infer-parser/", ["--check", "--stdin-filepath", "foo"], { input: "foo", }).test({ status: 0, @@ -54,8 +54,8 @@ describe("stdin with unknown path and no parser", () => { }); }); - describe("--list-different logs error but exits with 0", () => { - runPrettier( + test("--list-different logs error but exits with 0", async () => { + await runPrettier( "cli/infer-parser/", ["--list-different", "--stdin-filepath", "foo"], { input: "foo" } @@ -68,16 +68,16 @@ 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({ + test("specific file", async () => { + await runPrettier("cli/infer-parser/", ["--end-of-line", "lf", "FOO"]).test({ status: 2, stdout: "", write: [], }); }); - describe("multiple files", () => { - runPrettier("cli/infer-parser/", ["--end-of-line", "lf", "*"]).test({ + test("multiple files", async () => { + await runPrettier("cli/infer-parser/", ["--end-of-line", "lf", "*"]).test({ status: 2, write: [], }); @@ -85,15 +85,15 @@ describe("unknown path and no parser", () => { }); describe("--check with unknown path and no parser", () => { - describe("specific file", () => { - runPrettier("cli/infer-parser/", ["--check", "FOO"]).test({ + test("specific file", async () => { + await runPrettier("cli/infer-parser/", ["--check", "FOO"]).test({ status: 0, write: [], }); }); - describe("multiple files", () => { - runPrettier("cli/infer-parser/", ["--check", "*"]).test({ + test("multiple files", async () => { + await runPrettier("cli/infer-parser/", ["--check", "*"]).test({ status: 1, write: [], }); @@ -101,16 +101,16 @@ 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({ + test("specific file", async () => { + await runPrettier("cli/infer-parser/", ["--list-different", "FOO"]).test({ status: 0, stdout: "", write: [], }); }); - describe("multiple files", () => { - runPrettier("cli/infer-parser/", ["--list-different", "*"]).test({ + test("multiple files", async () => { + await runPrettier("cli/infer-parser/", ["--list-different", "*"]).test({ status: 1, stdout: "foo.js\n", write: [], @@ -119,39 +119,39 @@ 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({ + test("specific file", async () => { + await runPrettier("cli/infer-parser/", ["--write", "FOO"]).test({ status: 2, stdout: "", write: [], }); }); - describe("multiple files", () => { - runPrettier("cli/infer-parser/", ["--write", "*"]).test({ + test("multiple files", async () => { + await runPrettier("cli/infer-parser/", ["--write", "*"]).test({ status: 2, }); }); }); describe("--write and --check with unknown path and no parser", () => { - describe("specific file", () => { - runPrettier("cli/infer-parser/", ["--check", "--write", "FOO"]).test({ + test("specific file", async () => { + await runPrettier("cli/infer-parser/", ["--check", "--write", "FOO"]).test({ status: 0, write: [], }); }); - describe("multiple files", () => { - runPrettier("cli/infer-parser/", ["--check", "--write", "*"]).test({ + test("multiple files", async () => { + await runPrettier("cli/infer-parser/", ["--check", "--write", "*"]).test({ status: 0, }); }); }); describe("--write and --list-different with unknown path and no parser", () => { - describe("specific file", () => { - runPrettier("cli/infer-parser/", [ + test("specific file", async () => { + await runPrettier("cli/infer-parser/", [ "--list-different", "--write", "FOO", @@ -162,8 +162,8 @@ describe("--write and --list-different with unknown path and no parser", () => { }); }); - describe("multiple files", () => { - runPrettier("cli/infer-parser/", [ + test("multiple files", async () => { + await runPrettier("cli/infer-parser/", [ "--list-different", "--write", "*", @@ -195,8 +195,8 @@ describe("API with no path and no parser", () => { }); }); -describe("Known/Unknown", () => { - runPrettier("cli/infer-parser/known-unknown", [ +test("Known/Unknown", async () => { + await runPrettier("cli/infer-parser/known-unknown", [ "--end-of-line", "lf", "--list-different", diff --git a/tests_integration/__tests__/invalid-ignore.js b/tests_integration/__tests__/invalid-ignore.js index e7f7aa869daa..25f5f6bdb743 100644 --- a/tests_integration/__tests__/invalid-ignore.js +++ b/tests_integration/__tests__/invalid-ignore.js @@ -6,8 +6,8 @@ const runPrettier = require("../runPrettier"); expect.addSnapshotSerializer(require("../path-serializer")); -describe("throw error with invalid ignore", () => { - runPrettier("cli/invalid-ignore", ["something.js"]).test({ +test("throw error with invalid ignore", async () => { + await runPrettier("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 2774d6a865f1..9e0a583b7560 100644 --- a/tests_integration/__tests__/list-different.js +++ b/tests_integration/__tests__/list-different.js @@ -2,8 +2,8 @@ const runPrettier = require("../runPrettier"); -describe("checks stdin with --list-different", () => { - runPrettier("cli/with-shebang", ["--list-different", "--parser", "babel"], { +test("checks stdin with --list-different", async () => { + await runPrettier("cli/with-shebang", ["--list-different", "--parser", "babel"], { input: "0", }).test({ stdout: "(stdin)\n", @@ -12,8 +12,8 @@ describe("checks stdin with --list-different", () => { }); }); -describe("checks stdin with -l (alias for --list-different)", () => { - runPrettier("cli/with-shebang", ["-l", "--parser", "babel"], { +test("checks stdin with -l (alias for --list-different)", async () => { + await runPrettier("cli/with-shebang", ["-l", "--parser", "babel"], { input: "0", }).test({ stdout: "(stdin)\n", @@ -22,8 +22,8 @@ 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( +test("--list-different works in CI just as in a non-TTY mode", async () => { + const result0 = await runPrettier( "cli/write", ["--list-different", "formatted.js", "unformatted.js"], { @@ -34,7 +34,7 @@ describe("--list-different works in CI just as in a non-TTY mode", () => { status: 1, }); - const result1 = runPrettier( + const result1 = await runPrettier( "cli/write", ["--list-different", "formatted.js", "unformatted.js"], { diff --git a/tests_integration/__tests__/loglevel.js b/tests_integration/__tests__/loglevel.js index 04b32154ae83..b88b48fa8a17 100644 --- a/tests_integration/__tests__/loglevel.js +++ b/tests_integration/__tests__/loglevel.js @@ -3,24 +3,24 @@ const stripAnsi = require("strip-ansi"); const runPrettier = require("../runPrettier"); -test("do not show logs with --loglevel silent", () => { - runPrettierWithLogLevel("silent", null); +test("do not show logs with --loglevel silent", async () => { + await runPrettierWithLogLevel("silent", null); }); -test("do not show warnings with --loglevel error", () => { - runPrettierWithLogLevel("error", ["[error]"]); +test("do not show warnings with --loglevel error", async () => { + await runPrettierWithLogLevel("error", ["[error]"]); }); -test("show errors and warnings with --loglevel warn", () => { - runPrettierWithLogLevel("warn", ["[error]", "[warn]"]); +test("show errors and warnings with --loglevel warn", async () => { + await runPrettierWithLogLevel("warn", ["[error]", "[warn]"]); }); -test("show all logs with --loglevel debug", () => { - runPrettierWithLogLevel("debug", ["[error]", "[warn]", "[debug]"]); +test("show all logs with --loglevel debug", async () => { + await runPrettierWithLogLevel("debug", ["[error]", "[warn]", "[debug]"]); }); -describe("--write with --loglevel=silent doesn't log filenames", () => { - runPrettier("cli/write", [ +test("--write with --loglevel=silent doesn't log filenames", async () => { + await runPrettier("cli/write", [ "--write", "unformatted.js", "--loglevel=silent", @@ -29,7 +29,7 @@ describe("--write with --loglevel=silent doesn't log filenames", () => { }); }); -function runPrettierWithLogLevel(logLevel, patterns) { +async function runPrettierWithLogLevel(logLevel, patterns) { const result = runPrettier("cli/loglevel", [ "--loglevel", logLevel, @@ -39,9 +39,9 @@ function runPrettierWithLogLevel(logLevel, patterns) { "not-found.js", ]); - expect(result.status).toEqual(2); + expect(await result.status).toEqual(2); - const stderr = stripAnsi(result.stderr); + const stderr = stripAnsi(await result.stderr); if (patterns) { for (const pattern of patterns) { diff --git a/tests_integration/__tests__/parser-api.js b/tests_integration/__tests__/parser-api.js index e790caa8e54b..9ea65180d00d 100644 --- a/tests_integration/__tests__/parser-api.js +++ b/tests_integration/__tests__/parser-api.js @@ -29,8 +29,8 @@ test("allows usage of prettier's supported parsers", () => { expect(output).toEqual("bar();\n"); }); -describe("allows passing a string to resolve a parser", () => { - runPrettier("./custom-parsers/", [ +test("allows passing a string to resolve a parser", async () => { + await runPrettier("./custom-parsers/", [ "--end-of-line", "lf", "./custom-rename-input.js", diff --git a/tests_integration/__tests__/patterns-dirs.js b/tests_integration/__tests__/patterns-dirs.js index ebea3c3620db..8b6ea4828a64 100644 --- a/tests_integration/__tests__/patterns-dirs.js +++ b/tests_integration/__tests__/patterns-dirs.js @@ -63,8 +63,8 @@ const uppercaseRocksPlugin = path.join( projectRoot, "tests_config/prettier-plugins/prettier-plugin-uppercase-rocks" ); -describe("plugins `.`", () => { - runPrettier("cli/dirs/plugins", [ +test("plugins `.`", async () => { + await runPrettier("cli/dirs/plugins", [ ".", "-l", "--plugin", @@ -75,8 +75,8 @@ describe("plugins `.`", () => { status: 1, }); }); -describe("plugins `*`", () => { - runPrettier("cli/dirs/plugins", [ +test("plugins `*`", async () => { + await runPrettier("cli/dirs/plugins", [ "*", "-l", "--plugin", @@ -127,8 +127,8 @@ function testPatterns(namePrefix, cliArgs, expected = {}) { .map((arg) => (/^[\w./=-]+$/.test(arg) ? arg : `'${arg}'`)) .join(" "); - describe(testName, () => { - runPrettier("cli/patterns-dirs", [...cliArgs, "-l"]).test({ + test(testName, async () => { + await runPrettier("cli/patterns-dirs", [...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 34506c0b231c..91870a19ff59 100644 --- a/tests_integration/__tests__/patterns-glob.js +++ b/tests_integration/__tests__/patterns-glob.js @@ -11,14 +11,14 @@ fixtures-1/ └─ b.js */ -describe("fixtures-1: Should match all files", () => { - runPrettier("cli/patterns-glob/fixtures-1", ["*.js", "!file.js", "-l"]).test({ +test("fixtures-1: Should match all files", async () => { + await runPrettier("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({ +test("fixtures-1: Should match files except `a.js`", async () => { + await runPrettier("cli/patterns-glob/fixtures-1", ["*.js", "!a.js", "-l"]).test({ status: 1, }); }); @@ -32,20 +32,20 @@ fixtures-2/ └─ 2.css */ -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({ +test("fixtures-2: Should match all js files and all supported files in the '!dir.js' directory", async () => { + await runPrettier("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({ +test("fixtures-2: Should match `a.js` and `!b.js`", async () => { + await runPrettier("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({ +test("fixtures-2: Should only match `!b.js`", async () => { + await runPrettier("cli/patterns-glob/fixtures-2", ["*.js", "!a.js", "-l"]).test({ status: 1, }); }); @@ -61,8 +61,8 @@ fixtures-3/ └─in-svn.js */ -describe("fixtures-3: Should match `outside.js`, `dir/inside.js` and `dir/node_modules/in-node_modules.js`", () => { - runPrettier("cli/patterns-glob/fixtures-3", [ +test("fixtures-3: Should match `outside.js`, `dir/inside.js` and `dir/node_modules/in-node_modules.js`", async () => { + await runPrettier("cli/patterns-glob/fixtures-3", [ "**/*.js", "-l", "--with-node-modules", @@ -71,15 +71,15 @@ 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({ +test("fixtures-3: Should only match `outside.js` and `dir/inside.js`", async () => { + await runPrettier("cli/patterns-glob/fixtures-3", ["**/*.js", "-l"]).test({ status: 1, }); }); describe("fixtures-3: Should exclude `.svn`", () => { - describe("(existing)", () => { - runPrettier("cli/patterns-glob/fixtures-3", [ + test("(existing)", async () => { + await runPrettier("cli/patterns-glob/fixtures-3", [ "*.js", "dir/.svn/in-svn.js", "-l", @@ -88,8 +88,8 @@ describe("fixtures-3: Should exclude `.svn`", () => { }); }); - describe("(nonexisting)", () => { - runPrettier("cli/patterns-glob/fixtures-3", [ + test("(nonexisting)", async () => { + await runPrettier("cli/patterns-glob/fixtures-3", [ "*.js", ".svn/in-svn.js", "-l", @@ -110,14 +110,14 @@ fixtures-4/ └─ level-3.js */ -describe("fixtures-4: Should match `level-1.js`", () => { - runPrettier("cli/patterns-glob/fixtures-4", ["./0/./level-1.js", "-l"]).test({ +test("fixtures-4: Should match `level-1.js`", async () => { + await runPrettier("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", [ +test("fixtures-4: Should match `level-1.js` #2", async () => { + await runPrettier("cli/patterns-glob/fixtures-4", [ "./0/1/2/../../level-1.js", "-l", ]).test({ @@ -125,8 +125,8 @@ describe("fixtures-4: Should match `level-1.js` #2", () => { }); }); -describe("fixtures-4: Should match `level-1.js` #3", () => { - runPrettier("cli/patterns-glob/fixtures-4", [ +test("fixtures-4: Should match `level-1.js` #3", async () => { + await runPrettier("cli/patterns-glob/fixtures-4", [ "./0/non-exists-dir/2/../../level-1.js", "-l", ]).test({ diff --git a/tests_integration/__tests__/patterns.js b/tests_integration/__tests__/patterns.js index 807f190c8c52..824fecc750ce 100644 --- a/tests_integration/__tests__/patterns.js +++ b/tests_integration/__tests__/patterns.js @@ -4,8 +4,8 @@ const runPrettier = require("../runPrettier"); expect.addSnapshotSerializer(require("../path-serializer")); -describe("multiple patterns", () => { - runPrettier("cli/patterns", [ +test("multiple patterns", async () => { + await runPrettier("cli/patterns", [ "directory/**/*.js", "other-directory/**/*.js", "-l", @@ -14,8 +14,8 @@ describe("multiple patterns", () => { }); }); -describe("multiple patterns with non exists pattern", () => { - runPrettier("cli/patterns", [ +test("multiple patterns with non exists pattern", async () => { + await runPrettier("cli/patterns", [ "directory/**/*.js", "non-existent.js", "-l", @@ -24,8 +24,8 @@ describe("multiple patterns with non exists pattern", () => { }); }); -describe("multiple patterns with ignore nested directories pattern", () => { - runPrettier("cli/patterns", [ +test("multiple patterns with ignore nested directories pattern", async () => { + await runPrettier("cli/patterns", [ "**/*.js", "!**/nested-directory/**", "-l", @@ -34,20 +34,20 @@ describe("multiple patterns with ignore nested directories pattern", () => { }); }); -describe("multiple patterns by with ignore pattern, ignores node_modules by default", () => { - runPrettier("cli/patterns", ["**/*.js", "!directory/**", "-l"]).test({ +test("multiple patterns by with ignore pattern, ignores node_modules by default", async () => { + await runPrettier("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({ +test("multiple patterns by with ignore pattern, ignores node_modules by with ./**/*.js", async () => { + await runPrettier("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", [ +test("multiple patterns by with ignore pattern, doesn't ignore node_modules with --with-node-modules flag", async () => { + await runPrettier("cli/patterns", [ "**/*.js", "!directory/**", "-l", @@ -57,15 +57,15 @@ describe("multiple patterns by with ignore pattern, doesn't ignore node_modules }); }); -describe("no errors on empty patterns", () => { +test("no errors on empty patterns", async () => { // --parser is mandatory if no filepath is passed - runPrettier("cli/patterns", ["--parser", "babel"]).test({ + await runPrettier("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", [ +test("multiple patterns, throw error and exit with non zero code on non existing files", async () => { + await runPrettier("cli/patterns", [ "non-existent.js", "other-non-existent.js", "-l", diff --git a/tests_integration/__tests__/piped-output.js b/tests_integration/__tests__/piped-output.js index 173cd72e1357..a1746dcd589e 100644 --- a/tests_integration/__tests__/piped-output.js +++ b/tests_integration/__tests__/piped-output.js @@ -2,8 +2,8 @@ const runPrettier = require("../runPrettier"); -describe("output with --check + unformatted differs when piped", () => { - const result0 = runPrettier( +test("output with --check + unformatted differs when piped", async () => { + const result0 = await runPrettier( "cli/write", ["--write", "--check", "--no-color", "unformatted.js"], { stdoutIsTTY: true } @@ -11,7 +11,7 @@ describe("output with --check + unformatted differs when piped", () => { status: 0, }); - const result1 = runPrettier( + const result1 = await runPrettier( "cli/write", ["--write", "--check", "--no-color", "unformatted.js"], { stdoutIsTTY: false } @@ -23,8 +23,8 @@ describe("output with --check + unformatted differs when piped", () => { expect(result0.write).toEqual(result1.write); }); -describe("no file diffs with --check + formatted file", () => { - const result0 = runPrettier( +test("no file diffs with --check + formatted file", async () => { + const result0 = await runPrettier( "cli/write", ["--write", "--check", "--no-color", "formatted.js"], { stdoutIsTTY: true } @@ -32,7 +32,7 @@ describe("no file diffs with --check + formatted file", () => { status: 0, }); - const result1 = runPrettier( + const result1 = await runPrettier( "cli/write", ["--write", "--check", "--no-color", "formatted.js"], { stdoutIsTTY: false } @@ -45,8 +45,8 @@ describe("no file diffs with --check + formatted file", () => { expect(result0.write).toEqual(result1.write); }); -describe("output with --list-different + unformatted differs when piped", () => { - const result0 = runPrettier( +test("output with --list-different + unformatted differs when piped", async () => { + const result0 = await runPrettier( "cli/write", ["--write", "--list-different", "--no-color", "unformatted.js"], { stdoutIsTTY: true } @@ -54,7 +54,7 @@ describe("output with --list-different + unformatted differs when piped", () => status: 0, }); - const result1 = runPrettier( + const result1 = await runPrettier( "cli/write", ["--write", "--list-different", "--no-color", "unformatted.js"], { stdoutIsTTY: false } @@ -66,8 +66,8 @@ describe("output with --list-different + unformatted differs when piped", () => expect(result0.write).toEqual(result1.write); }); -describe("no file diffs with --list-different + formatted file", () => { - const result0 = runPrettier( +test("no file diffs with --list-different + formatted file", async () => { + const result0 = await runPrettier( "cli/write", ["--write", "--list-different", "--no-color", "formatted.js"], { stdoutIsTTY: true } @@ -75,7 +75,7 @@ describe("no file diffs with --list-different + formatted file", () => { status: 0, }); - const result1 = runPrettier( + const result1 = await runPrettier( "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 b0a3f24b9f63..dca5b087cec8 100644 --- a/tests_integration/__tests__/plugin-default-options.js +++ b/tests_integration/__tests__/plugin-default-options.js @@ -2,8 +2,8 @@ const runPrettier = require("../runPrettier"); -describe("plugin default options should work", () => { - runPrettier( +test("plugin default options should work", async () => { + await runPrettier( "plugins/defaultOptions", [ "--stdin-filepath", @@ -23,8 +23,8 @@ describe("plugin default options should work", () => { }); }); -describe("overriding plugin default options should work", () => { - runPrettier( +test("overriding plugin default options should work", async () => { + await runPrettier( "plugins/defaultOptions", ["--stdin-filepath", "example.foo", "--plugin=./plugin", "--tab-width=4"], { input: "hello-world" } diff --git a/tests_integration/__tests__/plugin-extensions.js b/tests_integration/__tests__/plugin-extensions.js index 26843f1b3123..d55cf1398eba 100644 --- a/tests_integration/__tests__/plugin-extensions.js +++ b/tests_integration/__tests__/plugin-extensions.js @@ -3,8 +3,8 @@ const runPrettier = require("../runPrettier"); const EOL = "\n"; -describe("uses 'extensions' from languages to determine parser", () => { - runPrettier("plugins/extensions", ["*.foo", "--plugin=./plugin"], { +test("uses 'extensions' from languages to determine parser", async () => { + await runPrettier("plugins/extensions", ["*.foo", "--plugin=./plugin"], { ignoreLineEndings: true, }).test({ stdout: "!contents" + EOL, diff --git a/tests_integration/__tests__/plugin-flush-line-suffix.js b/tests_integration/__tests__/plugin-flush-line-suffix.js index e60ab5adb25c..1b855a1c6be4 100644 --- a/tests_integration/__tests__/plugin-flush-line-suffix.js +++ b/tests_integration/__tests__/plugin-flush-line-suffix.js @@ -2,8 +2,8 @@ const runPrettier = require("../runPrettier"); -describe("flush all line-suffix content", () => { - runPrettier("plugins/flushLineSuffix", ["*.foo", "--plugin=./plugin"], { +test("flush all line-suffix content", async () => { + await runPrettier("plugins/flushLineSuffix", ["*.foo", "--plugin=./plugin"], { ignoreLineEndings: true, }).test({ stdout: "contents", diff --git a/tests_integration/__tests__/plugin-options-string.js b/tests_integration/__tests__/plugin-options-string.js index 96e3008fa6c9..81611da3ef17 100644 --- a/tests_integration/__tests__/plugin-options-string.js +++ b/tests_integration/__tests__/plugin-options-string.js @@ -3,18 +3,18 @@ const snapshotDiff = require("snapshot-diff"); const runPrettier = require("../runPrettier"); -describe("show external options with `--help`", () => { - const originalStdout = runPrettier("plugins/options-string", ["--help"]) +test("show external options with `--help`", async () => { + const originalStdout = await runPrettier("plugins/options-string", ["--help"]) .stdout; - const pluggedStdout = runPrettier("plugins/options-string", [ + const pluggedStdout = await runPrettier("plugins/options-string", [ "--help", "--plugin=./plugin", ]).stdout; expect(snapshotDiff(originalStdout, pluggedStdout)).toMatchSnapshot(); }); -describe("show detailed external option with `--help foo-string`", () => { - runPrettier("plugins/options-string", [ +test("show detailed external option with `--help foo-string`", async () => { + await runPrettier("plugins/options-string", [ "--plugin=./plugin", "--help", "foo-string", @@ -23,8 +23,8 @@ describe("show detailed external option with `--help foo-string`", () => { }); }); -describe("external options from CLI should work", () => { - runPrettier( +test("external options from CLI should work", async () => { + await runPrettier( "plugins/options-string", [ "--plugin=./plugin", @@ -42,8 +42,8 @@ describe("external options from CLI should work", () => { }); }); -describe("external options from config file should work", () => { - runPrettier( +test("external options from config file should work", async () => { + await runPrettier( "plugins/options-string", ["--config=./config.json", "--stdin-filepath", "example.foo"], { input: "hello-world" } @@ -55,8 +55,8 @@ describe("external options from config file should work", () => { }); }); -describe("Non exists plugin", () => { - runPrettier( +test("Non exists plugin", async () => { + await runPrettier( "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 209bed0ac2fc..8462d7910c6a 100644 --- a/tests_integration/__tests__/plugin-options.js +++ b/tests_integration/__tests__/plugin-options.js @@ -3,17 +3,17 @@ const snapshotDiff = require("snapshot-diff"); const runPrettier = require("../runPrettier"); -describe("show external options with `--help`", () => { - const originalStdout = runPrettier("plugins/options", ["--help"]).stdout; - const pluggedStdout = runPrettier("plugins/options", [ +test("show external options with `--help`", async () => { + const originalStdout = (await runPrettier("plugins/options", ["--help"]).test()).stdout; + const pluggedStdout = (await runPrettier("plugins/options", [ "--help", "--plugin=./plugin", - ]).stdout; + ]).test()).stdout; expect(snapshotDiff(originalStdout, pluggedStdout)).toMatchSnapshot(); }); -describe("show detailed external option with `--help foo-option`", () => { - runPrettier("plugins/options", [ +test("show detailed external option with `--help foo-option`", async () => { + await runPrettier("plugins/options", [ "--plugin=./plugin", "--help", "foo-option", @@ -22,8 +22,8 @@ describe("show detailed external option with `--help foo-option`", () => { }); }); -describe("include plugin's parsers to the values of the `parser` option`", () => { - runPrettier("plugins/options", [ +test("include plugin's parsers to the values of the `parser` option`", async () => { + await runPrettier("plugins/options", [ "--plugin=./plugin", "--help", "parser", @@ -32,8 +32,8 @@ describe("include plugin's parsers to the values of the `parser` option`", () => }); }); -describe("external options from CLI should work", () => { - runPrettier( +test("external options from CLI should work", async () => { + await runPrettier( "plugins/options", [ "--plugin=./plugin", @@ -51,8 +51,8 @@ describe("external options from CLI should work", () => { }); }); -describe("external options from config file should work", () => { - runPrettier( +test("external options from config file should work", async () => { + await runPrettier( "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 355b24a48210..94d33b6890a9 100644 --- a/tests_integration/__tests__/plugin-precedence.js +++ b/tests_integration/__tests__/plugin-precedence.js @@ -2,8 +2,8 @@ const runPrettier = require("../runPrettier"); -describe("json-stringify takes precedence over json for package.json", () => { - runPrettier("plugins", ["--stdin-filepath=package.json"], { +test("json-stringify takes precedence over json for package.json", async () => { + await runPrettier("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 23819fe50979..4ff7d0af37ff 100644 --- a/tests_integration/__tests__/plugin-preprocess.js +++ b/tests_integration/__tests__/plugin-preprocess.js @@ -3,8 +3,8 @@ const runPrettier = require("../runPrettier"); const EOL = "\n"; -describe("parser preprocess function is used to reshape input text", () => { - runPrettier("plugins/preprocess", ["*.foo", "--plugin=./plugin"], { +test("parser preprocess function is used to reshape input text", async () => { + await runPrettier("plugins/preprocess", ["*.foo", "--plugin=./plugin"], { ignoreLineEndings: true, }).test({ stdout: "preprocessed:contents" + EOL, diff --git a/tests_integration/__tests__/plugin-resolution.js b/tests_integration/__tests__/plugin-resolution.js index bcd2ec785fa7..895da4e1a6b5 100644 --- a/tests_integration/__tests__/plugin-resolution.js +++ b/tests_integration/__tests__/plugin-resolution.js @@ -3,8 +3,8 @@ const runPrettier = require("../runPrettier"); const EOL = "\n"; -describe("automatically loads 'prettier-plugin-*'", () => { - runPrettier("plugins/automatic", ["file.txt", "--parser=bar"]).test({ +test("automatically loads 'prettier-plugin-*'", async () => { + await runPrettier("plugins/automatic", ["file.txt", "--parser=bar"]).test({ stdout: "content from `prettier-plugin-bar` package + contents" + EOL, stderr: "", status: 0, @@ -12,8 +12,8 @@ describe("automatically loads 'prettier-plugin-*'", () => { }); }); -describe("automatically loads '@prettier/plugin-*'", () => { - runPrettier("plugins/automatic", ["file.txt", "--parser=foo"]).test({ +test("automatically loads '@prettier/plugin-*'", async () => { + await runPrettier("plugins/automatic", ["file.txt", "--parser=foo"]).test({ stdout: "foo+contents" + EOL, stderr: "", status: 0, @@ -21,8 +21,8 @@ describe("automatically loads '@prettier/plugin-*'", () => { }); }); -describe("automatically loads '@/prettier-plugin-*'", () => { - runPrettier("plugins/automatic", ["file.txt", "--parser=foobar"]).test({ +test("automatically loads '@/prettier-plugin-*'", async () => { + await runPrettier("plugins/automatic", ["file.txt", "--parser=foobar"]).test({ stdout: "foobar+contents" + EOL, stderr: "", status: 0, @@ -30,8 +30,8 @@ describe("automatically loads '@/prettier-plugin-*'", () => { }); }); -describe("automatically loads 'prettier-plugin-*' from --plugin-search-dir (same as autoload dir)", () => { - runPrettier("plugins/automatic", [ +test("automatically loads 'prettier-plugin-*' from --plugin-search-dir (same as autoload dir)", async () => { + await runPrettier("plugins/automatic", [ "file.txt", "--parser=foo", "--plugin-search-dir=.", @@ -43,8 +43,8 @@ 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", [ +test("automatically loads '@prettier/plugin-*' from --plugin-search-dir (same as autoload dir)", async () => { + await runPrettier("plugins/automatic", [ "file.txt", "--parser=bar", "--plugin-search-dir=.", @@ -56,8 +56,8 @@ 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", [ +test("automatically loads '@/prettier-plugin-*' from --plugin-search-dir (same as autoload dir)", async () => { + await runPrettier("plugins/automatic", [ "file.txt", "--parser=foobar", "--plugin-search-dir=.", @@ -69,8 +69,8 @@ describe("automatically loads '@/prettier-plugin-*' from --plugin-search-d }); }); -describe("automatically loads 'prettier-plugin-*' from --plugin-search-dir (different to autoload dir)", () => { - runPrettier("plugins", [ +test("automatically loads 'prettier-plugin-*' from --plugin-search-dir (different to autoload dir)", async () => { + await runPrettier("plugins", [ "automatic/file.txt", "--parser=foo", "--plugin-search-dir=automatic", @@ -82,8 +82,8 @@ 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", [ +test("automatically loads '@prettier/plugin-*' from --plugin-search-dir (different to autoload dir)", async () => { + await runPrettier("plugins", [ "automatic/file.txt", "--parser=bar", "--plugin-search-dir=automatic", @@ -95,8 +95,8 @@ describe("automatically loads '@prettier/plugin-*' from --plugin-search-dir (dif }); }); -describe("does not crash when --plugin-search-dir does not contain node_modules", () => { - runPrettier( +test("does not crash when --plugin-search-dir does not contain node_modules", async () => { + await runPrettier( "plugins/extensions", [ "file.foo", @@ -114,8 +114,8 @@ 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", [ +test("crashes when one of --plugin-search-dir does not exist", async () => { + await runPrettier("plugins/automatic", [ "file.txt", "--parser=foo", "--plugin-search-dir=non-existing-dir", @@ -128,8 +128,8 @@ describe("crashes when one of --plugin-search-dir does not exist", () => { }); }); -describe("loads --plugin by its relative path", () => { - runPrettier("plugins", [ +test("loads --plugin by its relative path", async () => { + await runPrettier("plugins", [ "automatic/file.txt", "--parser=bar", "--plugin=./automatic/node_modules/prettier-plugin-bar/index.js", @@ -141,8 +141,8 @@ describe("loads --plugin by its relative path", () => { }); }); -describe("loads --plugin by its relative path without leading ./", () => { - runPrettier("plugins", [ +test("loads --plugin by its relative path without leading ./", async () => { + await runPrettier("plugins", [ "automatic/file.txt", "--parser=bar", "--plugin=automatic/node_modules/prettier-plugin-bar/index.js", @@ -154,8 +154,8 @@ describe("loads --plugin by its relative path without leading ./", () => { }); }); -describe("loads --plugin by relative path to its directory (assuming index.js)", () => { - runPrettier("plugins", [ +test("loads --plugin by relative path to its directory (assuming index.js)", async () => { + await runPrettier("plugins", [ "automatic/file.txt", "--parser=bar", "--plugin=./automatic/node_modules/prettier-plugin-bar", @@ -167,8 +167,8 @@ describe("loads --plugin by relative path to its directory (assuming index.js)", }); }); -describe("loads --plugin by relative path to its directory without leading ./ (assuming index.js)", () => { - runPrettier("plugins", [ +test("loads --plugin by relative path to its directory without leading ./ (assuming index.js)", async () => { + await runPrettier("plugins", [ "automatic/file.txt", "--parser=bar", "--plugin=automatic/node_modules/prettier-plugin-bar", @@ -180,8 +180,8 @@ describe("loads --plugin by relative path to its directory without leading ./ (a }); }); -describe("loads --plugin by filename without leading ./ and ext, should resolve to file, not package", () => { - runPrettier("plugins/automatic", [ +test("loads --plugin by filename without leading ./ and ext, should resolve to file, not package", async () => { + await runPrettier("plugins/automatic", [ "file.txt", "--parser=bar", "--plugin=prettier-plugin-bar", @@ -193,8 +193,8 @@ describe("loads --plugin by filename without leading ./ and ext, should resolve }); }); -describe("loads --plugin by bespoke plugin name (assuming it is installed in cwd)", () => { - runPrettier("plugins/bespoke", [ +test("loads --plugin by bespoke plugin name (assuming it is installed in cwd)", async () => { + await runPrettier("plugins/bespoke", [ "../automatic/file.txt", "--parser=bespoke", "--plugin=@company/prettier-plugin-bespoke", diff --git a/tests_integration/__tests__/plugin-virtual-directory.js b/tests_integration/__tests__/plugin-virtual-directory.js index 4602eb01359c..0df2f277141b 100644 --- a/tests_integration/__tests__/plugin-virtual-directory.js +++ b/tests_integration/__tests__/plugin-virtual-directory.js @@ -2,8 +2,8 @@ const runPrettier = require("../runPrettier"); -describe("plugin search should not crash when prettier isn't inside a directory", () => { - runPrettier( +test("plugin search should not crash when prettier isn't inside a directory", async () => { + await runPrettier( "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 193781c9e807..1c9b244257a6 100644 --- a/tests_integration/__tests__/skip-folders.js +++ b/tests_integration/__tests__/skip-folders.js @@ -4,15 +4,15 @@ const runPrettier = require("../runPrettier"); expect.addSnapshotSerializer(require("../path-serializer")); -describe("skips folders in glob", () => { - runPrettier("cli/skip-folders", ["**/*", "-l"]).test({ +test("skips folders in glob", async () => { + await runPrettier("cli/skip-folders", ["**/*", "-l"]).test({ status: 1, stderr: "", }); }); -describe("skip folders passed specifically", () => { - runPrettier("cli/skip-folders", [ +test("skip folders passed specifically", async () => { + await runPrettier("cli/skip-folders", [ "a", "a/file.js", "b", diff --git a/tests_integration/__tests__/stdin-filepath.js b/tests_integration/__tests__/stdin-filepath.js index 32cb97e23d0f..c03026a3f170 100644 --- a/tests_integration/__tests__/stdin-filepath.js +++ b/tests_integration/__tests__/stdin-filepath.js @@ -3,8 +3,8 @@ const { isCI } = require("ci-info"); const runPrettier = require("../runPrettier"); -describe("format correctly if stdin content compatible with stdin-filepath", () => { - runPrettier( +test("format correctly if stdin content compatible with stdin-filepath", async () => { + await runPrettier( "cli", ["--stdin-filepath", "abc.css"], { input: ".name { display: none; }" } // css @@ -13,8 +13,8 @@ describe("format correctly if stdin content compatible with stdin-filepath", () }); }); -describe("throw error if stdin content incompatible with stdin-filepath", () => { - runPrettier( +test("throw error if stdin content incompatible with stdin-filepath", async () => { + await runPrettier( "cli", ["--stdin-filepath", "abc.js"], { input: ".name { display: none; }" } // css @@ -23,8 +23,8 @@ describe("throw error if stdin content incompatible with stdin-filepath", () => }); }); -describe("gracefully handle stdin-filepath with nonexistent directory", () => { - runPrettier( +test("gracefully handle stdin-filepath with nonexistent directory", async () => { + await runPrettier( "cli", ["--stdin-filepath", "definitely/nonexistent/path.css"], { input: ".name { display: none; }" } // css @@ -33,8 +33,8 @@ describe("gracefully handle stdin-filepath with nonexistent directory", () => { }); }); -describe("apply editorconfig for stdin-filepath with nonexistent file", () => { - runPrettier( +test("apply editorconfig for stdin-filepath with nonexistent file", async () => { + await runPrettier( "cli", ["--stdin-filepath", "config/editorconfig/nonexistent.js"], { @@ -49,8 +49,8 @@ function f() { }); }); -describe("apply editorconfig for stdin-filepath with nonexistent directory", () => { - runPrettier( +test("apply editorconfig for stdin-filepath with nonexistent directory", async () => { + await runPrettier( "cli", ["--stdin-filepath", "config/editorconfig/nonexistent/one/two/three.js"], { @@ -65,8 +65,8 @@ function f() { }); }); -describe("apply editorconfig for stdin-filepath with a deep path", () => { - runPrettier( +test("apply editorconfig for stdin-filepath with a deep path", async () => { + await runPrettier( "cli", ["--stdin-filepath", "config/editorconfig/" + "a/".repeat(30) + "three.js"], { @@ -82,13 +82,13 @@ function f() { }); if (isCI) { - describe("apply editorconfig for stdin-filepath in root", () => { + test("apply editorconfig for stdin-filepath in root", async () => { const code = ` function f() { console.log("should be indented with a tab"); } `.trim(); - runPrettier("cli", ["--stdin-filepath", "/foo.js"], { + await runPrettier("cli", ["--stdin-filepath", "/foo.js"], { input: code, // js }).test({ status: 0, @@ -99,8 +99,8 @@ function f() { }); } -describe("apply editorconfig for stdin-filepath with a deep path", () => { - runPrettier( +test("apply editorconfig for stdin-filepath with a deep path", async () => { + await runPrettier( "cli", ["--stdin-filepath", "config/editorconfig/" + "a/".repeat(30) + "three.js"], { @@ -115,8 +115,8 @@ function f() { }); }); -describe("don’t apply editorconfig outside project for stdin-filepath with nonexistent directory", () => { - runPrettier( +test("don’t apply editorconfig outside project for stdin-filepath with nonexistent directory", async () => { + await runPrettier( "cli", [ "--stdin-filepath", @@ -134,8 +134,8 @@ function f() { }); }); -describe("output file as-is if stdin-filepath matched patterns in ignore-path", () => { - runPrettier("cli/stdin-ignore", ["--stdin-filepath", "ignore/example.js"], { +test("output file as-is if stdin-filepath matched patterns in ignore-path", async () => { + await runPrettier("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 9b211902f118..eee155b5fe86 100644 --- a/tests_integration/__tests__/support-info.js +++ b/tests_integration/__tests__/support-info.js @@ -7,8 +7,8 @@ test("API getSupportInfo()", () => { expect(getCoreInfo()).toMatchSnapshot(); }); -describe("CLI --support-info", () => { - runPrettier("cli", "--support-info").test({ status: 0 }); +test("CLI --support-info", async () => { + await runPrettier("cli", "--support-info").test({ status: 0 }); }); function getCoreInfo() { diff --git a/tests_integration/__tests__/syntax-error.js b/tests_integration/__tests__/syntax-error.js index 362ffab404f6..409eb07f0dbb 100644 --- a/tests_integration/__tests__/syntax-error.js +++ b/tests_integration/__tests__/syntax-error.js @@ -2,8 +2,8 @@ const runPrettier = require("../runPrettier"); -describe("exits with non-zero code when input has a syntax error", () => { - runPrettier("cli/with-shebang", ["--parser", "babel"], { +test("exits with non-zero code when input has a syntax error", async () => { + await runPrettier("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 22a2e69b96a3..41f30896b249 100644 --- a/tests_integration/__tests__/with-config-precedence.js +++ b/tests_integration/__tests__/with-config-precedence.js @@ -2,8 +2,8 @@ const runPrettier = require("../runPrettier"); -describe("CLI overrides take precedence without --config-precedence", () => { - runPrettier("cli/config/", [ +test("CLI overrides take precedence without --config-precedence", async () => { + await runPrettier("cli/config/", [ "--end-of-line", "lf", "--print-width", @@ -14,8 +14,8 @@ describe("CLI overrides take precedence without --config-precedence", () => { }); }); -describe("CLI overrides take precedence with --config-precedence cli-override", () => { - runPrettier("cli/config/", [ +test("CLI overrides take precedence with --config-precedence cli-override", async () => { + await runPrettier("cli/config/", [ "--end-of-line", "lf", "--print-width", @@ -28,8 +28,8 @@ describe("CLI overrides take precedence with --config-precedence cli-override", }); }); -describe("CLI overrides take lower precedence with --config-precedence file-override", () => { - runPrettier("cli/config/js/", [ +test("CLI overrides take lower precedence with --config-precedence file-override", async () => { + await runPrettier("cli/config/js/", [ "--end-of-line", "crlf", "--tab-width", @@ -42,8 +42,8 @@ describe("CLI overrides take lower precedence with --config-precedence file-over }); }); -describe("CLI overrides are still applied when no config is found with --config-precedence file-override", () => { - runPrettier("cli/config/no-config/", [ +test("CLI overrides are still applied when no config is found with --config-precedence file-override", async () => { + await runPrettier("cli/config/no-config/", [ "--end-of-line", "lf", "--tab-width", @@ -57,8 +57,8 @@ 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/", [ +test("CLI overrides gets ignored when config exists with --config-precedence prefer-file", async () => { + await runPrettier("cli/config/js/", [ "--print-width", "1", "--tab-width", @@ -71,8 +71,8 @@ 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/", [ +test("CLI overrides gets applied when no config exists with --config-precedence prefer-file", async () => { + await runPrettier("cli/config/no-config/", [ "--end-of-line", "lf", "--print-width", @@ -88,8 +88,8 @@ 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", [ +test("CLI validate options with --config-precedence cli-override", async () => { + await runPrettier("cli/config-precedence", [ "--config-precedence", "cli-override", ]).test({ @@ -97,8 +97,8 @@ describe("CLI validate options with --config-precedence cli-override", () => { }); }); -describe("CLI validate options with --config-precedence file-override", () => { - runPrettier("cli/config-precedence", [ +test("CLI validate options with --config-precedence file-override", async () => { + await runPrettier("cli/config-precedence", [ "--config-precedence", "file-override", ]).test({ @@ -106,8 +106,8 @@ describe("CLI validate options with --config-precedence file-override", () => { }); }); -describe("CLI validate options with --config-precedence prefer-file", () => { - runPrettier("cli/config-precedence", [ +test("CLI validate options with --config-precedence prefer-file", async () => { + await runPrettier("cli/config-precedence", [ "--config-precedence", "prefer-file", ]).test({ @@ -115,8 +115,8 @@ describe("CLI validate options with --config-precedence prefer-file", () => { }); }); -describe("CLI --stdin-filepath works with --config-precedence prefer-file", () => { - runPrettier( +test("CLI --stdin-filepath works with --config-precedence prefer-file", async () => { + await runPrettier( "cli/config/", ["--stdin-filepath=abc.ts", "--no-semi", "--config-precedence=prefer-file"], { input: "let x: keyof Y = foo()" } // typescript @@ -126,8 +126,8 @@ describe("CLI --stdin-filepath works with --config-precedence prefer-file", () = }); }); -describe("CLI --stdin-filepath works with --config-precedence file-override", () => { - runPrettier( +test("CLI --stdin-filepath works with --config-precedence file-override", async () => { + await runPrettier( "cli/config/", [ "--stdin-filepath=abc.ts", @@ -141,8 +141,8 @@ describe("CLI --stdin-filepath works with --config-precedence file-override", () }); }); -describe("CLI --stdin-filepath works with --config-precedence cli-override", () => { - runPrettier( +test("CLI --stdin-filepath works with --config-precedence cli-override", async () => { + await runPrettier( "cli/config/", [ "--stdin-filepath=abc.ts", diff --git a/tests_integration/__tests__/with-node-modules.js b/tests_integration/__tests__/with-node-modules.js index 212d80d5cc5c..9ee6dc0550ec 100644 --- a/tests_integration/__tests__/with-node-modules.js +++ b/tests_integration/__tests__/with-node-modules.js @@ -4,20 +4,20 @@ const runPrettier = require("../runPrettier"); expect.addSnapshotSerializer(require("../path-serializer")); -describe("ignores node_modules by default", () => { - runPrettier("cli/with-node-modules", ["**/*.js", "-l"]).test({ +test("ignores node_modules by default", async () => { + await runPrettier("cli/with-node-modules", ["**/*.js", "-l"]).test({ status: 1, }); }); -describe("ignores node_modules by with ./**/*.js", () => { - runPrettier("cli/with-node-modules", ["./**/*.js", "-l"]).test({ +test("ignores node_modules by with ./**/*.js", async () => { + await runPrettier("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", [ +test("doesn't ignore node_modules with --with-node-modules flag", async () => { + await runPrettier("cli/with-node-modules", [ "**/*.js", "-l", "--with-node-modules", @@ -26,8 +26,8 @@ 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", [ +test("ignores node_modules by default for file list", async () => { + await runPrettier("cli/with-node-modules", [ "node_modules/node-module.js", "not_node_modules/file.js", "nested/node_modules/node-module.js", @@ -38,8 +38,8 @@ 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", [ +test("doesn't ignore node_modules with --with-node-modules flag for file list", async () => { + await runPrettier("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 020005d12d44..65cb9031bf20 100644 --- a/tests_integration/__tests__/with-parser-inference.js +++ b/tests_integration/__tests__/with-parser-inference.js @@ -3,20 +3,20 @@ const prettier = require("prettier-local"); const runPrettier = require("../runPrettier"); -describe("infers postcss parser", () => { - runPrettier("cli/with-parser-inference", ["--end-of-line", "lf", "*"]).test({ +test("infers postcss parser", async () => { + await runPrettier("cli/with-parser-inference", ["--end-of-line", "lf", "*"]).test({ status: 0, }); }); -describe("infers postcss parser with --check", () => { - runPrettier("cli/with-parser-inference", ["--check", "*"]).test({ +test("infers postcss parser with --check", async () => { + await runPrettier("cli/with-parser-inference", ["--check", "*"]).test({ status: 0, }); }); -describe("infers postcss parser with --list-different", () => { - runPrettier("cli/with-parser-inference", ["--list-different", "*"]).test({ +test("infers postcss parser with --list-different", async () => { + await runPrettier("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 62c78f744a28..d210319f17d1 100644 --- a/tests_integration/__tests__/with-shebang.js +++ b/tests_integration/__tests__/with-shebang.js @@ -2,8 +2,8 @@ const runPrettier = require("../runPrettier"); -describe("preserves shebang", () => { - runPrettier("cli/with-shebang", ["--end-of-line", "lf", "issue1890.js"]).test( +test("preserves shebang", async () => { + await runPrettier("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 32d891a38c8f..c99127af1424 100644 --- a/tests_integration/__tests__/write.js +++ b/tests_integration/__tests__/write.js @@ -2,27 +2,27 @@ const runPrettier = require("../runPrettier"); -describe("write file with --write + unformatted file", () => { - runPrettier("cli/write", ["--write", "unformatted.js"]).test({ +test("write file with --write + unformatted file", async () => { + await runPrettier("cli/write", ["--write", "unformatted.js"]).test({ status: 0, }); }); -describe("write file with -w + unformatted file", () => { - runPrettier("cli/write", ["-w", "unformatted.js"]).test({ +test("write file with -w + unformatted file", async () => { + await runPrettier("cli/write", ["-w", "unformatted.js"]).test({ status: 0, }); }); -describe("do not write file with --write + formatted file", () => { - runPrettier("cli/write", ["--write", "formatted.js"]).test({ +test("do not write file with --write + formatted file", async () => { + await runPrettier("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({ +test("do not write file with --write + invalid file", async () => { + await runPrettier("cli/write", ["--write", "invalid.js"]).test({ write: [], status: "non-zero", }); diff --git a/tests_integration/runPrettier.js b/tests_integration/runPrettier.js index 7c83ae5dec31..a792fe6c31dd 100644 --- a/tests_integration/runPrettier.js +++ b/tests_integration/runPrettier.js @@ -98,24 +98,24 @@ function runPrettier(dir, args = [], options = {}) { .spyOn(require(thirdParty), "findParentDir") .mockImplementation(() => process.cwd()); - try { - require(prettierCli); - status = (status === undefined ? process.exitCode : status) || 0; - } catch (error) { - status = 1; - stderr += error.message; - } finally { - process.chdir(originalCwd); - process.argv = originalArgv; - process.exitCode = originalExitCode; - process.stdin.isTTY = originalStdinIsTTY; - process.stdout.isTTY = originalStdoutIsTTY; - jest.restoreAllMocks(); - } + const test = async (testOptions = {}) => { + try { + await require(prettierCli); + status = (status === undefined ? process.exitCode : status) || 0; + } catch (error) { + status = 1; + stderr += error.message; + } finally { + process.chdir(originalCwd); + process.argv = originalArgv; + process.exitCode = originalExitCode; + process.stdin.isTTY = originalStdinIsTTY; + process.stdout.isTTY = originalStdoutIsTTY; + jest.restoreAllMocks(); + } - const result = { status, stdout, stderr, write }; + const result = { status, stdout, stderr, write }; - const testResult = (testOptions) => { for (const name of Object.keys(result)) { test(`(${name})`, () => { const value = @@ -142,7 +142,7 @@ function runPrettier(dir, args = [], options = {}) { return result; }; - return { test: testResult, ...result }; + return { test }; function appendStdout(text) { if (status === undefined) {