test(integration): update title and catch all outputs (#2951)

master
Ika 2017-10-02 11:08:34 -05:00 committed by Simon Lydell
parent 43cb08c45c
commit 7770356a51
41 changed files with 876 additions and 554 deletions

View File

@ -1,57 +1,69 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP // Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`boolean flags do not swallow the next argument 1`] = ` exports[`boolean flags do not swallow the next argument (stderr) 1`] = `""`;
exports[`boolean flags do not swallow the next argument (stdout) 1`] = `
"console.log('could be single quote and without semi'); "console.log('could be single quote and without semi');
" "
`; `;
exports[`boolean flags do not swallow the next argument 2`] = `""`; exports[`boolean flags do not swallow the next argument (write) 1`] = `Array []`;
exports[`deprecated option values are warned 1`] = ` exports[`deprecated option values are warned (stderr) 1`] = `
"console.log(\\"could be single quote and without semi\\");
"
`;
exports[`deprecated option values are warned 2`] = `
"\`--trailing-comma\` without an argument is deprecated. Prettier now treats it as: \`--trailing-comma=es5\`. "\`--trailing-comma\` without an argument is deprecated. Prettier now treats it as: \`--trailing-comma=es5\`.
" "
`; `;
exports[`deprecated options are warned 1`] = ` exports[`deprecated option values are warned (stdout) 1`] = `
"console.log(\\"could be single quote and without semi\\"); "console.log(\\"could be single quote and without semi\\");
" "
`; `;
exports[`deprecated options are warned 2`] = ` exports[`deprecated option values are warned (write) 1`] = `Array []`;
exports[`deprecated options are warned (stderr) 1`] = `
"\`--flow-parser\` is deprecated. Use \`--parser flow\` instead. "\`--flow-parser\` is deprecated. Use \`--parser flow\` instead.
" "
`; `;
exports[`negated options work 1`] = ` exports[`deprecated options are warned (stdout) 1`] = `
"console.log(\\"could be single quote and without semi\\")
"
`;
exports[`negated options work 2`] = `""`;
exports[`unknown negated options are warned 1`] = `
"console.log(\\"could be single quote and without semi\\"); "console.log(\\"could be single quote and without semi\\");
" "
`; `;
exports[`unknown negated options are warned 2`] = ` exports[`deprecated options are warned (write) 1`] = `Array []`;
exports[`negated options work (stderr) 1`] = `""`;
exports[`negated options work (stdout) 1`] = `
"console.log(\\"could be single quote and without semi\\")
"
`;
exports[`negated options work (write) 1`] = `Array []`;
exports[`unknown negated options are warned (stderr) 1`] = `
"Ignored unknown option: --no-unknown "Ignored unknown option: --no-unknown
" "
`; `;
exports[`unknown options are warned 1`] = ` exports[`unknown negated options are warned (stdout) 1`] = `
"console.log(\\"could be single quote and without semi\\"); "console.log(\\"could be single quote and without semi\\");
" "
`; `;
exports[`unknown options are warned 2`] = ` exports[`unknown negated options are warned (write) 1`] = `Array []`;
exports[`unknown options are warned (stderr) 1`] = `
"Ignored unknown option: --unknown "Ignored unknown option: --unknown
" "
`; `;
exports[`unknown options are warned (stdout) 1`] = `
"console.log(\\"could be single quote and without semi\\");
"
`;
exports[`unknown options are warned (write) 1`] = `Array []`;

View File

@ -1,33 +1,57 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP // Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`show warning with unknown option 1`] = ` exports[`show warning with unknown option (stderr) 1`] = `
"Ignored unknown option: hello "Ignored unknown option: hello
" "
`; `;
exports[`throw error with invalid config format 1`] = ` exports[`show warning with unknown option (stdout) 1`] = `""`;
exports[`show warning with unknown option (write) 1`] = `Array []`;
exports[`throw error with invalid config format (stderr) 1`] = `
"Error: Invalid configuration file. "Error: Invalid configuration file.
Failed to parse \\"<cwd>/tests_integration/cli/config/invalid/file/.prettierrc\\" as JSON, JS, or YAML. Failed to parse \\"<cwd>/tests_integration/cli/config/invalid/file/.prettierrc\\" as JSON, JS, or YAML.
" "
`; `;
exports[`throw error with invalid config option (int) 1`] = ` exports[`throw error with invalid config format (stdout) 1`] = `""`;
exports[`throw error with invalid config format (write) 1`] = `Array []`;
exports[`throw error with invalid config option (int) (stderr) 1`] = `
"Invalid tabWidth value. "Invalid tabWidth value.
Expected an integer, but received: 0.5" Expected an integer, but received: 0.5"
`; `;
exports[`throw error with invalid config option (trailingComma) 1`] = ` exports[`throw error with invalid config option (int) (stdout) 1`] = `""`;
exports[`throw error with invalid config option (int) (write) 1`] = `Array []`;
exports[`throw error with invalid config option (trailingComma) (stderr) 1`] = `
"Invalid option for trailingComma. "Invalid option for trailingComma.
Expected \\"none\\", \\"es5\\" or \\"all\\", but received: \\"wow\\"" Expected \\"none\\", \\"es5\\" or \\"all\\", but received: \\"wow\\""
`; `;
exports[`throw error with invalid config precedence option (configPrecedence) 1`] = ` exports[`throw error with invalid config option (trailingComma) (stdout) 1`] = `""`;
exports[`throw error with invalid config option (trailingComma) (write) 1`] = `Array []`;
exports[`throw error with invalid config precedence option (configPrecedence) (stderr) 1`] = `
"Invalid option for --config-precedence. "Invalid option for --config-precedence.
Expected \\"cli-override\\", \\"file-override\\" or \\"prefer-file\\", but received: \\"option/configPrecedence\\"" Expected \\"cli-override\\", \\"file-override\\" or \\"prefer-file\\", but received: \\"option/configPrecedence\\""
`; `;
exports[`throw error with invalid config target (directory) 1`] = ` exports[`throw error with invalid config precedence option (configPrecedence) (stdout) 1`] = `""`;
exports[`throw error with invalid config precedence option (configPrecedence) (write) 1`] = `Array []`;
exports[`throw error with invalid config target (directory) (stderr) 1`] = `
"Error: Invalid configuration file. "Error: Invalid configuration file.
EISDIR: illegal operation on a directory, read EISDIR: illegal operation on a directory, read
" "
`; `;
exports[`throw error with invalid config target (directory) (stdout) 1`] = `""`;
exports[`throw error with invalid config target (directory) (write) 1`] = `Array []`;

View File

@ -1,6 +1,8 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP // Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`CLI overrides take precedence 1`] = ` exports[`CLI overrides take precedence (stderr) 1`] = `""`;
exports[`CLI overrides take precedence (stdout) 1`] = `
"console.log( "console.log(
\\"jest/__best-tests__/file.js should have semi\\" \\"jest/__best-tests__/file.js should have semi\\"
); );
@ -53,19 +55,35 @@ function rcYaml() {
" "
`; `;
exports[`accepts configuration from --config 1`] = ` exports[`CLI overrides take precedence (write) 1`] = `Array []`;
exports[`accepts configuration from --config (stderr) 1`] = `""`;
exports[`accepts configuration from --config (stdout) 1`] = `
"function js() { "function js() {
console.log(\\"js/file.js should have tab width 8\\") console.log(\\"js/file.js should have tab width 8\\")
} }
" "
`; `;
exports[`resolves configuration file with --find-config-path file 1`] = ` exports[`accepts configuration from --config (write) 1`] = `Array []`;
exports[`prints nothing when no file found with --find-config-path (stderr) 1`] = `""`;
exports[`prints nothing when no file found with --find-config-path (write) 1`] = `Array []`;
exports[`resolves configuration file with --find-config-path file (stderr) 1`] = `""`;
exports[`resolves configuration file with --find-config-path file (stdout) 1`] = `
".prettierrc ".prettierrc
" "
`; `;
exports[`resolves configuration from external files 1`] = ` exports[`resolves configuration file with --find-config-path file (write) 1`] = `Array []`;
exports[`resolves configuration from external files (stderr) 1`] = `""`;
exports[`resolves configuration from external files (stdout) 1`] = `
"console.log(\\"jest/__best-tests__/file.js should have semi\\"); "console.log(\\"jest/__best-tests__/file.js should have semi\\");
console.log(\\"jest/Component.js should not have semi\\") console.log(\\"jest/Component.js should not have semi\\")
console.log(\\"jest/Component.test.js should have semi\\"); console.log(\\"jest/Component.test.js should have semi\\");
@ -100,7 +118,11 @@ function rcYaml() {
" "
`; `;
exports[`resolves configuration from external files and overrides by extname 1`] = ` exports[`resolves configuration from external files (write) 1`] = `Array []`;
exports[`resolves configuration from external files and overrides by extname (stderr) 1`] = `""`;
exports[`resolves configuration from external files and overrides by extname (stdout) 1`] = `
"function noConfigTs() { "function noConfigTs() {
console.log( console.log(
\\"no-config/file.ts should have semicolons because it has a .ts extension\\" \\"no-config/file.ts should have semicolons because it has a .ts extension\\"
@ -114,12 +136,22 @@ function packageTs() {
" "
`; `;
exports[`resolves json configuration file with --find-config-path file 1`] = ` exports[`resolves configuration from external files and overrides by extname (write) 1`] = `Array []`;
exports[`resolves json configuration file with --find-config-path file (stderr) 1`] = `""`;
exports[`resolves json configuration file with --find-config-path file (stdout) 1`] = `
"rc-json/.prettierrc.json "rc-json/.prettierrc.json
" "
`; `;
exports[`resolves yaml configuration file with --find-config-path file 1`] = ` exports[`resolves json configuration file with --find-config-path file (write) 1`] = `Array []`;
exports[`resolves yaml configuration file with --find-config-path file (stderr) 1`] = `""`;
exports[`resolves yaml configuration file with --find-config-path file (stdout) 1`] = `
"rc-yaml/.prettierrc.yaml "rc-yaml/.prettierrc.yaml
" "
`; `;
exports[`resolves yaml configuration file with --find-config-path file (write) 1`] = `Array []`;

View File

@ -1,11 +1,13 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP // Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`write cursorOffset to stderr with --cursor-offset <int> 1`] = ` exports[`write cursorOffset to stderr with --cursor-offset <int> (stderr) 1`] = `
"1
"
`;
exports[`write cursorOffset to stderr with --cursor-offset <int> (stdout) 1`] = `
"1; "1;
" "
`; `;
exports[`write cursorOffset to stderr with --cursor-offset <int> 2`] = ` exports[`write cursorOffset to stderr with --cursor-offset <int> (write) 1`] = `Array []`;
"1
"
`;

View File

@ -0,0 +1,5 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`checks stdin with --debug-check (write) 1`] = `Array []`;
exports[`doesn't crash when --debug-check is passed (write) 1`] = `Array []`;

View File

@ -0,0 +1,3 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`prints doc with --debug-print-doc (write) 1`] = `Array []`;

