diff --git a/package.json b/package.json index 32efe98f9..4e8f8566c 100644 --- a/package.json +++ b/package.json @@ -66,6 +66,7 @@ "rollup-plugin-node-resolve": "2.0.0", "rollup-plugin-replace": "1.1.1", "shelljs": "0.7.8", + "strip-ansi": "4.0.0", "sw-toolbox": "3.6.0", "uglify-es": "3.0.15", "webpack": "2.6.1" diff --git a/tests_integration/__tests__/__snapshots__/write.js.snap b/tests_integration/__tests__/__snapshots__/write.js.snap index d54cbffcf..78cada40a 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%s %dms " `; @@ -22,7 +22,7 @@ exports[`do not write file with --write + invalid file (stdout) 1`] = ` exports[`write file with --write + unformated file (stderr) 1`] = `""`; exports[`write file with --write + unformated file (stdout) 1`] = ` -"unformated.js%s %dms +"unformated.js%s %dms " `; diff --git a/tests_integration/__tests__/stdin-filepath.js b/tests_integration/__tests__/stdin-filepath.js index b3b4a793f..3e6708634 100644 --- a/tests_integration/__tests__/stdin-filepath.js +++ b/tests_integration/__tests__/stdin-filepath.js @@ -5,7 +5,7 @@ const runPrettier = require("../runPrettier"); describe("format correctly if stdin content compatible with stdin-filepath", () => { runPrettier( "cli", - ["--no-color", "--stdin-filepath", "abc.css"], + ["--stdin-filepath", "abc.css"], { input: ".name { display: none; }" } // css ).test({ status: 0 @@ -15,7 +15,7 @@ describe("format correctly if stdin content compatible with stdin-filepath", () describe("throw error if stdin content incompatible with stdin-filepath", () => { runPrettier( "cli", - ["--no-color", "--stdin-filepath", "abc.js"], + ["--stdin-filepath", "abc.js"], { input: ".name { display: none; }" } // css ).test({ status: "non-zero" diff --git a/tests_integration/__tests__/syntax-error.js b/tests_integration/__tests__/syntax-error.js index a55f429da..3d8bf712a 100644 --- a/tests_integration/__tests__/syntax-error.js +++ b/tests_integration/__tests__/syntax-error.js @@ -3,7 +3,7 @@ const runPrettier = require("../runPrettier"); describe("exits with non-zero code when input has a syntax error", () => { - runPrettier("cli/with-shebang", ["--stdin", "--no-color"], { + runPrettier("cli/with-shebang", ["--stdin"], { 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 1120884b8..19333c35f 100644 --- a/tests_integration/__tests__/with-config-precedence.js +++ b/tests_integration/__tests__/with-config-precedence.js @@ -104,7 +104,6 @@ describe("CLI --stdin-filepath works with --config-precedence prefer-file", () = runPrettier( "cli/config/", [ - "--no-color", "--stdin", "--stdin-filepath=abc.ts", "--no-semi", @@ -121,7 +120,6 @@ describe("CLI --stdin-filepath works with --config-precedence file-override", () runPrettier( "cli/config/", [ - "--no-color", "--stdin", "--stdin-filepath=abc.ts", "--no-semi", @@ -138,7 +136,6 @@ describe("CLI --stdin-filepath works with --config-precedence cli-override", () runPrettier( "cli/config/", [ - "--no-color", "--stdin", "--stdin-filepath=abc.ts", "--no-semi", diff --git a/tests_integration/__tests__/write.js b/tests_integration/__tests__/write.js index 8f7405ef3..04429a2f1 100644 --- a/tests_integration/__tests__/write.js +++ b/tests_integration/__tests__/write.js @@ -16,7 +16,7 @@ describe("do not write file with --write + formated file", () => { }); describe("do not write file with --write + invalid file", () => { - runPrettier("cli/write", ["--write", "invalid.js", "--no-color"]).test({ + runPrettier("cli/write", ["--write", "invalid.js"]).test({ write: [], status: "non-zero" }); diff --git a/tests_integration/runPrettier.js b/tests_integration/runPrettier.js index 91281886a..82d450a91 100644 --- a/tests_integration/runPrettier.js +++ b/tests_integration/runPrettier.js @@ -2,6 +2,7 @@ const fs = require("fs"); const path = require("path"); +const stripAnsi = require("strip-ansi"); const isProduction = process.env.NODE_ENV === "production"; const prettierApi = isProduction ? "../dist/index" : "../index"; @@ -88,14 +89,18 @@ function runPrettier(dir, args, options) { Object.keys(result).forEach(name => { test(`(${name})`, () => { + const value = + typeof result[name] === "string" + ? stripAnsi(result[name]) + : result[name]; if (name in testOptions) { if (name === "status" && testOptions[name] === "non-zero") { - expect(result[name]).not.toEqual(0); + expect(value).not.toEqual(0); } else { - expect(result[name]).toEqual(testOptions[name]); + expect(value).toEqual(testOptions[name]); } } else { - expect(result[name]).toMatchSnapshot(); + expect(value).toMatchSnapshot(); } }); }); diff --git a/yarn.lock b/yarn.lock index 776de3ab5..1217d73a3 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3836,18 +3836,18 @@ stringstream@~0.0.4: version "0.0.5" resolved "https://registry.yarnpkg.com/stringstream/-/stringstream-0.0.5.tgz#4e484cd4de5a0bbbee18e46307710a8a81621878" +strip-ansi@4.0.0, strip-ansi@^4.0.0: + version "4.0.0" + resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-4.0.0.tgz#a8479022eb1ac368a871389b635262c505ee368f" + dependencies: + ansi-regex "^3.0.0" + strip-ansi@^3.0.0, strip-ansi@^3.0.1: version "3.0.1" resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-3.0.1.tgz#6a385fb8853d952d5ff05d0e8aaf94278dc63dcf" dependencies: ansi-regex "^2.0.0" -strip-ansi@^4.0.0: - version "4.0.0" - resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-4.0.0.tgz#a8479022eb1ac368a871389b635262c505ee368f" - dependencies: - ansi-regex "^3.0.0" - strip-bom@3.0.0, strip-bom@^3.0.0: version "3.0.0" resolved "https://registry.yarnpkg.com/strip-bom/-/strip-bom-3.0.0.tgz#2334c18e9c759f7bdd56fdef7e9ae3d588e68ed3"