test: fix snapshots (#2957)

* test: trigger test to check its status

* test: update snapshots

* refactor: use strip-ansi
master
Ika 2017-10-02 12:56:34 -05:00 committed by Simon Lydell
parent 7770356a51
commit d9737e6ffa
8 changed files with 21 additions and 18 deletions

View File

@ -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"

View File

@ -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
"
`;

View File

@ -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"

View File

@ -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

View File

@ -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",

View File

@ -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"
});

View File

@ -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();
}
});
});

View File

@ -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"