View File

@ -1,6 +1,8 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP // Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`show detailed usage with --help bracket-spacing 1`] = ` exports[`show detailed usage with --help bracket-spacing (stderr) 1`] = `""`;
exports[`show detailed usage with --help bracket-spacing (stdout) 1`] = `
"--bracket-spacing "--bracket-spacing
Print spaces between brackets. Print spaces between brackets.
@ -9,7 +11,11 @@ Default: true
" "
`; `;
exports[`show detailed usage with --help color 1`] = ` exports[`show detailed usage with --help bracket-spacing (write) 1`] = `Array []`;
exports[`show detailed usage with --help color (stderr) 1`] = `""`;
exports[`show detailed usage with --help color (stdout) 1`] = `
"--color "--color
Colorize error messages. Colorize error messages.
@ -18,14 +24,22 @@ Default: true
" "
`; `;
exports[`show detailed usage with --help config 1`] = ` exports[`show detailed usage with --help color (write) 1`] = `Array []`;
exports[`show detailed usage with --help config (stderr) 1`] = `""`;
exports[`show detailed usage with --help config (stdout) 1`] = `
"--config <path> "--config <path>
Path to a Prettier configuration file (.prettierrc, package.json, prettier.config.js). Path to a Prettier configuration file (.prettierrc, package.json, prettier.config.js).
" "
`; `;
exports[`show detailed usage with --help config-precedence 1`] = ` exports[`show detailed usage with --help config (write) 1`] = `Array []`;
exports[`show detailed usage with --help config-precedence (stderr) 1`] = `""`;
exports[`show detailed usage with --help config-precedence (stdout) 1`] = `
"--config-precedence <cli-override|file-override|prefer-file> "--config-precedence <cli-override|file-override|prefer-file>
Define in which order config files and CLI options should be evaluated. Define in which order config files and CLI options should be evaluated.
@ -41,7 +55,11 @@ Default: cli-override
" "
`; `;
exports[`show detailed usage with --help cursor-offset 1`] = ` exports[`show detailed usage with --help config-precedence (write) 1`] = `Array []`;
exports[`show detailed usage with --help cursor-offset (stderr) 1`] = `""`;
exports[`show detailed usage with --help cursor-offset (stdout) 1`] = `
"--cursor-offset <int> "--cursor-offset <int>
Print (to stderr) where a cursor at the given position would move to after formatting. Print (to stderr) where a cursor at the given position would move to after formatting.
@ -51,14 +69,22 @@ Default: -1
" "
`; `;
exports[`show detailed usage with --help find-config-path 1`] = ` exports[`show detailed usage with --help cursor-offset (write) 1`] = `Array []`;
exports[`show detailed usage with --help find-config-path (stderr) 1`] = `""`;
exports[`show detailed usage with --help find-config-path (stdout) 1`] = `
"--find-config-path <path> "--find-config-path <path>
Find and print the path to a configuration file for the given input file. Find and print the path to a configuration file for the given input file.
" "
`; `;
exports[`show detailed usage with --help help 1`] = ` exports[`show detailed usage with --help find-config-path (write) 1`] = `Array []`;
exports[`show detailed usage with --help help (stderr) 1`] = `""`;
exports[`show detailed usage with --help help (stdout) 1`] = `
"-h, --help <flag> "-h, --help <flag>
Show CLI usage, or details about the given flag. Show CLI usage, or details about the given flag.
@ -66,7 +92,11 @@ exports[`show detailed usage with --help help 1`] = `
" "
`; `;
exports[`show detailed usage with --help ignore-path 1`] = ` exports[`show detailed usage with --help help (write) 1`] = `Array []`;
exports[`show detailed usage with --help ignore-path (stderr) 1`] = `""`;
exports[`show detailed usage with --help ignore-path (stdout) 1`] = `
"--ignore-path <path> "--ignore-path <path>
Path to a file with patterns describing files to ignore. Path to a file with patterns describing files to ignore.
@ -75,7 +105,11 @@ Default: .prettierignore
" "
`; `;
exports[`show detailed usage with --help jsx-bracket-same-line 1`] = ` exports[`show detailed usage with --help ignore-path (write) 1`] = `Array []`;
exports[`show detailed usage with --help jsx-bracket-same-line (stderr) 1`] = `""`;
exports[`show detailed usage with --help jsx-bracket-same-line (stdout) 1`] = `
"--jsx-bracket-same-line "--jsx-bracket-same-line
Put > on the last line instead of at a new line. Put > on the last line instead of at a new line.
@ -84,49 +118,77 @@ Default: false
" "
`; `;
exports[`show detailed usage with --help l (alias) 1`] = ` exports[`show detailed usage with --help jsx-bracket-same-line (write) 1`] = `Array []`;
exports[`show detailed usage with --help l (alias) (stderr) 1`] = `""`;
exports[`show detailed usage with --help l (alias) (stdout) 1`] = `
"-l, --list-different "-l, --list-different
Print the names of files that are different from Prettier's formatting. Print the names of files that are different from Prettier's formatting.
" "
`; `;
exports[`show detailed usage with --help list-different 1`] = ` exports[`show detailed usage with --help l (alias) (write) 1`] = `Array []`;
exports[`show detailed usage with --help list-different (stderr) 1`] = `""`;
exports[`show detailed usage with --help list-different (stdout) 1`] = `
"-l, --list-different "-l, --list-different
Print the names of files that are different from Prettier's formatting. Print the names of files that are different from Prettier's formatting.
" "
`; `;
exports[`show detailed usage with --help no-bracket-spacing 1`] = ` exports[`show detailed usage with --help list-different (write) 1`] = `Array []`;
exports[`show detailed usage with --help no-bracket-spacing (stderr) 1`] = `""`;
exports[`show detailed usage with --help no-bracket-spacing (stdout) 1`] = `
"--no-bracket-spacing "--no-bracket-spacing
Do not print spaces between brackets. Do not print spaces between brackets.
" "
`; `;
exports[`show detailed usage with --help no-color 1`] = ` exports[`show detailed usage with --help no-bracket-spacing (write) 1`] = `Array []`;
exports[`show detailed usage with --help no-color (stderr) 1`] = `""`;
exports[`show detailed usage with --help no-color (stdout) 1`] = `
"--no-color "--no-color
Do not colorize error messages. Do not colorize error messages.
" "
`; `;
exports[`show detailed usage with --help no-config 1`] = ` exports[`show detailed usage with --help no-color (write) 1`] = `Array []`;
exports[`show detailed usage with --help no-config (stderr) 1`] = `""`;
exports[`show detailed usage with --help no-config (stdout) 1`] = `
"--no-config "--no-config
Do not look for a configuration file. Do not look for a configuration file.
" "
`; `;
exports[`show detailed usage with --help no-semi 1`] = ` exports[`show detailed usage with --help no-config (write) 1`] = `Array []`;
exports[`show detailed usage with --help no-semi (stderr) 1`] = `""`;
exports[`show detailed usage with --help no-semi (stdout) 1`] = `
"--no-semi "--no-semi
Do not print semicolons, except at the beginning of lines which may need them. Do not print semicolons, except at the beginning of lines which may need them.
" "
`; `;
exports[`show detailed usage with --help parser 1`] = ` exports[`show detailed usage with --help no-semi (write) 1`] = `Array []`;
exports[`show detailed usage with --help parser (stderr) 1`] = `""`;
exports[`show detailed usage with --help parser (stdout) 1`] = `
"--parser <flow|babylon|typescript|css|less|scss|json|graphql> "--parser <flow|babylon|typescript|css|less|scss|json|graphql>
Which parser to use. Which parser to use.
@ -146,7 +208,11 @@ Default: babylon
" "
`; `;
exports[`show detailed usage with --help print-width 1`] = ` exports[`show detailed usage with --help parser (write) 1`] = `Array []`;
exports[`show detailed usage with --help print-width (stderr) 1`] = `""`;
exports[`show detailed usage with --help print-width (stdout) 1`] = `
"--print-width <int> "--print-width <int>
The line length where Prettier will try wrap. The line length where Prettier will try wrap.
@ -155,7 +221,11 @@ Default: 80
" "
`; `;
exports[`show detailed usage with --help range-end 1`] = ` exports[`show detailed usage with --help print-width (write) 1`] = `Array []`;
exports[`show detailed usage with --help range-end (stderr) 1`] = `""`;
exports[`show detailed usage with --help range-end (stdout) 1`] = `
"--range-end <int> "--range-end <int>
Format code ending at a given character offset (exclusive). Format code ending at a given character offset (exclusive).
@ -166,7 +236,11 @@ Default: Infinity
" "
`; `;
exports[`show detailed usage with --help range-start 1`] = ` exports[`show detailed usage with --help range-end (write) 1`] = `Array []`;
exports[`show detailed usage with --help range-start (stderr) 1`] = `""`;
exports[`show detailed usage with --help range-start (stdout) 1`] = `
"--range-start <int> "--range-start <int>
Format code starting at a given character offset. Format code starting at a given character offset.
@ -177,7 +251,11 @@ Default: 0
" "
`; `;
exports[`show detailed usage with --help require-pragma 1`] = ` exports[`show detailed usage with --help range-start (write) 1`] = `Array []`;
exports[`show detailed usage with --help require-pragma (stderr) 1`] = `""`;
exports[`show detailed usage with --help require-pragma (stdout) 1`] = `
"--require-pragma "--require-pragma
Require either '@prettier' or '@format' to be present in the file's first docblock comment Require either '@prettier' or '@format' to be present in the file's first docblock comment
@ -187,7 +265,11 @@ Default: false
" "
`; `;
exports[`show detailed usage with --help semi 1`] = ` exports[`show detailed usage with --help require-pragma (write) 1`] = `Array []`;
exports[`show detailed usage with --help semi (stderr) 1`] = `""`;
exports[`show detailed usage with --help semi (stdout) 1`] = `
"--semi "--semi
Print semicolons. Print semicolons.
@ -196,7 +278,11 @@ Default: true
" "
`; `;
exports[`show detailed usage with --help single-quote 1`] = ` exports[`show detailed usage with --help semi (write) 1`] = `Array []`;
exports[`show detailed usage with --help single-quote (stderr) 1`] = `""`;
exports[`show detailed usage with --help single-quote (stdout) 1`] = `
"--single-quote "--single-quote
Use single quotes instead of double quotes. Use single quotes instead of double quotes.
@ -205,21 +291,33 @@ Default: false
" "
`; `;
exports[`show detailed usage with --help stdin 1`] = ` exports[`show detailed usage with --help single-quote (write) 1`] = `Array []`;
exports[`show detailed usage with --help stdin (stderr) 1`] = `""`;
exports[`show detailed usage with --help stdin (stdout) 1`] = `
"--stdin "--stdin
Force reading input from stdin. Force reading input from stdin.
" "
`; `;
exports[`show detailed usage with --help stdin-filepath 1`] = ` exports[`show detailed usage with --help stdin (write) 1`] = `Array []`;
exports[`show detailed usage with --help stdin-filepath (stderr) 1`] = `""`;
exports[`show detailed usage with --help stdin-filepath (stdout) 1`] = `
"--stdin-filepath <path> "--stdin-filepath <path>
Path to the file to pretend that stdin comes from. Path to the file to pretend that stdin comes from.
" "
`; `;
exports[`show detailed usage with --help tab-width 1`] = ` exports[`show detailed usage with --help stdin-filepath (write) 1`] = `Array []`;
exports[`show detailed usage with --help tab-width (stderr) 1`] = `""`;
exports[`show detailed usage with --help tab-width (stdout) 1`] = `
"--tab-width <int> "--tab-width <int>
Number of spaces per indentation level. Number of spaces per indentation level.
@ -228,7 +326,11 @@ Default: 2
" "
`; `;
exports[`show detailed usage with --help trailing-comma 1`] = ` exports[`show detailed usage with --help tab-width (write) 1`] = `Array []`;
exports[`show detailed usage with --help trailing-comma (stderr) 1`] = `""`;
exports[`show detailed usage with --help trailing-comma (stdout) 1`] = `
"--trailing-comma <none|es5|all> "--trailing-comma <none|es5|all>
Print trailing commas wherever possible when multi-line. Print trailing commas wherever possible when multi-line.
@ -243,7 +345,11 @@ Default: none
" "
`; `;
exports[`show detailed usage with --help use-tabs 1`] = ` exports[`show detailed usage with --help trailing-comma (write) 1`] = `Array []`;
exports[`show detailed usage with --help use-tabs (stderr) 1`] = `""`;
exports[`show detailed usage with --help use-tabs (stdout) 1`] = `
"--use-tabs "--use-tabs
Indent with tabs instead of spaces. Indent with tabs instead of spaces.
@ -252,28 +358,44 @@ Default: false
" "
`; `;
exports[`show detailed usage with --help version 1`] = ` exports[`show detailed usage with --help use-tabs (write) 1`] = `Array []`;
exports[`show detailed usage with --help version (stderr) 1`] = `""`;
exports[`show detailed usage with --help version (stdout) 1`] = `
"-v, --version "-v, --version
Print Prettier version. Print Prettier version.
" "
`; `;
exports[`show detailed usage with --help with-node-modules 1`] = ` exports[`show detailed usage with --help version (write) 1`] = `Array []`;
exports[`show detailed usage with --help with-node-modules (stderr) 1`] = `""`;
exports[`show detailed usage with --help with-node-modules (stdout) 1`] = `
"--with-node-modules "--with-node-modules
Process files inside 'node_modules' directory. Process files inside 'node_modules' directory.
" "
`; `;
exports[`show detailed usage with --help write 1`] = ` exports[`show detailed usage with --help with-node-modules (write) 1`] = `Array []`;
exports[`show detailed usage with --help write (stderr) 1`] = `""`;
exports[`show detailed usage with --help write (stdout) 1`] = `
"--write "--write
Edit files in-place. (Beware!) Edit files in-place. (Beware!)
" "
`; `;
exports[`show usage with --help 1`] = ` exports[`show detailed usage with --help write (write) 1`] = `Array []`;
exports[`show usage with --help (stderr) 1`] = `""`;
exports[`show usage with --help (stdout) 1`] = `
"Usage: prettier [options] [file/glob ...] "Usage: prettier [options] [file/glob ...]
By default, output is written to stdout. By default, output is written to stdout.
@ -348,7 +470,33 @@ Other options:
" "
`; `;
exports[`show warning with --help not-found (typo) 1`] = ` exports[`show usage with --help (write) 1`] = `Array []`;
exports[`show version with --version (stderr) 1`] = `""`;
exports[`show version with --version (write) 1`] = `Array []`;
exports[`show warning with --help not-found (stderr) 1`] = `
"Unknown option name \\"not-found\\"
"
`;
exports[`show warning with --help not-found (stdout) 1`] = `
"-h, --help <flag>
Show CLI usage, or details about the given flag.
Example: --help write
"
`;
exports[`show warning with --help not-found (typo) (stderr) 1`] = `
"Unknown option name \\"parserr\\", did you mean \\"parser\\"?
"
`;
exports[`show warning with --help not-found (typo) (stdout) 1`] = `
"--parser <flow|babylon|typescript|css|less|scss|json|graphql> "--parser <flow|babylon|typescript|css|less|scss|json|graphql>
Which parser to use. Which parser to use.
@ -368,27 +516,13 @@ Default: babylon
" "
`; `;
exports[`show warning with --help not-found (typo) 2`] = ` exports[`show warning with --help not-found (typo) (write) 1`] = `Array []`;
"Unknown option name \\"parserr\\", did you mean \\"parser\\"?
" exports[`show warning with --help not-found (write) 1`] = `Array []`;
`;
exports[`show warning with --help not-found 1`] = ` exports[`throw error and show usage with something unexpected (stderr) 1`] = `""`;
"-h, --help <flag>
Show CLI usage, or details about the given flag. exports[`throw error and show usage with something unexpected (stdout) 1`] = `
Example: --help write
"
`;
exports[`show warning with --help not-found 2`] = `
"Unknown option name \\"not-found\\"
"
`;
exports[`throw error and show usage with something unexpected 1`] = `
"Usage: prettier [options] [file/glob ...] "Usage: prettier [options] [file/glob ...]
By default, output is written to stdout. By default, output is written to stdout.
@ -463,14 +597,22 @@ Other options:
" "
`; `;
exports[`throw error and show usage with something unexpected 2`] = `""`; exports[`throw error and show usage with something unexpected (write) 1`] = `Array []`;
exports[`throw error with --find-config-path + multiple files 1`] = ` exports[`throw error with --find-config-path + multiple files (stderr) 1`] = `
"Cannot use --find-config-path with multiple files "Cannot use --find-config-path with multiple files
" "
`; `;
exports[`throw error with --write + --debug-check 1`] = ` exports[`throw error with --find-config-path + multiple files (stdout) 1`] = `""`;
exports[`throw error with --find-config-path + multiple files (write) 1`] = `Array []`;
exports[`throw error with --write + --debug-check (stderr) 1`] = `
"Cannot use --write and --debug-check together. "Cannot use --write and --debug-check together.
" "
`; `;
exports[`throw error with --write + --debug-check (stdout) 1`] = `""`;
exports[`throw error with --write + --debug-check (write) 1`] = `Array []`;

