-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
/
format.js
69 lines (60 loc) · 1.84 KB
/
format.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
"use strict";
const prettier = require("prettier-local");
const { outdent } = require("outdent");
const fooPlugin = require("../plugins/defaultOptions/plugin.js");
test("yaml parser should handle CRLF correctly", () => {
const input = "a:\r\n 123\r\n";
expect(
// use JSON.stringify to observe CRLF
JSON.stringify(
prettier.format(input, { parser: "yaml", endOfLine: "auto" })
)
).toMatchSnapshot();
});
test("typescript parser should throw the first error when both JSX and non-JSX mode failed", () => {
const input = outdent`
import React from "react";
const App = () => (
<div className="App">
</div>
);
label:
`;
expect(() =>
prettier.format(input, { parser: "typescript" })
).toThrowErrorMatchingSnapshot();
});
test("html parser should handle CRLF correctly", () => {
const input = "<!--\r\n test\r\n test\r\n-->";
expect(
// use JSON.stringify to observe CRLF
JSON.stringify(
prettier.format(input, { parser: "html", endOfLine: "auto" })
)
).toMatchSnapshot();
});
test("markdown parser should handle CRLF correctly", () => {
const input = "```\r\n\r\n\r\n```";
expect(
// use JSON.stringify to observe CRLF
JSON.stringify(
prettier.format(input, { parser: "markdown", endOfLine: "auto" })
)
).toMatchSnapshot();
});
test("should work with foo plugin instance", () => {
const input = "a:\r\n 123\r\n";
expect(
JSON.stringify(
prettier.format(input, { parser: "foo-parser", plugins: [fooPlugin] })
)
).toMatchInlineSnapshot(
'"\\"{\\\\\\"tabWidth\\\\\\":8,\\\\\\"bracketSpacing\\\\\\":false}\\""'
);
});
test("'Adjacent JSX' error should not be swallowed by Babel's error recovery", () => {
const input = "<a></a>\n<b></b>";
expect(() =>
prettier.format(input, { parser: "babel" })
).toThrowErrorMatchingSnapshot();
});