Skip to content

Commit b9e0cb9

Browse files
authored
Ported test suite: line-after-filepath-with-errors (#35)
Notes on differences: - Running `prettier ./*` vs `prettier --check ./*` has different behaviour for invalid files. in the former, no errors are raised and the files are essentially ignored. We should decide if this is expected - Running with `--list-different`, invalid files have their paths listed in stderr, while in prettier they will raise errors. * test: template fixture path in string assertions * test: fix up tests
1 parent 8831ab3 commit b9e0cb9

6 files changed

Lines changed: 81 additions & 0 deletions

File tree

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
foo (+-) bar
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
foo (+-) bar

test/__fixtures__/syntax-errors/invalid-2.unknown

Whitespace-only changes.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
function foo() {}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`Line breaking after filepath with errors (stderr) 1`] = `
4+
"[error] invalid-1.js: SyntaxError: Unexpected token (1:8)
5+
[error] > 1 | foo (+-) bar
6+
[error] | ^
7+
[error] 2 |
8+
[error] invalid-2.js: SyntaxError: Unexpected token (1:8)
9+
[error] > 1 | foo (+-) bar
10+
[error] | ^
11+
[error] 2 |
12+
[error] invalid-2.unknown: UndefinedParserError: No parser could be inferred for file "$CWD/invalid-2.unknown"."
13+
`;
14+
15+
exports[`Line breaking after filepath with errors (stderr) 2`] = `
16+
"invalid-1.js
17+
invalid-2.js
18+
invalid-2.unknown"
19+
`;
20+
21+
exports[`Line breaking after filepath with errors (stderr) 3`] = `
22+
"[error] invalid-1.js: SyntaxError: Unexpected token (1:8)
23+
[error] > 1 | foo (+-) bar
24+
[error] | ^
25+
[error] 2 |
26+
[error] invalid-2.js: SyntaxError: Unexpected token (1:8)
27+
[error] > 1 | foo (+-) bar
28+
[error] | ^
29+
[error] 2 |
30+
[error] invalid-2.unknown: UndefinedParserError: No parser could be inferred for file "$CWD/invalid-2.unknown"."
31+
`;
32+
33+
exports[`Line breaking after filepath with errors (stderr) 4`] = `
34+
"[error] invalid-1.js: SyntaxError: Unexpected token (1:8)
35+
[error] > 1 | foo (+-) bar
36+
[error] | ^
37+
[error] 2 |
38+
[error] invalid-2.js: SyntaxError: Unexpected token (1:8)
39+
[error] > 1 | foo (+-) bar
40+
[error] | ^
41+
[error] 2 |
42+
[error] invalid-2.unknown: UndefinedParserError: No parser could be inferred for file "$CWD/invalid-2.unknown"."
43+
`;
44+
45+
exports[`Line breaking after filepath with errors (stdout) 1`] = `"function foo() {}"`;
46+
47+
exports[`Line breaking after filepath with errors (stdout) 2`] = `""`;
48+
49+
exports[`Line breaking after filepath with errors (stdout) 3`] = `"Checking formatting..."`;
50+
51+
exports[`Line breaking after filepath with errors (stdout) 4`] = `""`;
52+
53+
exports[`Line breaking after filepath with errors (write) 1`] = `[]`;
54+
55+
exports[`Line breaking after filepath with errors (write) 2`] = `[]`;
56+
57+
exports[`Line breaking after filepath with errors (write) 3`] = `[]`;
58+
59+
exports[`Line breaking after filepath with errors (write) 4`] = `[]`;
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { runCli } from "../utils";
2+
3+
describe("Line breaking after filepath with errors", () => {
4+
runCli("syntax-errors", ["./*.{js,unknown}"]).test({
5+
status: 1,
6+
});
7+
// TODO (43081j): this test throws errors in prettier. here it doesn't, and
8+
// lists each invalid file path in the output (stderr). we should decide
9+
// if to align with prettier
10+
runCli("syntax-errors", ["--list-different", "./*.{js,unknown}"]).test({
11+
status: 1,
12+
});
13+
runCli("syntax-errors", ["--check", "./*.{js,unknown}"]).test({
14+
status: 1,
15+
});
16+
runCli("syntax-errors", ["--write", "./*.{js,unknown}"]).test({
17+
status: 1,
18+
});
19+
});

0 commit comments

Comments
 (0)