diff --git a/bin/prettier.js b/bin/prettier.js index ef6dc443a..b32ce10cb 100755 --- a/bin/prettier.js +++ b/bin/prettier.js @@ -202,7 +202,7 @@ function format(input, opt) { diff(input, pp); } } - return {}; + return { formatted: opt.filepath || "(stdin)\n" }; } return prettier.formatWithCursor(input, opt); @@ -280,7 +280,7 @@ if (stdin) { }); } else { eachFilename(filepatterns, filename => { - if (write || argv["debug-check"]) { + if (write) { // Don't use `console.log` here since we need to replace this line. process.stdout.write(filename); } @@ -358,7 +358,6 @@ if (stdin) { } } } else if (argv["debug-check"]) { - process.stdout.write("\n"); if (output) { console.log(output); } else { diff --git a/tests_integration/__tests__/debug-check.js b/tests_integration/__tests__/debug-check.js index 3ca93fd7e..a54d0d099 100644 --- a/tests_integration/__tests__/debug-check.js +++ b/tests_integration/__tests__/debug-check.js @@ -8,5 +8,15 @@ test("doesn't crash when --debug-check is passed", () => { "--debug-check" ]); + expect(result.stdout).toEqual("issue1890.js\n"); + expect(result.stderr).toEqual(""); +}); + +test("checks stdin with --debug-check", () => { + const result = runPrettier("cli/with-shebang", ["--debug-check"], { + input: "0" + }); + + expect(result.stdout).toEqual("(stdin)\n"); expect(result.stderr).toEqual(""); }); diff --git a/tests_integration/runPrettier.js b/tests_integration/runPrettier.js index 682b50e68..e1329c33e 100644 --- a/tests_integration/runPrettier.js +++ b/tests_integration/runPrettier.js @@ -12,14 +12,18 @@ const PRETTIER_PATH = path.resolve(__dirname, "../bin/prettier.js"); // return the result of the spawned process: // [ 'status', 'signal', 'output', 'pid', 'stdout', 'stderr', // 'envPairs', 'options', 'args', 'file' ] -function runPrettier(dir, args) { +function runPrettier(dir, args, options) { const isRelative = dir[0] !== "/"; if (isRelative) { dir = path.resolve(__dirname, dir); } - const result = spawnSync(PRETTIER_PATH, args || [], { cwd: dir }); + const result = spawnSync( + PRETTIER_PATH, + args || [], + Object.assign({}, options, { cwd: dir }) + ); result.stdout = result.stdout && result.stdout.toString(); result.stderr = result.stderr && result.stderr.toString();