Files
test-repo/tests/integration/__tests__/format.js
T

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

70 lines
2.0 KiB
JavaScript
Raw Normal View History

2022-03-17 21:32:14 +08:00
import { outdent } from "outdent";
2022-07-20 23:18:24 +08:00
import prettier from "../../config/prettier-entry.js";
import fooPlugin from "../plugins/defaultOptions/plugin.cjs";
test("yaml parser should handle CRLF correctly", async () => {
const input = "a:\r\n 123\r\n";
expect(
// use JSON.stringify to observe CRLF
JSON.stringify(
await prettier.format(input, { parser: "yaml", endOfLine: "auto" }),
),
).toMatchSnapshot();
});
test("typescript parser should throw the first error when both JSX and non-JSX mode failed", async () => {
const input = outdent`
import React from "react";
const App = () => (
<div className="App">
</div>
);
label:
`;
await expect(
prettier.format(input, { parser: "typescript", filepath: "foo.unknown" }),
).rejects.toThrowErrorMatchingSnapshot();
});
2018-11-09 09:56:46 +08:00
test("html parser should handle CRLF correctly", async () => {
2018-11-09 09:56:46 +08:00
const input = "<!--\r\n test\r\n test\r\n-->";
expect(
// use JSON.stringify to observe CRLF
JSON.stringify(
await prettier.format(input, { parser: "html", endOfLine: "auto" }),
),
2018-11-09 09:56:46 +08:00
).toMatchSnapshot();
});
test("markdown parser should handle CRLF correctly", async () => {
const input = "```\r\n\r\n\r\n```";
expect(
// use JSON.stringify to observe CRLF
JSON.stringify(
await prettier.format(input, { parser: "markdown", endOfLine: "auto" }),
),
).toMatchSnapshot();
});
2019-01-18 22:40:18 +08:00
test("should work with foo plugin instance", async () => {
2019-01-18 22:40:18 +08:00
const input = "a:\r\n 123\r\n";
expect(
JSON.stringify(
await prettier.format(input, {
parser: "foo-parser",
plugins: [fooPlugin],
}),
2019-01-18 22:40:18 +08:00
),
).toMatchInlineSnapshot(
String.raw`""{\"tabWidth\":8,\"bracketSpacing\":false}""`,
);
2019-01-18 22:40:18 +08:00
});
test("'Adjacent JSX' error should not be swallowed by Babel's error recovery", async () => {
const input = "<a></a>\n<b></b>";
await expect(
2020-02-14 06:14:24 +08:00
prettier.format(input, { parser: "babel" }),
).rejects.toThrowErrorMatchingSnapshot();
});