forked from prettier/prettier
/
early-exit.js
114 lines (99 loc) · 2.66 KB
/
early-exit.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
"use strict";
const prettier = require("prettier-local");
const runPrettier = require("../runPrettier");
describe("show version with --version", () => {
runPrettier("cli/with-shebang", ["--version"]).test({
stdout: prettier.version + "\n",
status: 0,
});
});
describe("show usage with --help", () => {
runPrettier("cli", ["--help"]).test({
status: 0,
});
});
describe("show detailed usage with --help l (alias)", () => {
runPrettier("cli", ["--help", "l"]).test({
status: 0,
});
});
describe("show detailed usage with plugin options (automatic resolution)", () => {
runPrettier("plugins/automatic", [
"--help",
"tab-width",
"--parser=bar",
"--plugin-search-dir=.",
]).test({
status: 0,
});
});
describe("show detailed usage with plugin options (manual resolution)", () => {
runPrettier("cli", [
"--help",
"tab-width",
"--plugin=../plugins/automatic/node_modules/prettier-plugin-bar",
"--parser=bar",
]).test({
status: 0,
});
});
describe("throw error with --help not-found", () => {
runPrettier("cli", ["--help", "not-found"]).test({
status: 1,
});
});
describe("show warning with --help not-found (typo)", () => {
runPrettier("cli", [
"--help",
// cspell:disable-next-line
"parserr",
]).test({
status: 0,
});
});
describe("throw error with --check + --list-different", () => {
runPrettier("cli", ["--check", "--list-different"]).test({
status: 1,
});
});
describe("throw error with --write + --debug-check", () => {
runPrettier("cli", ["--write", "--debug-check"]).test({
status: 1,
});
});
describe("throw error with --find-config-path + multiple files", () => {
runPrettier("cli", ["--find-config-path", "abc.js", "def.js"]).test({
status: 1,
});
});
describe("throw error with --file-info + multiple files", () => {
runPrettier("cli", ["--file-info", "abc.js", "def.js"]).test({
status: 1,
});
});
describe("throw error and show usage with something unexpected", () => {
runPrettier("cli", [], { isTTY: true }).test({
status: "non-zero",
});
});
test("node version error", async () => {
const originalProcessVersion = process.version;
try {
Object.defineProperty(process, "version", {
value: "v8.0.0",
writable: false,
});
const result = runPrettier("cli", ["--help"]);
expect(await result.status).toEqual(1);
const snapshot = {};
for (const name of ["stderr", "stdout", "write"]) {
snapshot[name] = await result[name];
}
expect(snapshot).toMatchSnapshot();
} finally {
Object.defineProperty(process, "version", {
value: originalProcessVersion,
writable: false,
});
}
});