Skip to content

Commit 11afbb2

Browse files
43081jfabiospampinato
authored andcommitted
Ported test suite: early-exit
- Showing help text for flags is no longer supported. - All of "--check", "--write" and "--list-different" are considered incompatible with each other. - "--file-info", "--find-config-path" and "--support-info" are not supported anymore.
1 parent 724624f commit 11afbb2

2 files changed

Lines changed: 289 additions & 0 deletions

File tree

Lines changed: 205 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,205 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`show usage with --help (stderr) 1`] = `""`;
4+
5+
exports[`show usage with --help (stdout) 1`] = `
6+
"
7+
prettier 3.3.3
8+
9+
USAGE
10+
11+
prettier [file/dir/glob...] [options]
12+
prettier "src/**/*.js" --check
13+
prettier "src/**/*.js" -l --no-cache
14+
prettier "src/**/*.js" --write --no-parallel
15+
prettier ./path/to/target/file.js --cache-location ./path/to/cache/file.json
16+
17+
ARGUMENTS
18+
19+
[file/dir/glob...] Files, directories or globs to format
20+
21+
OUTPUT OPTIONS
22+
23+
--check, -c Check if the given files are formatted, print a human-friendly summary (see also --list-different)
24+
--list-different, -l Print the names of files that are different from Prettier's formatting (see also --check)
25+
--write, -w Edit files in-place (Beware!)
26+
27+
FORMAT OPTIONS
28+
29+
--arrow-parens <always|avoid>
30+
Include parentheses around a sole arrow function parameter
31+
Defaults to "always"
32+
--bracket-same-line Put ">" of opening tags on the last line instead of on a new line
33+
Defaults to "false"
34+
--no-bracket-spacing Do not print spaces between brackets
35+
Defaults to "true"
36+
--embedded-language-formatting <auto|off>
37+
Control how Prettier formats quoted code embedded in the file
38+
Defaults to "auto"
39+
--end-of-line <lf|crlf|cr|auto>
40+
Which end of line characters to apply
41+
Defaults to "lf"
42+
--experimental-ternaries
43+
Use curious ternaries, with the question mark after the condition
44+
Defaults to "false"
45+
--html-whitespace-sensitivity <css|strict|ignore>
46+
How to handle whitespaces in HTML
47+
Defaults to "css"
48+
--jsx-single-quote Use single quotes in JSX
49+
Defaults to "false"
50+
--parser <flow|babel|babel-flow|babel-ts|typescript|acorn|espree|meriyah|css|less|scss|json|json5|json-stringify|graphql|markdown|mdx|vue|yaml|glimmer|html|angular|lwc>
51+
Which parser to use
52+
--print-width <int> The line length where Prettier will try wrap
53+
Defaults to "80"
54+
--prose-wrap <always|never|preserve>
55+
How to wrap prose
56+
Defaults to "preserve"
57+
--quote-props <as-needed|consistent|preserve>
58+
Change when properties in objects are quoted
59+
Defaults to "as-needed"
60+
--no-semi Do not print semicolons, except at the beginning of lines which may need them
61+
Defaults to "true"
62+
--single-attribute-per-line
63+
Enforce single attribute per line in HTML, Vue and JSX
64+
Defaults to "false"
65+
--single-quote Use single quotes instead of double quotes
66+
Defaults to "false"
67+
--tab-width <int> Number of spaces per indentation level
68+
Defaults to "2"
69+
--trailing-comma <all|es5|none>
70+
Print trailing commas wherever possible when multi-line
71+
Defaults to "all"
72+
--use-tabs Indent with tabs instead of spaces
73+
Defaults to "false"
74+
--vue-indent-script-and-style
75+
Indent script and style tags in Vue files
76+
Defaults to "false"
77+
78+
CONFIG OPTIONS
79+
80+
--no-config Do not look for a configuration file
81+
--config-path <path> Path to a Prettier configuration file (.prettierrc, package.json, prettier.config.js)
82+
--config-precedence <cli-override|file-override>
83+
Define in which order config files and CLI options should be evaluated.
84+
Defaults to "cli-override"
85+
--no-editorconfig Don't take .editorconfig into account when parsing configuration
86+
--no-ignore Do not look for an ignore file
87+
--ignore-path <path...> Path to a file with patterns describing files to ignore
88+
Multiple values are accepted
89+
Defaults to [.gitignore, .prettierignore]
90+
--plugin <package...> Add a plugin
91+
Multiple plugins are accepted
92+
Defaults to []
93+
--with-node-modules Process files inside the "node_modules" directory
94+
95+
EDITOR OPTIONS
96+
97+
--cursor-offset <int> Print (to stderr) where a cursor at the given position would move to after formatting
98+
Defaults to "-1"
99+
--range-end <int> Format code ending at a given character offset (exclusive)
100+
The range will extend forwards to the end of the selected statement
101+
Defaults to "Infinity"
102+
--range-start <int> Format code starting at a given character offset
103+
The range will extend backwards to the start of the first line containing the selected statement
104+
Defaults to "0"
105+
106+
OTHER OPTIONS
107+
108+
--help Display help for the command
109+
--version, -v Display the version number
110+
--no-cache Do not use the built-in caching mechanism
111+
--cache-location <path> Path to the cache file
112+
--no-color Do not colorize output messages
113+
--no-error-on-unmatched-pattern
114+
Prevent errors when pattern is unmatched
115+
--ignore-unknown, -u Ignore unknown files
116+
--insert-pragma Insert @format pragma into file's first docblock comment
117+
Defaults to "false"
118+
--log-level <silent|error|warn|log|debug>
119+
What level of logs to report
120+
Defaults to "log"
121+
--no-parallel Process files in parallel
122+
Defaults to "true"
123+
--parallel-workers <int> Number of parallel workers to use
124+
Defaults to "0"
125+
--require-pragma Require either "@prettier" or "@format" to be present in the file's first docblock comment in order for it to be formatted
126+
Defaults to "false"
127+
--stdin-filepath <path> Path to the file to pretend that stdin comes from
128+
"
129+
`;
130+
131+
exports[`show usage with --help (write) 1`] = `[]`;
132+
133+
exports[`show version with --version (stderr) 1`] = `""`;
134+
135+
exports[`show version with --version (write) 1`] = `[]`;
136+
137+
exports[`throw error with --check + --list-different (stderr) 1`] = `
138+
"
139+
Incompatible options: "check" and "list-different" cannot be used together
140+
"
141+
`;
142+
143+
exports[`throw error with --check + --list-different (stdout) 1`] = `""`;
144+
145+
exports[`throw error with --check + --list-different (write) 1`] = `[]`;
146+
147+
exports[`throw error with --check + --write (stderr) 1`] = `
148+
"
149+
Incompatible options: "check" and "write" cannot be used together
150+
"
151+
`;
152+
153+
exports[`throw error with --check + --write (stdout) 1`] = `""`;
154+
155+
exports[`throw error with --check + --write (write) 1`] = `[]`;
156+
157+
exports[`throw error with --list-different + --write (stderr) 1`] = `
158+
"
159+
Incompatible options: "list-different" and "write" cannot be used together
160+
"
161+
`;
162+
163+
exports[`throw error with --list-different + --write (stdout) 1`] = `""`;
164+
165+
exports[`throw error with --list-different + --write (write) 1`] = `[]`;
166+
167+
exports[`throw error with something unexpected (stderr) 1`] = `
168+
"
169+
Expected at least one target file/dir/glob
170+
"
171+
`;
172+
173+
exports[`throw error with something unexpected (stdout) 1`] = `""`;
174+
175+
exports[`throw error with something unexpected (write) 1`] = `[]`;
176+
177+
exports[`throw unsupported error with --file-info (stderr) 1`] = `
178+
"
179+
The "--file-info" option is not currently supported, please open an issue on GitHub if you need it
180+
"
181+
`;
182+
183+
exports[`throw unsupported error with --file-info (stdout) 1`] = `""`;
184+
185+
exports[`throw unsupported error with --file-info (write) 1`] = `[]`;
186+
187+
exports[`throw unsupported error with --find-config-path (stderr) 1`] = `
188+
"
189+
Unknown option: "find-config-path"
190+
"
191+
`;
192+
193+
exports[`throw unsupported error with --find-config-path (stdout) 1`] = `""`;
194+
195+
exports[`throw unsupported error with --find-config-path (write) 1`] = `[]`;
196+
197+
exports[`throw unsupported error with --support-info (stderr) 1`] = `
198+
"
199+
The "--support-info" option is not currently supported, please open an issue on GitHub if you need it
200+
"
201+
`;
202+
203+
exports[`throw unsupported error with --support-info (stdout) 1`] = `""`;
204+
205+
exports[`throw unsupported error with --support-info (write) 1`] = `[]`;

