test: add tests for `--stdin-filepath`

master
ikatyang 2017-09-08 15:08:19 +08:00
parent 50a26900de
commit 08460e5ca5
2 changed files with 46 additions and 0 deletions

View File

@ -0,0 +1,19 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`format correctly if stdin content compatible with stdin-filepath 1`] = `
".name {
display: none;
}
"
`;
exports[`format correctly if stdin content compatible with stdin-filepath 2`] = `""`;
exports[`throw error if stdin content incompatible with stdin-filepath 1`] = `""`;
exports[`throw error if stdin content incompatible with stdin-filepath 2`] = `
"stdin: SyntaxError: Unexpected token (1:1)
> 1 | .name { display: none; }
| ^
"
`;

View File

@ -0,0 +1,27 @@
"use strict";
const runPrettier = require("../runPrettier");
test("format correctly if stdin content compatible with stdin-filepath", () => {
const result = runPrettier(
"cli",
["--no-color", "--stdin-filepath", "abc.css"],
{ input: ".name { display: none; }" } // css
);
expect(result.stdout).toMatchSnapshot();
expect(result.stderr).toMatchSnapshot();
expect(result.status).toEqual(0);
});
test("throw error if stdin content incompatible with stdin-filepath", () => {
const result = runPrettier(
"cli",
["--no-color", "--stdin-filepath", "abc.js"],
{ input: ".name { display: none; }" } // css
);
expect(result.stdout).toMatchSnapshot();
expect(result.stderr).toMatchSnapshot();
expect(result.status).not.toEqual(0);
});