Files
test-repo/tests/integration/__tests__/format.js
T
fisker Cheung a85f38f096 Merge branch 'main' into next
# Conflicts:
#	.github/workflows/dev-test.yml
#	jest.config.mjs
#	package.json
#	scripts/vendors/vendor-meta.json
#	scripts/vendors/vendors.mjs
#	src/cli/format.js
#	src/cli/options/create-minimist-options.js
#	src/cli/options/parse-cli-arguments.js
#	src/cli/usage.js
#	src/cli/utils.js
#	src/common/create-ignorer.js
#	src/common/load-plugins.js
#	src/config/resolve-config.js
#	src/index.js
#	src/language-css/utils/css-units.evaluate.js
#	src/language-html/ast.js
#	src/language-html/print-preprocess.js
#	src/language-html/utils/index.js
#	src/main/multiparser.js
#	tests/format/markdown/auto-link/jsfmt.spec.js
#	tests/integration/__tests__/__snapshots__/config-resolution.js.snap
#	tests/integration/__tests__/__snapshots__/with-config-precedence.js.snap
#	tests/integration/__tests__/file-info.js
#	yarn.lock
2022-04-25 14:28:27 +08:00

66 lines
1.8 KiB
JavaScript

import prettier from "prettier-local";
import { outdent } from "outdent";
import fooPlugin from "../plugins/defaultOptions/plugin.cjs";
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();
});