test/__tests__/early-exit.js

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
import { runCli } from "../utils";
2+
import { PRETTIER_VERSION } from "../../dist/constants.js";
3+
4+
describe("show version with --version", () => {
5+
runCli("with-shebang", [
6+
"--version",
7+
]).test({
8+
stdout: PRETTIER_VERSION,
9+
status: 0,
10+
});
11+
});
12+
13+
describe("show usage with --help", () => {
14+
runCli("", [
15+
"--help",
16+
]).test({
17+
status: 0,
18+
});
19+
});
20+
21+
describe("throw error with --check + --list-different", () => {
22+
runCli("", [
23+
"--check",
24+
"--list-different",
25+
]).test({
26+
status: 1,
27+
});
28+
});
29+
30+
describe("throw error with --check + --write", () => {
31+
runCli("", [
32+
"--check",
33+
"--write",
34+
]).test({
35+
status: 1,
36+
});
37+
});
38+
39+
describe("throw error with --list-different + --write", () => {
40+
runCli("", [
41+
"--list-different",
42+
"--write",
43+
]).test({
44+
status: 1,
45+
});
46+
});
47+
48+
describe("throw unsupported error with --file-info", () => {
49+
runCli("", [
50+
"--file-info",
51+
"abc.js",
52+
"def.js",
53+
]).test({
54+
status: 1,
55+
});
56+
});
57+
58+
describe("throw unsupported error with --find-config-path", () => {
59+
runCli("", [
60+
"--find-config-path",
61+
"abc.js",
62+
"def.js",
63+
]).test({
64+
status: 1,
65+
});
66+
});
67+
68+
describe("throw unsupported error with --support-info", () => {
69+
runCli("", [
70+
"--support-info",
71+
"abc.js",
72+
"def.js",
73+
]).test({
74+
status: 1,
75+
});
76+
});
77+
78+
describe("throw error with something unexpected", () => {
79+
runCli("", [], {
80+
isTTY: true,
81+
}).test({
82+
status: "non-zero",
83+
});
84+
});

0 commit comments

Comments
 (0)