Skip to content

Commit

Permalink
Ported test suite: check
Browse files Browse the repository at this point in the history
  • Loading branch information
fabiospampinato committed Sep 15, 2024
1 parent 41dc791 commit 3950236
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 0 deletions.
33 changes: 33 additions & 0 deletions test/__tests__/__snapshots__/check.js.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`--checks should print the number of files that need formatting (stderr) 1`] = `
"[warn] unformatted.js
[warn] unformatted2.js
[warn] Code style issues found in 2 files. Run Prettier with --write to fix."
`;

exports[`--checks should print the number of files that need formatting (stdout) 1`] = `"Checking formatting..."`;

exports[`--checks should print the number of files that need formatting (write) 1`] = `[]`;

exports[`--checks works in CI just as in a non-TTY mode (stderr) 1`] = `
"[warn] unformatted.js
[warn] Code style issues found in 1 file. Run Prettier with --write to fix."
`;

exports[`--checks works in CI just as in a non-TTY mode (stderr) 2`] = `
"[warn] unformatted.js
[warn] Code style issues found in 1 file. Run Prettier with --write to fix."
`;

exports[`--checks works in CI just as in a non-TTY mode (stdout) 1`] = `"Checking formatting..."`;

exports[`--checks works in CI just as in a non-TTY mode (stdout) 2`] = `"Checking formatting..."`;

exports[`--checks works in CI just as in a non-TTY mode (write) 1`] = `[]`;

exports[`--checks works in CI just as in a non-TTY mode (write) 2`] = `[]`;

exports[`checks stdin with --check (write) 1`] = `[]`;

exports[`checks stdin with -c (alias for --check) (write) 1`] = `[]`;
65 changes: 65 additions & 0 deletions test/__tests__/check.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import { runCli } from "../utils";

describe("checks stdin with --check", () => {
runCli("with-shebang", [
"--check",
"--parser",
"babel",
], {
input: "0",
}).test({
stdout: "(stdin)",
stderr: "",
status: "non-zero",
});
});

describe("checks stdin with -c (alias for --check)", () => {
runCli("with-shebang", [
"-c",
"--parser",
"babel",
], {
input: "0",
}).test({
stdout: "(stdin)",
stderr: "",
status: "non-zero",
});
});

describe("--checks works in CI just as in a non-TTY mode", () => {
const result0 = runCli("write", [
"--check",
"formatted.js",
"unformatted.js",
]).test({
status: 1,
});

const result1 = runCli("write", [
"--check",
"formatted.js",
"unformatted.js",
], {
tty: false, //TODO: actually implement this, read .isTTY via a env-mockable module
}).test({
status: 1,
});

test("Should have same stdout", async () => {
expect(await result0.stdout).toEqual(await result1.stdout);
});
});

describe("--checks should print the number of files that need formatting", () => {
runCli("write", [
"--check",
"unformatted.js",
"unformatted2.js",
], {
input: "0",
}).test({
status: 1,
});
});

0 comments on commit 3950236

Please sign in to comment.