View File

@ -1,6 +1,10 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP // Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`support absolute filename 1`] = ` exports[`support absolute filename (stderr) 1`] = `""`;
exports[`support absolute filename (stdout) 1`] = `
"regular-module.js "regular-module.js
" "
`; `;
exports[`support absolute filename (write) 1`] = `Array []`;

View File

@ -1,11 +1,19 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP // Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`ignore path 1`] = ` exports[`ignore path (stderr) 1`] = `""`;
exports[`ignore path (stdout) 1`] = `
"regular-module.js "regular-module.js
" "
`; `;
exports[`support .prettierignore 1`] = ` exports[`ignore path (write) 1`] = `Array []`;
exports[`support .prettierignore (stderr) 1`] = `""`;
exports[`support .prettierignore (stdout) 1`] = `
"other-regular-modules.js "other-regular-modules.js
" "
`; `;
exports[`support .prettierignore (write) 1`] = `Array []`;

View File

@ -1,6 +1,10 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP // Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`throw error with invalid ignore 1`] = ` exports[`throw error with invalid ignore (stderr) 1`] = `
"Unable to read <cwd>/tests_integration/cli/invalid-ignore/.prettierignore: "Unable to read <cwd>/tests_integration/cli/invalid-ignore/.prettierignore:
" "
`; `;
exports[`throw error with invalid ignore (stdout) 1`] = `""`;
exports[`throw error with invalid ignore (write) 1`] = `Array []`;

View File

@ -0,0 +1,3 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`checks stdin with --list-different (write) 1`] = `Array []`;

View File

@ -1,6 +1,8 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP // Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`multiple patterns 1`] = ` exports[`multiple patterns (stderr) 1`] = `""`;
exports[`multiple patterns (stdout) 1`] = `
"directory/file.js "directory/file.js
directory/nested-directory/nested-directory-file.js directory/nested-directory/nested-directory-file.js
other-directory/file.js other-directory/file.js
@ -8,7 +10,11 @@ other-directory/nested-directory/nested-directory-file.js
" "
`; `;
exports[`multiple patterns by with ignore pattern, doesn't ignore node_modules with --with-node-modules flag 1`] = ` exports[`multiple patterns (write) 1`] = `Array []`;
exports[`multiple patterns by with ignore pattern, doesn't ignore node_modules with --with-node-modules flag (stderr) 1`] = `""`;
exports[`multiple patterns by with ignore pattern, doesn't ignore node_modules with --with-node-modules flag (stdout) 1`] = `
"node_modules/node-module.js "node_modules/node-module.js
other-directory/file.js other-directory/file.js
other-directory/nested-directory/nested-directory-file.js other-directory/nested-directory/nested-directory-file.js
@ -17,7 +23,11 @@ regular-module.js
" "
`; `;
exports[`multiple patterns by with ignore pattern, ignores node_modules by default 1`] = ` exports[`multiple patterns by with ignore pattern, doesn't ignore node_modules with --with-node-modules flag (write) 1`] = `Array []`;
exports[`multiple patterns by with ignore pattern, ignores node_modules by default (stderr) 1`] = `""`;
exports[`multiple patterns by with ignore pattern, ignores node_modules by default (stdout) 1`] = `
"other-directory/file.js "other-directory/file.js
other-directory/nested-directory/nested-directory-file.js other-directory/nested-directory/nested-directory-file.js
other-regular-modules.js other-regular-modules.js
@ -25,7 +35,11 @@ regular-module.js
" "
`; `;
exports[`multiple patterns by with ignore pattern, ignores node_modules by with ./**/*.js 1`] = ` exports[`multiple patterns by with ignore pattern, ignores node_modules by default (write) 1`] = `Array []`;
exports[`multiple patterns by with ignore pattern, ignores node_modules by with ./**/*.js (stderr) 1`] = `""`;
exports[`multiple patterns by with ignore pattern, ignores node_modules by with ./**/*.js (stdout) 1`] = `
"./other-directory/file.js "./other-directory/file.js
./other-directory/nested-directory/nested-directory-file.js ./other-directory/nested-directory/nested-directory-file.js
./other-regular-modules.js ./other-regular-modules.js
@ -33,7 +47,11 @@ exports[`multiple patterns by with ignore pattern, ignores node_modules by with
" "
`; `;
exports[`multiple patterns with ignore nested directories pattern 1`] = ` exports[`multiple patterns by with ignore pattern, ignores node_modules by with ./**/*.js (write) 1`] = `Array []`;
exports[`multiple patterns with ignore nested directories pattern (stderr) 1`] = `""`;
exports[`multiple patterns with ignore nested directories pattern (stdout) 1`] = `
"directory/file.js "directory/file.js
other-directory/file.js other-directory/file.js
other-regular-modules.js other-regular-modules.js
@ -41,13 +59,29 @@ regular-module.js
" "
`; `;
exports[`multiple patterns with non exists pattern 1`] = ` exports[`multiple patterns with ignore nested directories pattern (write) 1`] = `Array []`;
exports[`multiple patterns with non exists pattern (stderr) 1`] = `""`;
exports[`multiple patterns with non exists pattern (stdout) 1`] = `
"directory/file.js "directory/file.js
directory/nested-directory/nested-directory-file.js directory/nested-directory/nested-directory-file.js
" "
`; `;
exports[`multiple patterns, throw error and exit with non zero code on non existing files 1`] = ` exports[`multiple patterns with non exists pattern (write) 1`] = `Array []`;
exports[`multiple patterns, throw error and exit with non zero code on non existing files (stderr) 1`] = `
"No matching files. Patterns tried: non-existent.js other-non-existent.js !**/node_modules/** !./node_modules/** "No matching files. Patterns tried: non-existent.js other-non-existent.js !**/node_modules/** !./node_modules/**
" "
`; `;
exports[`multiple patterns, throw error and exit with non zero code on non existing files (stdout) 1`] = `""`;
exports[`multiple patterns, throw error and exit with non zero code on non existing files (write) 1`] = `Array []`;
exports[`no errors on empty patterns (stderr) 1`] = `""`;
exports[`no errors on empty patterns (stdout) 1`] = `""`;
exports[`no errors on empty patterns (write) 1`] = `Array []`;

View File

@ -1,7 +1,11 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP // Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`allows passing a string to resolve a parser 1`] = ` exports[`allows passing a string to resolve a parser (stderr) 1`] = `""`;
exports[`allows passing a string to resolve a parser (stdout) 1`] = `
"/* eslint-disable */ "/* eslint-disable */
bar(); bar();
" "
`; `;
exports[`allows passing a string to resolve a parser (write) 1`] = `Array []`;

