Files
test-repo/tests/integration/__tests__/with-parser-inference.js
T
fisker Cheung e3cb487706 Merge branch 'main' into next
# Conflicts:
#	.eslintrc.cjs
#	package.json
#	src/language-yaml/index.js
#	yarn.lock
2022-07-11 17:03:30 +08:00

99 lines
2.4 KiB
JavaScript

import prettier from "prettier-local";
import { outdent } from "outdent";
describe("infers postcss parser", () => {
runPrettier("cli/with-parser-inference", ["--end-of-line", "lf", "*"]).test({
status: 0,
});
});
describe("infers postcss parser with --check", () => {
runPrettier("cli/with-parser-inference", ["--check", "*"]).test({
status: 0,
});
});
describe("infers postcss parser with --list-different", () => {
runPrettier("cli/with-parser-inference", ["--list-different", "*"]).test({
status: 0,
});
});
describe("infers parser from filename", () => {
test("json from .prettierrc", async () => {
expect(
await prettier.format(" { } ", { filepath: "x/y/.prettierrc" })
).toBe("{}\n");
});
test("json from .stylelintrc", async () => {
expect(
await prettier.format(" { } ", { filepath: "x/y/.stylelintrc" })
).toBe("{}\n");
});
test("yaml from .stylelintrc", async () => {
expect(
await prettier.format(" extends: '' ", {
filepath: "x/y/.stylelintrc",
})
).toBe('extends: ""\n');
});
test("babel from Jakefile", async () => {
expect(
await prettier.format("let foo = ( x = 1 ) => x", {
filepath: "x/y/Jakefile",
})
).toBe("let foo = (x = 1) => x;\n");
});
test("json from .swcrc", async () => {
expect(
await prettier.format(
/* indent */ `
{
"jsc": {
// Requires v1.2.50 or upper and requires target to be es2016 or upper.
"keepClassNames": false
}}
`,
{ filepath: "/path/to/.swcrc" }
)
).toBe(
outdent`
{
"jsc": {
// Requires v1.2.50 or upper and requires target to be es2016 or upper.
"keepClassNames": false
}
}
` + "\n"
);
});
test("json from .lintstagedrc", () => {
expect(
prettier.format(" { '*': 'your-cmd' } ", {
filepath: "/path/to/.lintstagedrc",
})
).toBe('{ "*": "your-cmd" }\n');
});
test("yaml from .lintstagedrc", () => {
expect(
prettier.format(
/* indent */ `
'*':
- your-cmd
`,
{ filepath: "/path/to/.lintstagedrc" }
)
).toBe(
outdent`
"*":
- your-cmd
` + "\n"
);
});
});