Skip to content

Commit

Permalink
Integration test: Rename runPrettier to runCli (#14687)
Browse files Browse the repository at this point in the history
  • Loading branch information
fisker committed Apr 11, 2023
1 parent 578f093 commit fb948bb
Show file tree
Hide file tree
Showing 54 changed files with 359 additions and 433 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ module.exports = {
},
globals: {
run_spec: "readonly",
runPrettier: "readonly",
runCli: "readonly",
},
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
const selector = [
"CallExpression",
'[callee.type="Identifier"]',
'[callee.name="runPrettier"]',
'[callee.name="runCli"]',
].join("");

const MESSAGE_ID_CALL = "await-cli-tests/call";
Expand All @@ -16,9 +16,8 @@ module.exports = {
url: "https://github.com/prettier/prettier/blob/main/scripts/tools/eslint-plugin-prettier-internal-rules/await-cli-tests.js",
},
messages: {
[MESSAGE_ID_CALL]:
"'runPrettier()' should be awaited or calling `.test()`.",
[MESSAGE_ID_GETTER]: "'runPrettier().{{property}}' should be awaited.",
[MESSAGE_ID_CALL]: "'runCli()' should be awaited or calling `.test()`.",
[MESSAGE_ID_GETTER]: "'runCli().{{property}}' should be awaited.",
},
},
create(context) {
Expand Down
18 changes: 9 additions & 9 deletions scripts/tools/eslint-plugin-prettier-internal-rules/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,26 @@ const test = (ruleId, tests) => {

test("await-cli-tests", {
valid: [
"async () => await runPrettier()",
"runPrettier().test()",
"notRunPrettier()",
"async () => await runPrettier().stderr",
"async () => await runCli()",
"runCli().test()",
"notRunCli()",
"async () => await runCli().stderr",
outdent`
async () => {
const originalStdout = await runPrettier("plugins/options", ["--help"]).stdout;
const originalStdout = await runCli("plugins/options", ["--help"]).stdout;
}
`,
],
invalid: [
{
code: "runPrettier()",
code: "runCli()",
errors: [
{ message: "'runPrettier()' should be awaited or calling `.test()`." },
{ message: "'runCli()' should be awaited or calling `.test()`." },
],
},
{
code: "runPrettier().stderr",
errors: [{ message: "'runPrettier().stderr' should be awaited." }],
code: "runCli().stderr",
errors: [{ message: "'runCli().stderr' should be awaited." }],
},
],
});
Expand Down
22 changes: 11 additions & 11 deletions tests/integration/__tests__/arg-parsing.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
describe("boolean flags do not swallow the next argument", () => {
runPrettier("cli/arg-parsing", [
runCli("cli/arg-parsing", [
"--end-of-line",
"lf",
"--single-quote",
Expand All @@ -10,7 +10,7 @@ describe("boolean flags do not swallow the next argument", () => {
});

describe("negated options work", () => {
runPrettier("cli/arg-parsing", [
runCli("cli/arg-parsing", [
"--end-of-line",
"lf",
"--no-semi",
Expand All @@ -21,7 +21,7 @@ describe("negated options work", () => {
});

describe("unknown options are warned", () => {
runPrettier("cli/arg-parsing", [
runCli("cli/arg-parsing", [
"--end-of-line",
"lf",
"file.js",
Expand All @@ -32,7 +32,7 @@ describe("unknown options are warned", () => {
});

describe("unknown negated options are warned", () => {
runPrettier("cli/arg-parsing", [
runCli("cli/arg-parsing", [
"--end-of-line",
"lf",
"file.js",
Expand All @@ -43,14 +43,14 @@ describe("unknown negated options are warned", () => {
});

describe("unknown options not suggestion `_`", () => {
runPrettier("cli/arg-parsing", ["file.js", "-a"]).test({
runCli("cli/arg-parsing", ["file.js", "-a"]).test({
status: 0,
write: [],
});
});

describe("allow overriding flags", () => {
runPrettier(
runCli(
"cli/arg-parsing",
["--tab-width=1", "--tab-width=3", "--parser=babel"],
{ input: "function a() { b }" }
Expand All @@ -63,7 +63,7 @@ describe("allow overriding flags", () => {
describe("number file/dir", () => {
const patterns = ["1", "2.2", "3", "4.44"];
for (const pattern of patterns) {
runPrettier("cli/arg-parsing/number", [
runCli("cli/arg-parsing/number", [
"--parser=babel",
"--list-different",
pattern,
Expand All @@ -73,7 +73,7 @@ describe("number file/dir", () => {
write: [],
});
}
runPrettier("cli/arg-parsing/number", [
runCli("cli/arg-parsing/number", [
"--parser=babel",
"--list-different",
...patterns,
Expand All @@ -85,19 +85,19 @@ describe("number file/dir", () => {
});

describe("deprecated option values are warned", () => {
runPrettier("cli/arg-parsing", ["file.js", "--jsx-bracket-same-line"]).test({
runCli("cli/arg-parsing", ["file.js", "--jsx-bracket-same-line"]).test({
status: 0,
});
});

describe("options with `cliName` should not allow to pass directly", () => {
// `filepath` can only pass through `--stdin-filepath`
// `plugins` and `pluginSearchDirs` works the same
runPrettier("cli/arg-parsing", ["--stdin-filepath", "file.js"], {
runCli("cli/arg-parsing", ["--stdin-filepath", "file.js"], {
isTTY: false,
input: "prettier()",
}).test({ status: 0, stderr: "", write: [] });
runPrettier("cli/arg-parsing", ["--filepath", "file.js"], {
runCli("cli/arg-parsing", ["--filepath", "file.js"], {
isTTY: false,
input: "prettier()",
}).test({ status: 2, write: [] });
Expand Down

0 comments on commit fb948bb

Please sign in to comment.