View File

@ -1,19 +1,23 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP // Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`format correctly if stdin content compatible with stdin-filepath 1`] = ` exports[`format correctly if stdin content compatible with stdin-filepath (stderr) 1`] = `""`;
exports[`format correctly if stdin content compatible with stdin-filepath (stdout) 1`] = `
".name { ".name {
display: none; display: none;
} }
" "
`; `;
exports[`format correctly if stdin content compatible with stdin-filepath 2`] = `""`; exports[`format correctly if stdin content compatible with stdin-filepath (write) 1`] = `Array []`;
exports[`throw error if stdin content incompatible with stdin-filepath 1`] = `""`; exports[`throw error if stdin content incompatible with stdin-filepath (stderr) 1`] = `
exports[`throw error if stdin content incompatible with stdin-filepath 2`] = `
"stdin: SyntaxError: Unexpected token (1:1) "stdin: SyntaxError: Unexpected token (1:1)
> 1 | .name { display: none; } > 1 | .name { display: none; }
| ^ | ^
" "
`; `;
exports[`throw error if stdin content incompatible with stdin-filepath (stdout) 1`] = `""`;
exports[`throw error if stdin content incompatible with stdin-filepath (write) 1`] = `Array []`;

View File

@ -0,0 +1,12 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`exits with non-zero code when input has a syntax error (stderr) 1`] = `
"stdin: SyntaxError: Unexpected token, expected ; (1:2)
> 1 | a.2
| ^
"
`;
exports[`exits with non-zero code when input has a syntax error (stdout) 1`] = `""`;
exports[`exits with non-zero code when input has a syntax error (write) 1`] = `Array []`;

View File

@ -1,28 +1,40 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP // Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`CLI --stdin-filepath works with --config-precedence cli-override 1`] = ` exports[`CLI --stdin-filepath works with --config-precedence cli-override (stdout) 1`] = `
"let x: keyof Y = foo<typeof X>() "let x: keyof Y = foo<typeof X>()
" "
`; `;
exports[`CLI --stdin-filepath works with --config-precedence file-override 1`] = ` exports[`CLI --stdin-filepath works with --config-precedence cli-override (write) 1`] = `Array []`;
exports[`CLI --stdin-filepath works with --config-precedence file-override (stdout) 1`] = `
"let x: keyof Y = foo<typeof X>(); "let x: keyof Y = foo<typeof X>();
" "
`; `;
exports[`CLI --stdin-filepath works with --config-precedence prefer-file 1`] = ` exports[`CLI --stdin-filepath works with --config-precedence file-override (write) 1`] = `Array []`;
exports[`CLI --stdin-filepath works with --config-precedence prefer-file (stdout) 1`] = `
"let x: keyof Y = foo<typeof X>(); "let x: keyof Y = foo<typeof X>();
" "
`; `;
exports[`CLI overrides are still applied when no config is found with --config-precedence file-override 1`] = ` exports[`CLI --stdin-filepath works with --config-precedence prefer-file (write) 1`] = `Array []`;
exports[`CLI overrides are still applied when no config is found with --config-precedence file-override (stderr) 1`] = `""`;
exports[`CLI overrides are still applied when no config is found with --config-precedence file-override (stdout) 1`] = `
"function noConfigJs() { "function noConfigJs() {
console.log(\\"no-config/file.js should have no semicolons\\") console.log(\\"no-config/file.js should have no semicolons\\")
} }
" "
`; `;
exports[`CLI overrides gets applied when no config exists with --config-precedence prefer-file 1`] = ` exports[`CLI overrides are still applied when no config is found with --config-precedence file-override (write) 1`] = `Array []`;
exports[`CLI overrides gets applied when no config exists with --config-precedence prefer-file (stderr) 1`] = `""`;
exports[`CLI overrides gets applied when no config exists with --config-precedence prefer-file (stdout) 1`] = `
"function noConfigJs() { "function noConfigJs() {
console.log( console.log(
\\"no-config/file.js should have no semicolons\\" \\"no-config/file.js should have no semicolons\\"
@ -31,7 +43,11 @@ exports[`CLI overrides gets applied when no config exists with --config-preceden
" "
`; `;
exports[`CLI overrides gets ignored when config exists with --config-precedence prefer-file 1`] = ` exports[`CLI overrides gets applied when no config exists with --config-precedence prefer-file (write) 1`] = `Array []`;
exports[`CLI overrides gets ignored when config exists with --config-precedence prefer-file (stderr) 1`] = `""`;
exports[`CLI overrides gets ignored when config exists with --config-precedence prefer-file (stdout) 1`] = `
"function js() { "function js() {
console.log(\\"js/file.js should have tab width 8\\"); console.log(\\"js/file.js should have tab width 8\\");
} }
@ -43,7 +59,11 @@ module.exports = {
" "
`; `;
exports[`CLI overrides take lower precedence with --config-precedence file-override 1`] = ` exports[`CLI overrides gets ignored when config exists with --config-precedence prefer-file (write) 1`] = `Array []`;
exports[`CLI overrides take lower precedence with --config-precedence file-override (stderr) 1`] = `""`;
exports[`CLI overrides take lower precedence with --config-precedence file-override (stdout) 1`] = `
"function js() { "function js() {
console.log(\\"js/file.js should have tab width 8\\"); console.log(\\"js/file.js should have tab width 8\\");
} }
@ -55,7 +75,11 @@ module.exports = {
" "
`; `;
exports[`CLI overrides take precedence with --config-precedence cli-override 1`] = ` exports[`CLI overrides take lower precedence with --config-precedence file-override (write) 1`] = `Array []`;
exports[`CLI overrides take precedence with --config-precedence cli-override (stderr) 1`] = `""`;
exports[`CLI overrides take precedence with --config-precedence cli-override (stdout) 1`] = `
"console.log( "console.log(
\\"jest/__best-tests__/file.js should have semi\\" \\"jest/__best-tests__/file.js should have semi\\"
); );
@ -108,7 +132,11 @@ function rcYaml() {
" "
`; `;
exports[`CLI overrides take precedence without --config-precedence 1`] = ` exports[`CLI overrides take precedence with --config-precedence cli-override (write) 1`] = `Array []`;
exports[`CLI overrides take precedence without --config-precedence (stderr) 1`] = `""`;
exports[`CLI overrides take precedence without --config-precedence (stdout) 1`] = `
"console.log( "console.log(
\\"jest/__best-tests__/file.js should have semi\\" \\"jest/__best-tests__/file.js should have semi\\"
); );
@ -161,17 +189,31 @@ function rcYaml() {
" "
`; `;
exports[`CLI validate options with --config-precedence cli-override 1`] = ` exports[`CLI overrides take precedence without --config-precedence (write) 1`] = `Array []`;
exports[`CLI validate options with --config-precedence cli-override (stderr) 1`] = `
"Invalid printWidth value. "Invalid printWidth value.
Expected an integer, but received: 0.5" Expected an integer, but received: 0.5"
`; `;
exports[`CLI validate options with --config-precedence file-override 1`] = ` exports[`CLI validate options with --config-precedence cli-override (stdout) 1`] = `""`;
exports[`CLI validate options with --config-precedence cli-override (write) 1`] = `Array []`;
exports[`CLI validate options with --config-precedence file-override (stderr) 1`] = `
"Invalid printWidth value. "Invalid printWidth value.
Expected an integer, but received: 0.5" Expected an integer, but received: 0.5"
`; `;
exports[`CLI validate options with --config-precedence prefer-file 1`] = ` exports[`CLI validate options with --config-precedence file-override (stdout) 1`] = `""`;
exports[`CLI validate options with --config-precedence file-override (write) 1`] = `Array []`;
exports[`CLI validate options with --config-precedence prefer-file (stderr) 1`] = `
"Invalid printWidth value. "Invalid printWidth value.
Expected an integer, but received: 0.5" Expected an integer, but received: 0.5"
`; `;
exports[`CLI validate options with --config-precedence prefer-file (stdout) 1`] = `""`;
exports[`CLI validate options with --config-precedence prefer-file (write) 1`] = `Array []`;

View File

@ -1,33 +1,53 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP // Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`doesn't ignore node_modules with --with-node-modules flag 1`] = ` exports[`doesn't ignore node_modules with --with-node-modules flag (stderr) 1`] = `""`;
exports[`doesn't ignore node_modules with --with-node-modules flag (stdout) 1`] = `
"node_modules/node-module.js "node_modules/node-module.js
not_node_modules/file.js not_node_modules/file.js
regular-module.js regular-module.js
" "
`; `;
exports[`doesn't ignore node_modules with --with-node-modules flag for file list 1`] = ` exports[`doesn't ignore node_modules with --with-node-modules flag (write) 1`] = `Array []`;
exports[`doesn't ignore node_modules with --with-node-modules flag for file list (stderr) 1`] = `""`;
exports[`doesn't ignore node_modules with --with-node-modules flag for file list (stdout) 1`] = `
"node_modules/node-module.js "node_modules/node-module.js
not_node_modules/file.js not_node_modules/file.js
regular-module.js regular-module.js
" "
`; `;
exports[`ignores node_modules by default 1`] = ` exports[`doesn't ignore node_modules with --with-node-modules flag for file list (write) 1`] = `Array []`;
exports[`ignores node_modules by default (stderr) 1`] = `""`;
exports[`ignores node_modules by default (stdout) 1`] = `
"not_node_modules/file.js "not_node_modules/file.js
regular-module.js regular-module.js
" "
`; `;
exports[`ignores node_modules by default for file list 1`] = ` exports[`ignores node_modules by default (write) 1`] = `Array []`;
exports[`ignores node_modules by default for file list (stderr) 1`] = `""`;
exports[`ignores node_modules by default for file list (stdout) 1`] = `
"not_node_modules/file.js "not_node_modules/file.js
regular-module.js regular-module.js
" "
`; `;
exports[`ignores node_modules by with ./**/*.js 1`] = ` exports[`ignores node_modules by default for file list (write) 1`] = `Array []`;
exports[`ignores node_modules by with ./**/*.js (stderr) 1`] = `""`;
exports[`ignores node_modules by with ./**/*.js (stdout) 1`] = `
"./not_node_modules/file.js "./not_node_modules/file.js
./regular-module.js ./regular-module.js
" "
`; `;
exports[`ignores node_modules by with ./**/*.js (write) 1`] = `Array []`;

View File

@ -1,6 +1,8 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP // Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`infers postcss parser 1`] = ` exports[`infers postcss parser (stderr) 1`] = `""`;
exports[`infers postcss parser (stdout) 1`] = `
"/* JavaScript */ "/* JavaScript */
\\"use strict\\"; \\"use strict\\";
/* Stylesheet */ /* Stylesheet */
@ -10,4 +12,10 @@ exports[`infers postcss parser 1`] = `
" "
`; `;
exports[`infers postcss parser with --list-different 1`] = `""`; exports[`infers postcss parser (write) 1`] = `Array []`;
exports[`infers postcss parser with --list-different (stderr) 1`] = `""`;
exports[`infers postcss parser with --list-different (stdout) 1`] = `""`;
exports[`infers postcss parser with --list-different (write) 1`] = `Array []`;

View File

@ -1,7 +1,11 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP // Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`preserves shebang 1`] = ` exports[`preserves shebang (stderr) 1`] = `""`;
exports[`preserves shebang (stdout) 1`] = `
"#!/usr/bin/env node "#!/usr/bin/env node
\\"use strict\\"; \\"use strict\\";
" "
`; `;
exports[`preserves shebang (write) 1`] = `Array []`;

View File

@ -1,13 +1,32 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP // Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`do not write file with --write + invalid file 1`] = ` exports[`do not write file with --write + formated file (stderr) 1`] = `""`;
exports[`do not write file with --write + formated file (stdout) 1`] = `
"formated.js%s %dms
"
`;
exports[`do not write file with --write + invalid file (stderr) 1`] = `
"invalid.js: SyntaxError: Unexpected token, expected ; (1:6) "invalid.js: SyntaxError: Unexpected token, expected ; (1:6)
> 1 | this is invalid! > 1 | this is invalid!
| ^ | ^
" "
`; `;
exports[`write file with --write + unformated file 1`] = ` exports[`do not write file with --write + invalid file (stdout) 1`] = `
"invalid.js
"
`;
exports[`write file with --write + unformated file (stderr) 1`] = `""`;
exports[`write file with --write + unformated file (stdout) 1`] = `
"unformated.js%s %dms
"
`;
exports[`write file with --write + unformated file (write) 1`] = `
Array [ Array [
Object { Object {
"content": "var x = 1; "content": "var x = 1;

View File

@ -2,53 +2,38 @@
const runPrettier = require("../runPrettier"); const runPrettier = require("../runPrettier");
test("boolean flags do not swallow the next argument", () => { describe("boolean flags do not swallow the next argument", () => {
const result = runPrettier("cli/arg-parsing", ["--single-quote", "file.js"]); runPrettier("cli/arg-parsing", ["--single-quote", "file.js"]).test({
status: 0
expect(result.stdout).toMatchSnapshot(); });
expect(result.stderr).toMatchSnapshot();
expect(result.status).toEqual(0);
}); });
test("negated options work", () => { describe("negated options work", () => {
const result = runPrettier("cli/arg-parsing", ["--no-semi", "file.js"]); runPrettier("cli/arg-parsing", ["--no-semi", "file.js"]).test({
status: 0
expect(result.stdout).toMatchSnapshot(); });
expect(result.stderr).toMatchSnapshot();
expect(result.status).toEqual(0);
}); });
test("unknown options are warned", () => { describe("unknown options are warned", () => {
const result = runPrettier("cli/arg-parsing", ["file.js", "--unknown"]); runPrettier("cli/arg-parsing", ["file.js", "--unknown"]).test({
status: 0
expect(result.stdout).toMatchSnapshot(); });
expect(result.stderr).toMatchSnapshot();
expect(result.status).toEqual(0);
}); });
test("unknown negated options are warned", () => { describe("unknown negated options are warned", () => {
const result = runPrettier("cli/arg-parsing", ["file.js", "--no-unknown"]); runPrettier("cli/arg-parsing", ["file.js", "--no-unknown"]).test({
status: 0
expect(result.stdout).toMatchSnapshot(); });
expect(result.stderr).toMatchSnapshot();
expect(result.status).toEqual(0);
}); });
test("deprecated options are warned", () => { describe("deprecated options are warned", () => {
const result = runPrettier("cli/arg-parsing", ["file.js", "--flow-parser"]); runPrettier("cli/arg-parsing", ["file.js", "--flow-parser"]).test({
status: 0
expect(result.stdout).toMatchSnapshot(); });
expect(result.stderr).toMatchSnapshot();
expect(result.status).toEqual(0);
}); });
test("deprecated option values are warned", () => { describe("deprecated option values are warned", () => {
const result = runPrettier("cli/arg-parsing", [ runPrettier("cli/arg-parsing", ["file.js", "--trailing-comma"]).test({
"file.js", status: 0
"--trailing-comma" });
]);
expect(result.stdout).toMatchSnapshot();
expect(result.stderr).toMatchSnapshot();
expect(result.status).toEqual(0);
}); });

View File

@ -4,53 +4,44 @@ const runPrettier = require("../runPrettier");
expect.addSnapshotSerializer(require("../path-serializer")); expect.addSnapshotSerializer(require("../path-serializer"));
test("throw error with invalid config format", () => { describe("throw error with invalid config format", () => {
const output = runPrettier("cli/config/invalid", [ runPrettier("cli/config/invalid", ["--config", "file/.prettierrc"]).test({
"--config", status: "non-zero"
"file/.prettierrc" });
]);
expect(output.stderr).toMatchSnapshot();
expect(output.status).not.toBe(0);
}); });
test("throw error with invalid config target (directory)", () => { describe("throw error with invalid config target (directory)", () => {
const output = runPrettier("cli/config/invalid", [ runPrettier("cli/config/invalid", [
"--config", "--config",
"folder/.prettierrc" // this is a directory "folder/.prettierrc" // this is a directory
]); ]).test({
expect(output.stderr).toMatchSnapshot(); status: "non-zero"
expect(output.status).not.toBe(0); });
}); });
test("throw error with invalid config option (int)", () => { describe("throw error with invalid config option (int)", () => {
const output = runPrettier("cli/config/invalid", ["--config", "option/int"]); runPrettier("cli/config/invalid", ["--config", "option/int"]).test({
expect(output.stderr).toMatchSnapshot(); status: "non-zero"
expect(output.status).not.toBe(0); });
}); });
test("throw error with invalid config option (trailingComma)", () => { describe("throw error with invalid config option (trailingComma)", () => {
const output = runPrettier("cli/config/invalid", [ runPrettier("cli/config/invalid", ["--config", "option/trailingComma"]).test({
"--config", status: "non-zero"
"option/trailingComma" });
]);
expect(output.stderr).toMatchSnapshot();
expect(output.status).not.toBe(0);
}); });
test("throw error with invalid config precedence option (configPrecedence)", () => { describe("throw error with invalid config precedence option (configPrecedence)", () => {
const output = runPrettier("cli/config/invalid", [ runPrettier("cli/config/invalid", [
"--config-precedence", "--config-precedence",
"option/configPrecedence" "option/configPrecedence"
]); ]).test({
expect(output.stderr).toMatchSnapshot(); status: "non-zero"
expect(output.status).not.toBe(0); });
}); });
test("show warning with unknown option", () => { describe("show warning with unknown option", () => {
const output = runPrettier("cli/config/invalid", [ runPrettier("cli/config/invalid", ["--config", "option/unknown"]).test({
"--config", status: 0
"option/unknown" });
]);
expect(output.stderr).toMatchSnapshot();
expect(output.status).toBe(0);
}); });

View File

@ -7,65 +7,53 @@ const prettier = require("../../tests_config/require_prettier");
expect.addSnapshotSerializer(require("../path-serializer")); expect.addSnapshotSerializer(require("../path-serializer"));
test("resolves configuration from external files", () => { describe("resolves configuration from external files", () => {
const output = runPrettier("cli/config/", ["**/*.js"]); runPrettier("cli/config/", ["**/*.js"]).test({
expect(output.stdout).toMatchSnapshot(); status: 0
expect(output.status).toEqual(0); });
}); });
test("resolves configuration from external files and overrides by extname", () => { describe("resolves configuration from external files and overrides by extname", () => {
const output = runPrettier("cli/config/", ["**/*.ts"]); runPrettier("cli/config/", ["**/*.ts"]).test({
expect(output.stdout).toMatchSnapshot(); status: 0
expect(output.status).toEqual(0); });
}); });
test("accepts configuration from --config", () => { describe("accepts configuration from --config", () => {
const output = runPrettier("cli/config/", [ runPrettier("cli/config/", ["--config", ".prettierrc", "./js/file.js"]).test({
"--config", status: 0
".prettierrc", });
"./js/file.js"
]);
expect(output.stdout).toMatchSnapshot();
expect(output.status).toEqual(0);
}); });
test("resolves configuration file with --find-config-path file", () => { describe("resolves configuration file with --find-config-path file", () => {
const output = runPrettier("cli/config/", [ runPrettier("cli/config/", ["--find-config-path", "no-config/file.js"]).test({
"--find-config-path", status: 0
"no-config/file.js" });
]);
expect(output.stdout).toMatchSnapshot();
expect(output.status).toEqual(0);
}); });
test("resolves json configuration file with --find-config-path file", () => { describe("resolves json configuration file with --find-config-path file", () => {
const output = runPrettier("cli/config/", [ runPrettier("cli/config/", ["--find-config-path", "rc-json/file.js"]).test({
"--find-config-path", status: 0
"rc-json/file.js" });
]);
expect(output.stdout).toMatchSnapshot();
expect(output.status).toEqual(0);
}); });
test("resolves yaml configuration file with --find-config-path file", () => { describe("resolves yaml configuration file with --find-config-path file", () => {
const output = runPrettier("cli/config/", [ runPrettier("cli/config/", ["--find-config-path", "rc-yaml/file.js"]).test({
"--find-config-path", status: 0
"rc-yaml/file.js" });
]);
expect(output.stdout).toMatchSnapshot();
expect(output.status).toEqual(0);
}); });
test("prints nothing when no file found with --find-config-path", () => { describe("prints nothing when no file found with --find-config-path", () => {
const output = runPrettier("cli/config/", ["--find-config-path", ".."]); runPrettier("cli/config/", ["--find-config-path", ".."]).test({
expect(output.stdout).toEqual(""); stdout: "",
expect(output.status).toEqual(1); status: 1
});
}); });
test("CLI overrides take precedence", () => { describe("CLI overrides take precedence", () => {
const output = runPrettier("cli/config/", ["--print-width", "1", "**/*.js"]); runPrettier("cli/config/", ["--print-width", "1", "**/*.js"]).test({
expect(output.stdout).toMatchSnapshot(); status: 0
expect(output.status).toEqual(0); });
}); });
test("API resolveConfig with no args", () => { test("API resolveConfig with no args", () => {

View File

@ -2,10 +2,8 @@
const runPrettier = require("../runPrettier"); const runPrettier = require("../runPrettier");
test("write cursorOffset to stderr with --cursor-offset <int>", () => { describe("write cursorOffset to stderr with --cursor-offset <int>", () => {
const result = runPrettier("cli", ["--cursor-offset", "2"], { input: " 1" }); runPrettier("cli", ["--cursor-offset", "2"], { input: " 1" }).test({
status: 0
expect(result.stdout).toMatchSnapshot(); });
expect(result.stderr).toMatchSnapshot();
expect(result.status).toEqual(0);
}); });

View File

@ -2,23 +2,20 @@
const runPrettier = require("../runPrettier"); const runPrettier = require("../runPrettier");
test("doesn't crash when --debug-check is passed", () => { describe("doesn't crash when --debug-check is passed", () => {
const result = runPrettier("cli/with-shebang", [ runPrettier("cli/with-shebang", ["issue1890.js", "--debug-check"]).test({
"issue1890.js", stdout: "issue1890.js\n",
"--debug-check" stderr: "",
]); status: 0
});
expect(result.stdout).toEqual("issue1890.js\n"); });
expect(result.stderr).toEqual("");
expect(result.status).toEqual(0); describe("checks stdin with --debug-check", () => {
}); runPrettier("cli/with-shebang", ["--debug-check"], {
input: "0"
test("checks stdin with --debug-check", () => { }).test({
const result = runPrettier("cli/with-shebang", ["--debug-check"], { stdout: "(stdin)\n",
input: "0" stderr: "",
status: 0
}); });
expect(result.stdout).toEqual("(stdin)\n");
expect(result.stderr).toEqual("");
expect(result.status).toEqual(0);
}); });

View File

@ -2,12 +2,12 @@
const runPrettier = require("../runPrettier"); const runPrettier = require("../runPrettier");
test("prints doc with --debug-print-doc", () => { describe("prints doc with --debug-print-doc", () => {
const result = runPrettier("cli/with-shebang", ["--debug-print-doc"], { runPrettier("cli/with-shebang", ["--debug-print-doc"], {
input: "0" input: "0"
}).test({
stdout: '["0", ";", hardline, breakParent];\n',
stderr: "",
status: 0
}); });
expect(result.stdout).toEqual('["0", ";", hardline, breakParent];\n');
expect(result.stderr).toEqual("");
expect(result.status).toEqual(0);
}); });

View File

@ -4,24 +4,23 @@ const prettier = require("../../tests_config/require_prettier");
const runPrettier = require("../runPrettier"); const runPrettier = require("../runPrettier");
const constant = require("../../src/cli-constant"); const constant = require("../../src/cli-constant");
test("show version with --version", () => { describe("show version with --version", () => {
const result = runPrettier("cli/with-shebang", ["--version"]); runPrettier("cli/with-shebang", ["--version"]).test({
stdout: prettier.version + "\n",
expect(result.stdout).toBe(prettier.version + "\n"); status: 0
expect(result.status).toEqual(0); });
}); });
test("show usage with --help", () => { describe("show usage with --help", () => {
const result = runPrettier("cli", ["--help"]); runPrettier("cli", ["--help"]).test({
status: 0
expect(result.stdout).toMatchSnapshot(); });
expect(result.status).toEqual(0);
}); });
test(`show detailed usage with --help l (alias)`, () => { describe(`show detailed usage with --help l (alias)`, () => {
const result = runPrettier("cli", ["--help", "l"]); runPrettier("cli", ["--help", "l"]).test({
expect(result.stdout).toMatchSnapshot(); status: 0
expect(result.status).toEqual(0); });
}); });
constant.detailedOptions.forEach(option => { constant.detailedOptions.forEach(option => {
@ -31,48 +30,40 @@ constant.detailedOptions.forEach(option => {
].filter(Boolean); ].filter(Boolean);
optionNames.forEach(optionName => { optionNames.forEach(optionName => {
test(`show detailed usage with --help ${optionName}`, () => { describe(`show detailed usage with --help ${optionName}`, () => {
const result = runPrettier("cli", ["--help", optionName]); runPrettier("cli", ["--help", optionName]).test({
expect(result.stdout).toMatchSnapshot(); status: 0
expect(result.status).toEqual(0); });
}); });
}); });
}); });
test("show warning with --help not-found", () => { describe("show warning with --help not-found", () => {
const result = runPrettier("cli", ["--help", "not-found"]); runPrettier("cli", ["--help", "not-found"]).test({
status: 0
expect(result.stdout).toMatchSnapshot(); });
expect(result.stderr).toMatchSnapshot();
expect(result.status).toEqual(0);
}); });
test("show warning with --help not-found (typo)", () => { describe("show warning with --help not-found (typo)", () => {
const result = runPrettier("cli", ["--help", "parserr"]); runPrettier("cli", ["--help", "parserr"]).test({
status: 0
expect(result.stdout).toMatchSnapshot(); });
expect(result.stderr).toMatchSnapshot();
expect(result.status).toEqual(0);
}); });
test("throw error with --write + --debug-check", () => { describe("throw error with --write + --debug-check", () => {
const result = runPrettier("cli", ["--write", "--debug-check"]); runPrettier("cli", ["--write", "--debug-check"]).test({
status: 1
expect(result.stderr).toMatchSnapshot(); });
expect(result.status).toEqual(1);
}); });
test("throw error with --find-config-path + multiple files", () => { describe("throw error with --find-config-path + multiple files", () => {
const result = runPrettier("cli", ["--find-config-path", "abc.js", "def.js"]); runPrettier("cli", ["--find-config-path", "abc.js", "def.js"]).test({
status: 1
expect(result.stderr).toMatchSnapshot(); });
expect(result.status).toEqual(1);
}); });
test("throw error and show usage with something unexpected", () => { describe("throw error and show usage with something unexpected", () => {
const result = runPrettier("cli", [], { isTTY: true }); runPrettier("cli", [], { isTTY: true }).test({
status: "non-zero"
expect(result.stdout).toMatchSnapshot(); });
expect(result.stderr).toMatchSnapshot();
expect(result.status).not.toEqual(0);
}); });

View File

@ -3,14 +3,13 @@
const path = require("path"); const path = require("path");
const runPrettier = require("../runPrettier"); const runPrettier = require("../runPrettier");
test("support absolute filename", () => { describe("support absolute filename", () => {
const result = runPrettier("cli/ignore-absolute-path", [ runPrettier("cli/ignore-absolute-path", [
path.resolve(__dirname, "../cli/ignore-absolute-path/ignored/module.js"), path.resolve(__dirname, "../cli/ignore-absolute-path/ignored/module.js"),
path.resolve(__dirname, "../cli/ignore-absolute-path/depth1/ignored/*.js"), path.resolve(__dirname, "../cli/ignore-absolute-path/depth1/ignored/*.js"),
path.resolve(__dirname, "../cli/ignore-absolute-path/regular-module.js"), path.resolve(__dirname, "../cli/ignore-absolute-path/regular-module.js"),
"-l" "-l"
]); ]).test({
status: 1
expect(result.stdout).toMatchSnapshot(); });
expect(result.status).toEqual(1);
}); });

View File

@ -2,21 +2,19 @@
const runPrettier = require("../runPrettier"); const runPrettier = require("../runPrettier");
test("ignore path", () => { describe("ignore path", () => {
const result = runPrettier("cli/ignore-path", [ runPrettier("cli/ignore-path", [
"**/*.js", "**/*.js",
"--ignore-path", "--ignore-path",
".gitignore", ".gitignore",
"-l" "-l"
]); ]).test({
status: 1
expect(result.stdout).toMatchSnapshot(); });
expect(result.status).toEqual(1);
}); });
test("support .prettierignore", () => { describe("support .prettierignore", () => {
const result = runPrettier("cli/ignore-path", ["**/*.js", "-l"]); runPrettier("cli/ignore-path", ["**/*.js", "-l"]).test({
status: 1
expect(result.stdout).toMatchSnapshot(); });
expect(result.status).toEqual(1);
}); });

View File

@ -4,9 +4,8 @@ const runPrettier = require("../runPrettier");
expect.addSnapshotSerializer(require("../path-serializer")); expect.addSnapshotSerializer(require("../path-serializer"));
test("throw error with invalid ignore", () => { describe("throw error with invalid ignore", () => {
const result = runPrettier("cli/invalid-ignore", ["something.js"]); runPrettier("cli/invalid-ignore", ["something.js"]).test({
status: "non-zero"
expect(result.stderr).toMatchSnapshot(); });
expect(result.status).not.toEqual(0);
}); });

View File

@ -2,12 +2,12 @@
const runPrettier = require("../runPrettier"); const runPrettier = require("../runPrettier");
test("checks stdin with --list-different", () => { describe("checks stdin with --list-different", () => {
const result = runPrettier("cli/with-shebang", ["--list-different"], { runPrettier("cli/with-shebang", ["--list-different"], {
input: "0" input: "0"
}).test({
stdout: "(stdin)\n",
stderr: "",
status: "non-zero"
}); });
expect(result.stdout).toEqual("(stdin)\n");
expect(result.stderr).toEqual("");
expect(result.status).not.toEqual(0);
}); });

View File

@ -2,85 +2,79 @@
const runPrettier = require("../runPrettier"); const runPrettier = require("../runPrettier");
test("multiple patterns", () => { describe("multiple patterns", () => {
const result = runPrettier("cli/multiple-patterns", [ runPrettier("cli/multiple-patterns", [
"directory/**/*.js", "directory/**/*.js",
"other-directory/**/*.js", "other-directory/**/*.js",
"-l" "-l"
]); ]).test({
status: 1
expect(result.stdout).toMatchSnapshot(); });
expect(result.status).toEqual(1);
}); });
test("multiple patterns with non exists pattern", () => { describe("multiple patterns with non exists pattern", () => {
const result = runPrettier("cli/multiple-patterns", [ runPrettier("cli/multiple-patterns", [
"directory/**/*.js", "directory/**/*.js",
"non-existent.js", "non-existent.js",
"-l" "-l"
]); ]).test({
status: 1
expect(result.stdout).toMatchSnapshot(); });
expect(result.status).toEqual(1);
}); });
test("multiple patterns with ignore nested directories pattern", () => { describe("multiple patterns with ignore nested directories pattern", () => {
const result = runPrettier("cli/multiple-patterns", [ runPrettier("cli/multiple-patterns", [
"**/*.js", "**/*.js",
"!**/nested-directory/**", "!**/nested-directory/**",
"-l" "-l"
]); ]).test({
status: 1
expect(result.stdout).toMatchSnapshot(); });
expect(result.status).toEqual(1);
}); });
test("multiple patterns by with ignore pattern, ignores node_modules by default", () => { describe("multiple patterns by with ignore pattern, ignores node_modules by default", () => {
const result = runPrettier("cli/multiple-patterns", [ runPrettier("cli/multiple-patterns", [
"**/*.js", "**/*.js",
"!directory/**", "!directory/**",
"-l" "-l"
]); ]).test({
status: 1
expect(result.stdout).toMatchSnapshot(); });
expect(result.status).toEqual(1);
}); });
test("multiple patterns by with ignore pattern, ignores node_modules by with ./**/*.js", () => { describe("multiple patterns by with ignore pattern, ignores node_modules by with ./**/*.js", () => {
const result = runPrettier("cli/multiple-patterns", [ runPrettier("cli/multiple-patterns", [
"./**/*.js", "./**/*.js",
"!./directory/**", "!./directory/**",
"-l" "-l"
]); ]).test({
status: 1
expect(result.stdout).toMatchSnapshot(); });
expect(result.status).toEqual(1);
}); });
test("multiple patterns by with ignore pattern, doesn't ignore node_modules with --with-node-modules flag", () => { describe("multiple patterns by with ignore pattern, doesn't ignore node_modules with --with-node-modules flag", () => {
const result = runPrettier("cli/multiple-patterns", [ runPrettier("cli/multiple-patterns", [
"**/*.js", "**/*.js",
"!directory/**", "!directory/**",
"-l", "-l",
"--with-node-modules" "--with-node-modules"
]); ]).test({
status: 1
expect(result.stdout).toMatchSnapshot(); });
expect(result.status).toEqual(1);
}); });
test("no errors on empty patterns", () => { describe("no errors on empty patterns", () => {
const result = runPrettier("cli/multiple-patterns"); runPrettier("cli/multiple-patterns").test({
expect(result.status).toEqual(0); status: 0
});
}); });
test("multiple patterns, throw error and exit with non zero code on non existing files", () => { describe("multiple patterns, throw error and exit with non zero code on non existing files", () => {
const result = runPrettier("cli/multiple-patterns", [ runPrettier("cli/multiple-patterns", [
"non-existent.js", "non-existent.js",
"other-non-existent.js", "other-non-existent.js",
"-l" "-l"
]); ]).test({
status: 2
expect(result.stderr).toMatchSnapshot(); });
expect(result.status).toEqual(2);
}); });

View File

@ -29,12 +29,12 @@ test("allows usage of prettier's supported parsers", () => {
expect(output).toEqual("bar();\n"); expect(output).toEqual("bar();\n");
}); });
test("allows passing a string to resolve a parser", () => { describe("allows passing a string to resolve a parser", () => {
const output = runPrettier("./custom-parsers/", [ runPrettier("./custom-parsers/", [
"./custom-rename-input.js", "./custom-rename-input.js",
"--parser", "--parser",
"./custom-rename-parser" "./custom-rename-parser"
]); ]).test({
expect(output.stdout).toMatchSnapshot(); status: 0
expect(output.status).toEqual(0); });
}); });

View File

@ -2,26 +2,22 @@
const runPrettier = require("../runPrettier"); const runPrettier = require("../runPrettier");
test("format correctly if stdin content compatible with stdin-filepath", () => { describe("format correctly if stdin content compatible with stdin-filepath", () => {
const result = runPrettier( runPrettier(
"cli", "cli",
["--no-color", "--stdin-filepath", "abc.css"], ["--no-color", "--stdin-filepath", "abc.css"],
{ input: ".name { display: none; }" } // css { input: ".name { display: none; }" } // css
); ).test({
status: 0
expect(result.stdout).toMatchSnapshot(); });
expect(result.stderr).toMatchSnapshot();
expect(result.status).toEqual(0);
}); });
test("throw error if stdin content incompatible with stdin-filepath", () => { describe("throw error if stdin content incompatible with stdin-filepath", () => {
const result = runPrettier( runPrettier(
"cli", "cli",
["--no-color", "--stdin-filepath", "abc.js"], ["--no-color", "--stdin-filepath", "abc.js"],
{ input: ".name { display: none; }" } // css { input: ".name { display: none; }" } // css
); ).test({
status: "non-zero"
expect(result.stdout).toMatchSnapshot(); });
expect(result.stderr).toMatchSnapshot();
expect(result.status).not.toEqual(0);
}); });

View File

@ -2,10 +2,10 @@
const runPrettier = require("../runPrettier"); const runPrettier = require("../runPrettier");
test("exits with non-zero code when input has a syntax error", () => { describe("exits with non-zero code when input has a syntax error", () => {
const result = runPrettier("cli/with-shebang", ["--stdin"], { runPrettier("cli/with-shebang", ["--stdin", "--no-color"], {
input: "a.2" input: "a.2"
}).test({
status: 2
}); });
expect(result.status).toEqual(2);
}); });

View File

@ -2,50 +2,50 @@
const runPrettier = require("../runPrettier"); const runPrettier = require("../runPrettier");
test("CLI overrides take precedence without --config-precedence", () => { describe("CLI overrides take precedence without --config-precedence", () => {
const output = runPrettier("cli/config/", ["--print-width", "1", "**/*.js"]); runPrettier("cli/config/", ["--print-width", "1", "**/*.js"]).test({
expect(output.stdout).toMatchSnapshot(); status: 0
expect(output.status).toEqual(0); });
}); });
test("CLI overrides take precedence with --config-precedence cli-override", () => { describe("CLI overrides take precedence with --config-precedence cli-override", () => {
const output = runPrettier("cli/config/", [ runPrettier("cli/config/", [
"--print-width", "--print-width",
"1", "1",
"--config-precedence", "--config-precedence",
"cli-override", "cli-override",
"**/*.js" "**/*.js"
]); ]).test({
expect(output.stdout).toMatchSnapshot(); status: 0
expect(output.status).toEqual(0); });
}); });
test("CLI overrides take lower precedence with --config-precedence file-override", () => { describe("CLI overrides take lower precedence with --config-precedence file-override", () => {
const output = runPrettier("cli/config/js/", [ runPrettier("cli/config/js/", [
"--tab-width", "--tab-width",
"1", "1",
"--config-precedence", "--config-precedence",
"file-override", "file-override",
"**/*.js" "**/*.js"
]); ]).test({
expect(output.stdout).toMatchSnapshot(); status: 0
expect(output.status).toEqual(0); });
}); });
test("CLI overrides are still applied when no config is found with --config-precedence file-override", () => { describe("CLI overrides are still applied when no config is found with --config-precedence file-override", () => {
const output = runPrettier("cli/config/no-config/", [ runPrettier("cli/config/no-config/", [
"--tab-width", "--tab-width",
"6", "6",
"--config-precedence", "--config-precedence",
"file-override", "file-override",
"**/*.js" "**/*.js"
]); ]).test({
expect(output.stdout).toMatchSnapshot(); status: 0
expect(output.status).toEqual(0); });
}); });
test("CLI overrides gets ignored when config exists with --config-precedence prefer-file", () => { describe("CLI overrides gets ignored when config exists with --config-precedence prefer-file", () => {
const output = runPrettier("cli/config/js/", [ runPrettier("cli/config/js/", [
"--print-width", "--print-width",
"1", "1",
"--tab-width", "--tab-width",
@ -53,13 +53,13 @@ test("CLI overrides gets ignored when config exists with --config-precedence pre
"--config-precedence", "--config-precedence",
"prefer-file", "prefer-file",
"**/*.js" "**/*.js"
]); ]).test({
expect(output.stdout).toMatchSnapshot(); status: 0
expect(output.status).toEqual(0); });
}); });
test("CLI overrides gets applied when no config exists with --config-precedence prefer-file", () => { describe("CLI overrides gets applied when no config exists with --config-precedence prefer-file", () => {
const output = runPrettier("cli/config/no-config/", [ runPrettier("cli/config/no-config/", [
"--print-width", "--print-width",
"1", "1",
"--tab-width", "--tab-width",
@ -68,40 +68,40 @@ test("CLI overrides gets applied when no config exists with --config-precedence
"--config-precedence", "--config-precedence",
"prefer-file", "prefer-file",
"**/*.js" "**/*.js"
]); ]).test({
expect(output.stdout).toMatchSnapshot(); status: 0
expect(output.status).toEqual(0); });
}); });
test("CLI validate options with --config-precedence cli-override", () => { describe("CLI validate options with --config-precedence cli-override", () => {
const output = runPrettier("cli/config-precedence", [ runPrettier("cli/config-precedence", [
"--config-precedence", "--config-precedence",
"cli-override" "cli-override"
]); ]).test({
expect(output.stderr).toMatchSnapshot(); status: "non-zero"
expect(output.status).not.toEqual(0); });
}); });
test("CLI validate options with --config-precedence file-override", () => { describe("CLI validate options with --config-precedence file-override", () => {
const output = runPrettier("cli/config-precedence", [ runPrettier("cli/config-precedence", [
"--config-precedence", "--config-precedence",
"file-override" "file-override"
]); ]).test({
expect(output.stderr).toMatchSnapshot(); status: "non-zero"
expect(output.status).not.toEqual(0); });
}); });
test("CLI validate options with --config-precedence prefer-file", () => { describe("CLI validate options with --config-precedence prefer-file", () => {
const output = runPrettier("cli/config-precedence", [ runPrettier("cli/config-precedence", [
"--config-precedence", "--config-precedence",
"prefer-file" "prefer-file"
]); ]).test({
expect(output.stderr).toMatchSnapshot(); status: "non-zero"
expect(output.status).not.toEqual(0); });
}); });
test("CLI --stdin-filepath works with --config-precedence prefer-file", () => { describe("CLI --stdin-filepath works with --config-precedence prefer-file", () => {
const result = runPrettier( runPrettier(
"cli/config/", "cli/config/",
[ [
"--no-color", "--no-color",
@ -111,15 +111,14 @@ test("CLI --stdin-filepath works with --config-precedence prefer-file", () => {
"--config-precedence=prefer-file" "--config-precedence=prefer-file"
], ],
{ input: "let x: keyof Y = foo<typeof X>()" } // typescript { input: "let x: keyof Y = foo<typeof X>()" } // typescript
); ).test({
stderr: "",
expect(result.stdout).toMatchSnapshot(); status: 0
expect(result.stderr).toEqual(""); });
expect(result.status).toEqual(0);
}); });
test("CLI --stdin-filepath works with --config-precedence file-override", () => { describe("CLI --stdin-filepath works with --config-precedence file-override", () => {
const result = runPrettier( runPrettier(
"cli/config/", "cli/config/",
[ [
"--no-color", "--no-color",
@ -129,15 +128,14 @@ test("CLI --stdin-filepath works with --config-precedence file-override", () =>
"--config-precedence=file-override" "--config-precedence=file-override"
], ],
{ input: "let x: keyof Y = foo<typeof X>()" } // typescript { input: "let x: keyof Y = foo<typeof X>()" } // typescript
); ).test({
stderr: "",
expect(result.stdout).toMatchSnapshot(); status: 0
expect(result.stderr).toEqual(""); });
expect(result.status).toEqual(0);
}); });
test("CLI --stdin-filepath works with --config-precedence cli-override", () => { describe("CLI --stdin-filepath works with --config-precedence cli-override", () => {
const result = runPrettier( runPrettier(
"cli/config/", "cli/config/",
[ [
"--no-color", "--no-color",
@ -147,9 +145,8 @@ test("CLI --stdin-filepath works with --config-precedence cli-override", () => {
"--config-precedence=cli-override" "--config-precedence=cli-override"
], ],
{ input: "let x: keyof Y = foo<typeof X>()" } // typescript { input: "let x: keyof Y = foo<typeof X>()" } // typescript
); ).test({
stderr: "",
expect(result.stdout).toMatchSnapshot(); status: 0
expect(result.stderr).toEqual(""); });
expect(result.status).toEqual(0);
}); });

View File

@ -2,52 +2,47 @@
const runPrettier = require("../runPrettier"); const runPrettier = require("../runPrettier");
test("ignores node_modules by default", () => { describe("ignores node_modules by default", () => {
const result = runPrettier("cli/with-node-modules", ["**/*.js", "-l"]); runPrettier("cli/with-node-modules", ["**/*.js", "-l"]).test({
status: 1
expect(result.stdout).toMatchSnapshot(); });
expect(result.status).toEqual(1);
}); });
test("ignores node_modules by with ./**/*.js", () => { describe("ignores node_modules by with ./**/*.js", () => {
const result = runPrettier("cli/with-node-modules", ["./**/*.js", "-l"]); runPrettier("cli/with-node-modules", ["./**/*.js", "-l"]).test({
status: 1
expect(result.stdout).toMatchSnapshot(); });
expect(result.status).toEqual(1);
}); });
test("doesn't ignore node_modules with --with-node-modules flag", () => { describe("doesn't ignore node_modules with --with-node-modules flag", () => {
const result = runPrettier("cli/with-node-modules", [ runPrettier("cli/with-node-modules", [
"**/*.js", "**/*.js",
"-l", "-l",
"--with-node-modules" "--with-node-modules"
]); ]).test({
status: 1
expect(result.stdout).toMatchSnapshot(); });
expect(result.status).toEqual(1);
}); });
test("ignores node_modules by default for file list", () => { describe("ignores node_modules by default for file list", () => {
const result = runPrettier("cli/with-node-modules", [ runPrettier("cli/with-node-modules", [
"node_modules/node-module.js", "node_modules/node-module.js",
"not_node_modules/file.js", "not_node_modules/file.js",
"regular-module.js", "regular-module.js",
"-l" "-l"
]); ]).test({
status: 1
expect(result.stdout).toMatchSnapshot(); });
expect(result.status).toEqual(1);
}); });
test("doesn't ignore node_modules with --with-node-modules flag for file list", () => { describe("doesn't ignore node_modules with --with-node-modules flag for file list", () => {
const result = runPrettier("cli/with-node-modules", [ runPrettier("cli/with-node-modules", [
"node_modules/node-module.js", "node_modules/node-module.js",
"not_node_modules/file.js", "not_node_modules/file.js",
"regular-module.js", "regular-module.js",
"-l", "-l",
"--with-node-modules" "--with-node-modules"
]); ]).test({
status: 1
expect(result.stdout).toMatchSnapshot(); });
expect(result.status).toEqual(1);
}); });

View File

@ -2,19 +2,14 @@
const runPrettier = require("../runPrettier"); const runPrettier = require("../runPrettier");
test("infers postcss parser", () => { describe("infers postcss parser", () => {
const result = runPrettier("cli/with-parser-inference", ["*"]); runPrettier("cli/with-parser-inference", ["*"]).test({
status: 0
expect(result.stdout).toMatchSnapshot(); });
expect(result.status).toEqual(0);
}); });
test("infers postcss parser with --list-different", () => { describe("infers postcss parser with --list-different", () => {
const result = runPrettier("cli/with-parser-inference", [ runPrettier("cli/with-parser-inference", ["--list-different", "*"]).test({
"--list-different", status: 0
"*" });
]);
expect(result.stdout).toMatchSnapshot();
expect(result.status).toEqual(0);
}); });

View File

@ -2,9 +2,8 @@
const runPrettier = require("../runPrettier"); const runPrettier = require("../runPrettier");
test("preserves shebang", () => { describe("preserves shebang", () => {
const result = runPrettier("cli/with-shebang", ["issue1890.js"]); runPrettier("cli/with-shebang", ["issue1890.js"]).test({
status: 0
expect(result.stdout).toMatchSnapshot(); });
expect(result.status).toEqual(0);
}); });

View File

@ -2,28 +2,22 @@
const runPrettier = require("../runPrettier"); const runPrettier = require("../runPrettier");
test("write file with --write + unformated file", () => { describe("write file with --write + unformated file", () => {
const result = runPrettier("cli/write", ["--write", "unformated.js"]); runPrettier("cli/write", ["--write", "unformated.js"]).test({
status: 0
expect(result.write).toMatchSnapshot(); });
expect(result.status).toEqual(0);
}); });
test("do not write file with --write + formated file", () => { describe("do not write file with --write + formated file", () => {
const result = runPrettier("cli/write", ["--write", "formated.js"]); runPrettier("cli/write", ["--write", "formated.js"]).test({
write: [],
expect(result.write).toHaveLength(0); status: 0
expect(result.status).toEqual(0); });
}); });
test("do not write file with --write + invalid file", () => { describe("do not write file with --write + invalid file", () => {
const result = runPrettier("cli/write", [ runPrettier("cli/write", ["--write", "invalid.js", "--no-color"]).test({
"--write", write: [],
"invalid.js", status: "non-zero"
"--no-color" });
]);
expect(result.stderr).toMatchSnapshot();
expect(result.write).toHaveLength(0);
expect(result.status).not.toEqual(0);
}); });

View File

@ -81,7 +81,27 @@ function runPrettier(dir, args, options) {
jest.restoreAllMocks(); jest.restoreAllMocks();
} }
return { status, stdout, stderr, write }; const result = { status, stdout, stderr, write };
const testResult = testOptions => {
testOptions = testOptions || {};
Object.keys(result).forEach(name => {
test(`(${name})`, () => {
if (name in testOptions) {
if (name === "status" && testOptions[name] === "non-zero") {
expect(result[name]).not.toEqual(0);
} else {
expect(result[name]).toEqual(testOptions[name]);
}
} else {
expect(result[name]).toMatchSnapshot();
}
});
});
};
return { test: testResult };
function appendStdout(text) { function appendStdout(text) {
if (status === undefined) { if (status === undefined) {