From 482ec01c8eba93973f510ef803095bac87cc4429 Mon Sep 17 00:00:00 2001 From: Lucas Azzola Date: Fri, 6 Oct 2017 14:12:32 +1100 Subject: [PATCH] Fix build (#2981) --- src/cli-util.js | 4 +- .../__snapshots__/piped-output.js.snap | 42 ++++++++++++++++--- .../__tests__/__snapshots__/write.js.snap | 6 +-- tests_integration/__tests__/piped-output.js | 34 +++++++-------- tests_integration/runPrettier.js | 2 + 5 files changed, 59 insertions(+), 29 deletions(-) diff --git a/src/cli-util.js b/src/cli-util.js index c65918075..612544ec0 100644 --- a/src/cli-util.js +++ b/src/cli-util.js @@ -325,13 +325,13 @@ function formatFiles(argv) { // mtime based caches. if (output === input) { if (!argv["list-different"]) { - console.log(chalk.grey("%s %dms"), filename, Date.now() - start); + console.log(chalk.grey(filename), `${Date.now() - start}ms`); } } else { if (argv["list-different"]) { console.log(filename); } else { - console.log("%s %dms", filename, Date.now() - start); + console.log(filename, `${Date.now() - start}ms`); } try { diff --git a/tests_integration/__tests__/__snapshots__/piped-output.js.snap b/tests_integration/__tests__/__snapshots__/piped-output.js.snap index ad1df38cb..844ab7fc9 100644 --- a/tests_integration/__tests__/__snapshots__/piped-output.js.snap +++ b/tests_integration/__tests__/__snapshots__/piped-output.js.snap @@ -1,15 +1,47 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`no file diffs with --list-different + formatted file 1`] = `Array []`; +exports[`no file diffs with --list-different + formatted file (stderr) 1`] = `""`; -exports[`no file diffs with --list-different + formatted file 2`] = `Array []`; +exports[`no file diffs with --list-different + formatted file (stderr) 2`] = `""`; -exports[`output with --list-different + unformatted differs when piped 1`] = ` -"unformated.jsunformated.js +exports[`no file diffs with --list-different + formatted file (stdout) 1`] = `"formated.js"`; + +exports[`no file diffs with --list-different + formatted file (stdout) 2`] = `""`; + +exports[`no file diffs with --list-different + formatted file (write) 1`] = `Array []`; + +exports[`no file diffs with --list-different + formatted file (write) 2`] = `Array []`; + +exports[`output with --list-different + unformatted differs when piped (stderr) 1`] = `""`; + +exports[`output with --list-different + unformatted differs when piped (stderr) 2`] = `""`; + +exports[`output with --list-different + unformatted differs when piped (stdout) 1`] = ` +"unformated.jsunformated.js " `; -exports[`output with --list-different + unformatted differs when piped 2`] = ` +exports[`output with --list-different + unformatted differs when piped (stdout) 2`] = ` "unformated.js " `; + +exports[`output with --list-different + unformatted differs when piped (write) 1`] = ` +Array [ + Object { + "content": "var x = 1; +", + "filename": "unformated.js", + }, +] +`; + +exports[`output with --list-different + unformatted differs when piped (write) 2`] = ` +Array [ + Object { + "content": "var x = 1; +", + "filename": "unformated.js", + }, +] +`; diff --git a/tests_integration/__tests__/__snapshots__/write.js.snap b/tests_integration/__tests__/__snapshots__/write.js.snap index 78cada40a..5cf531db4 100644 --- a/tests_integration/__tests__/__snapshots__/write.js.snap +++ b/tests_integration/__tests__/__snapshots__/write.js.snap @@ -3,7 +3,7 @@ exports[`do not write file with --write + formated file (stderr) 1`] = `""`; exports[`do not write file with --write + formated file (stdout) 1`] = ` -"formated.js%s %dms +"formated.js " `; @@ -15,14 +15,14 @@ exports[`do not write file with --write + invalid file (stderr) 1`] = ` `; exports[`do not write file with --write + invalid file (stdout) 1`] = ` -"invalid.js +" " `; exports[`write file with --write + unformated file (stderr) 1`] = `""`; exports[`write file with --write + unformated file (stdout) 1`] = ` -"unformated.js%s %dms +"unformated.js " `; diff --git a/tests_integration/__tests__/piped-output.js b/tests_integration/__tests__/piped-output.js index 46e4606fb..70a94ff0b 100644 --- a/tests_integration/__tests__/piped-output.js +++ b/tests_integration/__tests__/piped-output.js @@ -2,47 +2,43 @@ const runPrettier = require("../runPrettier"); -test("output with --list-different + unformatted differs when piped", () => { +describe("output with --list-different + unformatted differs when piped", () => { const result0 = runPrettier( "cli/write", ["--write", "--list-different", "--no-color", "unformated.js"], { stdoutIsTTY: true } - ); + ).test({ + status: 1 + }); const result1 = runPrettier( "cli/write", ["--write", "--list-different", "--no-color", "unformated.js"], { stdoutIsTTY: false } - ); + ).test({ + status: 1 + }); - expect(result0.stdout).toMatchSnapshot(); - expect(result0.status).toEqual(1); - - expect(result1.stdout).toMatchSnapshot(); - expect(result1.status).toEqual(1); - - expect(result0.stdout).not.toEqual(result1.stdout); expect(result0.stdout.length).toBeGreaterThan(result1.stdout.length); expect(result0.write).toEqual(result1.write); }); -test("no file diffs with --list-different + formatted file", () => { +describe("no file diffs with --list-different + formatted file", () => { const result0 = runPrettier( "cli/write", ["--write", "--list-different", "--no-color", "formated.js"], { stdoutIsTTY: true } - ); + ).test({ + status: 0 + }); + const result1 = runPrettier( "cli/write", ["--write", "--list-different", "--no-color", "formated.js"], { stdoutIsTTY: false } - ); - - expect(result0.write).toMatchSnapshot(); - expect(result0.status).toEqual(0); - - expect(result1.write).toMatchSnapshot(); - expect(result1.status).toEqual(0); + ).test({ + status: 0 + }); expect(result0.stdout).not.toEqual(result1.stdout); expect(result0.stdout.length).toBeGreaterThan(result1.stdout.length); diff --git a/tests_integration/runPrettier.js b/tests_integration/runPrettier.js index b018234e6..343e742c4 100644 --- a/tests_integration/runPrettier.js +++ b/tests_integration/runPrettier.js @@ -107,6 +107,8 @@ function runPrettier(dir, args, options) { } }); }); + + return result; }; return { test: testResult };