diff --git a/tests_integration/__tests__/__snapshots__/arg-parsing.js.snap b/tests_integration/__tests__/__snapshots__/arg-parsing.js.snap index d2c2e63c..91b0c411 100644 --- a/tests_integration/__tests__/__snapshots__/arg-parsing.js.snap +++ b/tests_integration/__tests__/__snapshots__/arg-parsing.js.snap @@ -1,57 +1,69 @@ // 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'); " `; -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`] = ` -"console.log(\\"could be single quote and without semi\\"); -" -`; - -exports[`deprecated option values are warned 2`] = ` +exports[`deprecated option values are warned (stderr) 1`] = ` "\`--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\\"); " `; -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. " `; -exports[`negated options work 1`] = ` -"console.log(\\"could be single quote and without semi\\") -" -`; - -exports[`negated options work 2`] = `""`; - -exports[`unknown negated options are warned 1`] = ` +exports[`deprecated options are warned (stdout) 1`] = ` "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 " `; -exports[`unknown options are warned 1`] = ` +exports[`unknown negated options are warned (stdout) 1`] = ` "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 " `; + +exports[`unknown options are warned (stdout) 1`] = ` +"console.log(\\"could be single quote and without semi\\"); +" +`; + +exports[`unknown options are warned (write) 1`] = `Array []`; diff --git a/tests_integration/__tests__/__snapshots__/config-invalid.js.snap b/tests_integration/__tests__/__snapshots__/config-invalid.js.snap index 4b0c32e9..78524a69 100644 --- a/tests_integration/__tests__/__snapshots__/config-invalid.js.snap +++ b/tests_integration/__tests__/__snapshots__/config-invalid.js.snap @@ -1,33 +1,57 @@ // 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 " `; -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. Failed to parse \\"/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. 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. 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. 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. 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 []`; diff --git a/tests_integration/__tests__/__snapshots__/config-resolution.js.snap b/tests_integration/__tests__/__snapshots__/config-resolution.js.snap index f607859a..e4ff66ca 100644 --- a/tests_integration/__tests__/__snapshots__/config-resolution.js.snap +++ b/tests_integration/__tests__/__snapshots__/config-resolution.js.snap @@ -1,6 +1,8 @@ // 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( \\"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() { 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 " `; -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/Component.js should not 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() { console.log( \\"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 " `; -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 " `; + +exports[`resolves yaml configuration file with --find-config-path file (write) 1`] = `Array []`; diff --git a/tests_integration/__tests__/__snapshots__/cursot-offset.js.snap b/tests_integration/__tests__/__snapshots__/cursot-offset.js.snap index 5c11f037..ec8eeb83 100644 --- a/tests_integration/__tests__/__snapshots__/cursot-offset.js.snap +++ b/tests_integration/__tests__/__snapshots__/cursot-offset.js.snap @@ -1,11 +1,13 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`write cursorOffset to stderr with --cursor-offset 1`] = ` +exports[`write cursorOffset to stderr with --cursor-offset (stderr) 1`] = ` +"1 +" +`; + +exports[`write cursorOffset to stderr with --cursor-offset (stdout) 1`] = ` "1; " `; -exports[`write cursorOffset to stderr with --cursor-offset 2`] = ` -"1 -" -`; +exports[`write cursorOffset to stderr with --cursor-offset (write) 1`] = `Array []`; diff --git a/tests_integration/__tests__/__snapshots__/debug-check.js.snap b/tests_integration/__tests__/__snapshots__/debug-check.js.snap new file mode 100644 index 00000000..e6df5935 --- /dev/null +++ b/tests_integration/__tests__/__snapshots__/debug-check.js.snap @@ -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 []`; diff --git a/tests_integration/__tests__/__snapshots__/debug-print-doc.js.snap b/tests_integration/__tests__/__snapshots__/debug-print-doc.js.snap new file mode 100644 index 00000000..d4087111 --- /dev/null +++ b/tests_integration/__tests__/__snapshots__/debug-print-doc.js.snap @@ -0,0 +1,3 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`prints doc with --debug-print-doc (write) 1`] = `Array []`; diff --git a/tests_integration/__tests__/__snapshots__/early-exit.js.snap b/tests_integration/__tests__/__snapshots__/early-exit.js.snap index 57550074..f52e6286 100644 --- a/tests_integration/__tests__/__snapshots__/early-exit.js.snap +++ b/tests_integration/__tests__/__snapshots__/early-exit.js.snap @@ -1,6 +1,8 @@ // 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 ...] 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 + + 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 Which parser to use. @@ -368,27 +516,13 @@ Default: babylon " `; -exports[`show warning with --help not-found (typo) 2`] = ` -"Unknown option name \\"parserr\\", did you mean \\"parser\\"? +exports[`show warning with --help not-found (typo) (write) 1`] = `Array []`; -" -`; +exports[`show warning with --help not-found (write) 1`] = `Array []`; -exports[`show warning with --help not-found 1`] = ` -"-h, --help +exports[`throw error and show usage with something unexpected (stderr) 1`] = `""`; - Show CLI usage, or details about the given flag. - 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`] = ` +exports[`throw error and show usage with something unexpected (stdout) 1`] = ` "Usage: prettier [options] [file/glob ...] 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 " `; -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. " `; + +exports[`throw error with --write + --debug-check (stdout) 1`] = `""`; + +exports[`throw error with --write + --debug-check (write) 1`] = `Array []`; diff --git a/tests_integration/__tests__/__snapshots__/ignore-absolute-path.js.snap b/tests_integration/__tests__/__snapshots__/ignore-absolute-path.js.snap index a396d0f8..32694e8e 100644 --- a/tests_integration/__tests__/__snapshots__/ignore-absolute-path.js.snap +++ b/tests_integration/__tests__/__snapshots__/ignore-absolute-path.js.snap @@ -1,6 +1,10 @@ // 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 " `; + +exports[`support absolute filename (write) 1`] = `Array []`; diff --git a/tests_integration/__tests__/__snapshots__/ignore-path.js.snap b/tests_integration/__tests__/__snapshots__/ignore-path.js.snap index d88c338b..32cd5821 100644 --- a/tests_integration/__tests__/__snapshots__/ignore-path.js.snap +++ b/tests_integration/__tests__/__snapshots__/ignore-path.js.snap @@ -1,11 +1,19 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`ignore path 1`] = ` +exports[`ignore path (stderr) 1`] = `""`; + +exports[`ignore path (stdout) 1`] = ` "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 " `; + +exports[`support .prettierignore (write) 1`] = `Array []`; diff --git a/tests_integration/__tests__/__snapshots__/invalid-ignore.js.snap b/tests_integration/__tests__/__snapshots__/invalid-ignore.js.snap index ba39faeb..1a004e09 100644 --- a/tests_integration/__tests__/__snapshots__/invalid-ignore.js.snap +++ b/tests_integration/__tests__/__snapshots__/invalid-ignore.js.snap @@ -1,6 +1,10 @@ // 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 /tests_integration/cli/invalid-ignore/.prettierignore: " `; + +exports[`throw error with invalid ignore (stdout) 1`] = `""`; + +exports[`throw error with invalid ignore (write) 1`] = `Array []`; diff --git a/tests_integration/__tests__/__snapshots__/list-different.js.snap b/tests_integration/__tests__/__snapshots__/list-different.js.snap new file mode 100644 index 00000000..8e00c14e --- /dev/null +++ b/tests_integration/__tests__/__snapshots__/list-different.js.snap @@ -0,0 +1,3 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`checks stdin with --list-different (write) 1`] = `Array []`; diff --git a/tests_integration/__tests__/__snapshots__/multiple-patterns.js.snap b/tests_integration/__tests__/__snapshots__/multiple-patterns.js.snap index 23d6bf4b..c1f0bfe0 100644 --- a/tests_integration/__tests__/__snapshots__/multiple-patterns.js.snap +++ b/tests_integration/__tests__/__snapshots__/multiple-patterns.js.snap @@ -1,6 +1,8 @@ // 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/nested-directory/nested-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 other-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/nested-directory/nested-directory-file.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/nested-directory/nested-directory-file.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 other-directory/file.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/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/** " `; + +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 []`; diff --git a/tests_integration/__tests__/__snapshots__/parser-api.js.snap b/tests_integration/__tests__/__snapshots__/parser-api.js.snap index e01429b3..047ca6ac 100644 --- a/tests_integration/__tests__/__snapshots__/parser-api.js.snap +++ b/tests_integration/__tests__/__snapshots__/parser-api.js.snap @@ -1,7 +1,11 @@ // 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 */ bar(); " `; + +exports[`allows passing a string to resolve a parser (write) 1`] = `Array []`; diff --git a/tests_integration/__tests__/__snapshots__/stdin-filepath.js.snap b/tests_integration/__tests__/__snapshots__/stdin-filepath.js.snap index 822c4ab1..6041b6c6 100644 --- a/tests_integration/__tests__/__snapshots__/stdin-filepath.js.snap +++ b/tests_integration/__tests__/__snapshots__/stdin-filepath.js.snap @@ -1,19 +1,23 @@ // 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 { 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 2`] = ` +exports[`throw error if stdin content incompatible with stdin-filepath (stderr) 1`] = ` "stdin: SyntaxError: Unexpected token (1:1) > 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 []`; diff --git a/tests_integration/__tests__/__snapshots__/syntax-error.js.snap b/tests_integration/__tests__/__snapshots__/syntax-error.js.snap new file mode 100644 index 00000000..efc4f61d --- /dev/null +++ b/tests_integration/__tests__/__snapshots__/syntax-error.js.snap @@ -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 []`; diff --git a/tests_integration/__tests__/__snapshots__/with-config-precedence.js.snap b/tests_integration/__tests__/__snapshots__/with-config-precedence.js.snap index b27fe3a2..28efd980 100644 --- a/tests_integration/__tests__/__snapshots__/with-config-precedence.js.snap +++ b/tests_integration/__tests__/__snapshots__/with-config-precedence.js.snap @@ -1,28 +1,40 @@ // 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() " `; -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(); " `; -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(); " `; -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() { 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() { console.log( \\"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() { 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() { 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( \\"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( \\"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. 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. 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. 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 []`; diff --git a/tests_integration/__tests__/__snapshots__/with-node-modules.js.snap b/tests_integration/__tests__/__snapshots__/with-node-modules.js.snap index 9bb5c7f5..a76fb42c 100644 --- a/tests_integration/__tests__/__snapshots__/with-node-modules.js.snap +++ b/tests_integration/__tests__/__snapshots__/with-node-modules.js.snap @@ -1,33 +1,53 @@ // 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 not_node_modules/file.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 not_node_modules/file.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 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 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 ./regular-module.js " `; + +exports[`ignores node_modules by with ./**/*.js (write) 1`] = `Array []`; diff --git a/tests_integration/__tests__/__snapshots__/with-parser-inference.js.snap b/tests_integration/__tests__/__snapshots__/with-parser-inference.js.snap index 5117e3e0..a36fd289 100644 --- a/tests_integration/__tests__/__snapshots__/with-parser-inference.js.snap +++ b/tests_integration/__tests__/__snapshots__/with-parser-inference.js.snap @@ -1,6 +1,8 @@ // 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 */ \\"use strict\\"; /* 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 []`; diff --git a/tests_integration/__tests__/__snapshots__/with-shebang.js.snap b/tests_integration/__tests__/__snapshots__/with-shebang.js.snap index bbd86897..807b89ad 100644 --- a/tests_integration/__tests__/__snapshots__/with-shebang.js.snap +++ b/tests_integration/__tests__/__snapshots__/with-shebang.js.snap @@ -1,7 +1,11 @@ // 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 \\"use strict\\"; " `; + +exports[`preserves shebang (write) 1`] = `Array []`; diff --git a/tests_integration/__tests__/__snapshots__/write.js.snap b/tests_integration/__tests__/__snapshots__/write.js.snap index bc3daa98..d54cbffc 100644 --- a/tests_integration/__tests__/__snapshots__/write.js.snap +++ b/tests_integration/__tests__/__snapshots__/write.js.snap @@ -1,13 +1,32 @@ // 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) > 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 [ Object { "content": "var x = 1; diff --git a/tests_integration/__tests__/arg-parsing.js b/tests_integration/__tests__/arg-parsing.js index 7465a2a0..36420e2d 100644 --- a/tests_integration/__tests__/arg-parsing.js +++ b/tests_integration/__tests__/arg-parsing.js @@ -2,53 +2,38 @@ const runPrettier = require("../runPrettier"); -test("boolean flags do not swallow the next argument", () => { - const result = runPrettier("cli/arg-parsing", ["--single-quote", "file.js"]); - - expect(result.stdout).toMatchSnapshot(); - expect(result.stderr).toMatchSnapshot(); - expect(result.status).toEqual(0); +describe("boolean flags do not swallow the next argument", () => { + runPrettier("cli/arg-parsing", ["--single-quote", "file.js"]).test({ + status: 0 + }); }); -test("negated options work", () => { - const result = runPrettier("cli/arg-parsing", ["--no-semi", "file.js"]); - - expect(result.stdout).toMatchSnapshot(); - expect(result.stderr).toMatchSnapshot(); - expect(result.status).toEqual(0); +describe("negated options work", () => { + runPrettier("cli/arg-parsing", ["--no-semi", "file.js"]).test({ + status: 0 + }); }); -test("unknown options are warned", () => { - const result = runPrettier("cli/arg-parsing", ["file.js", "--unknown"]); - - expect(result.stdout).toMatchSnapshot(); - expect(result.stderr).toMatchSnapshot(); - expect(result.status).toEqual(0); +describe("unknown options are warned", () => { + runPrettier("cli/arg-parsing", ["file.js", "--unknown"]).test({ + status: 0 + }); }); -test("unknown negated options are warned", () => { - const result = runPrettier("cli/arg-parsing", ["file.js", "--no-unknown"]); - - expect(result.stdout).toMatchSnapshot(); - expect(result.stderr).toMatchSnapshot(); - expect(result.status).toEqual(0); +describe("unknown negated options are warned", () => { + runPrettier("cli/arg-parsing", ["file.js", "--no-unknown"]).test({ + status: 0 + }); }); -test("deprecated options are warned", () => { - const result = runPrettier("cli/arg-parsing", ["file.js", "--flow-parser"]); - - expect(result.stdout).toMatchSnapshot(); - expect(result.stderr).toMatchSnapshot(); - expect(result.status).toEqual(0); +describe("deprecated options are warned", () => { + runPrettier("cli/arg-parsing", ["file.js", "--flow-parser"]).test({ + status: 0 + }); }); -test("deprecated option values are warned", () => { - const result = runPrettier("cli/arg-parsing", [ - "file.js", - "--trailing-comma" - ]); - - expect(result.stdout).toMatchSnapshot(); - expect(result.stderr).toMatchSnapshot(); - expect(result.status).toEqual(0); +describe("deprecated option values are warned", () => { + runPrettier("cli/arg-parsing", ["file.js", "--trailing-comma"]).test({ + status: 0 + }); }); diff --git a/tests_integration/__tests__/config-invalid.js b/tests_integration/__tests__/config-invalid.js index 9bdce5fa..82a3c86a 100644 --- a/tests_integration/__tests__/config-invalid.js +++ b/tests_integration/__tests__/config-invalid.js @@ -4,53 +4,44 @@ const runPrettier = require("../runPrettier"); expect.addSnapshotSerializer(require("../path-serializer")); -test("throw error with invalid config format", () => { - const output = runPrettier("cli/config/invalid", [ - "--config", - "file/.prettierrc" - ]); - expect(output.stderr).toMatchSnapshot(); - expect(output.status).not.toBe(0); +describe("throw error with invalid config format", () => { + runPrettier("cli/config/invalid", ["--config", "file/.prettierrc"]).test({ + status: "non-zero" + }); }); -test("throw error with invalid config target (directory)", () => { - const output = runPrettier("cli/config/invalid", [ +describe("throw error with invalid config target (directory)", () => { + runPrettier("cli/config/invalid", [ "--config", "folder/.prettierrc" // this is a directory - ]); - expect(output.stderr).toMatchSnapshot(); - expect(output.status).not.toBe(0); + ]).test({ + status: "non-zero" + }); }); -test("throw error with invalid config option (int)", () => { - const output = runPrettier("cli/config/invalid", ["--config", "option/int"]); - expect(output.stderr).toMatchSnapshot(); - expect(output.status).not.toBe(0); +describe("throw error with invalid config option (int)", () => { + runPrettier("cli/config/invalid", ["--config", "option/int"]).test({ + status: "non-zero" + }); }); -test("throw error with invalid config option (trailingComma)", () => { - const output = runPrettier("cli/config/invalid", [ - "--config", - "option/trailingComma" - ]); - expect(output.stderr).toMatchSnapshot(); - expect(output.status).not.toBe(0); +describe("throw error with invalid config option (trailingComma)", () => { + runPrettier("cli/config/invalid", ["--config", "option/trailingComma"]).test({ + status: "non-zero" + }); }); -test("throw error with invalid config precedence option (configPrecedence)", () => { - const output = runPrettier("cli/config/invalid", [ +describe("throw error with invalid config precedence option (configPrecedence)", () => { + runPrettier("cli/config/invalid", [ "--config-precedence", "option/configPrecedence" - ]); - expect(output.stderr).toMatchSnapshot(); - expect(output.status).not.toBe(0); + ]).test({ + status: "non-zero" + }); }); -test("show warning with unknown option", () => { - const output = runPrettier("cli/config/invalid", [ - "--config", - "option/unknown" - ]); - expect(output.stderr).toMatchSnapshot(); - expect(output.status).toBe(0); +describe("show warning with unknown option", () => { + runPrettier("cli/config/invalid", ["--config", "option/unknown"]).test({ + status: 0 + }); }); diff --git a/tests_integration/__tests__/config-resolution.js b/tests_integration/__tests__/config-resolution.js index ef6a8a78..dcd3e48c 100644 --- a/tests_integration/__tests__/config-resolution.js +++ b/tests_integration/__tests__/config-resolution.js @@ -7,65 +7,53 @@ const prettier = require("../../tests_config/require_prettier"); expect.addSnapshotSerializer(require("../path-serializer")); -test("resolves configuration from external files", () => { - const output = runPrettier("cli/config/", ["**/*.js"]); - expect(output.stdout).toMatchSnapshot(); - expect(output.status).toEqual(0); +describe("resolves configuration from external files", () => { + runPrettier("cli/config/", ["**/*.js"]).test({ + status: 0 + }); }); -test("resolves configuration from external files and overrides by extname", () => { - const output = runPrettier("cli/config/", ["**/*.ts"]); - expect(output.stdout).toMatchSnapshot(); - expect(output.status).toEqual(0); +describe("resolves configuration from external files and overrides by extname", () => { + runPrettier("cli/config/", ["**/*.ts"]).test({ + status: 0 + }); }); -test("accepts configuration from --config", () => { - const output = runPrettier("cli/config/", [ - "--config", - ".prettierrc", - "./js/file.js" - ]); - expect(output.stdout).toMatchSnapshot(); - expect(output.status).toEqual(0); +describe("accepts configuration from --config", () => { + runPrettier("cli/config/", ["--config", ".prettierrc", "./js/file.js"]).test({ + status: 0 + }); }); -test("resolves configuration file with --find-config-path file", () => { - const output = runPrettier("cli/config/", [ - "--find-config-path", - "no-config/file.js" - ]); - expect(output.stdout).toMatchSnapshot(); - expect(output.status).toEqual(0); +describe("resolves configuration file with --find-config-path file", () => { + runPrettier("cli/config/", ["--find-config-path", "no-config/file.js"]).test({ + status: 0 + }); }); -test("resolves json configuration file with --find-config-path file", () => { - const output = runPrettier("cli/config/", [ - "--find-config-path", - "rc-json/file.js" - ]); - expect(output.stdout).toMatchSnapshot(); - expect(output.status).toEqual(0); +describe("resolves json configuration file with --find-config-path file", () => { + runPrettier("cli/config/", ["--find-config-path", "rc-json/file.js"]).test({ + status: 0 + }); }); -test("resolves yaml configuration file with --find-config-path file", () => { - const output = runPrettier("cli/config/", [ - "--find-config-path", - "rc-yaml/file.js" - ]); - expect(output.stdout).toMatchSnapshot(); - expect(output.status).toEqual(0); +describe("resolves yaml configuration file with --find-config-path file", () => { + runPrettier("cli/config/", ["--find-config-path", "rc-yaml/file.js"]).test({ + status: 0 + }); }); -test("prints nothing when no file found with --find-config-path", () => { - const output = runPrettier("cli/config/", ["--find-config-path", ".."]); - expect(output.stdout).toEqual(""); - expect(output.status).toEqual(1); +describe("prints nothing when no file found with --find-config-path", () => { + runPrettier("cli/config/", ["--find-config-path", ".."]).test({ + stdout: "", + status: 1 + }); }); -test("CLI overrides take precedence", () => { - const output = runPrettier("cli/config/", ["--print-width", "1", "**/*.js"]); - expect(output.stdout).toMatchSnapshot(); - expect(output.status).toEqual(0); +describe("CLI overrides take precedence", () => { + runPrettier("cli/config/", ["--print-width", "1", "**/*.js"]).test({ + status: 0 + }); }); test("API resolveConfig with no args", () => { diff --git a/tests_integration/__tests__/cursot-offset.js b/tests_integration/__tests__/cursot-offset.js index d0b371e1..011d6b87 100644 --- a/tests_integration/__tests__/cursot-offset.js +++ b/tests_integration/__tests__/cursot-offset.js @@ -2,10 +2,8 @@ const runPrettier = require("../runPrettier"); -test("write cursorOffset to stderr with --cursor-offset ", () => { - const result = runPrettier("cli", ["--cursor-offset", "2"], { input: " 1" }); - - expect(result.stdout).toMatchSnapshot(); - expect(result.stderr).toMatchSnapshot(); - expect(result.status).toEqual(0); +describe("write cursorOffset to stderr with --cursor-offset ", () => { + runPrettier("cli", ["--cursor-offset", "2"], { input: " 1" }).test({ + status: 0 + }); }); diff --git a/tests_integration/__tests__/debug-check.js b/tests_integration/__tests__/debug-check.js index 1ec62b88..40b3120e 100644 --- a/tests_integration/__tests__/debug-check.js +++ b/tests_integration/__tests__/debug-check.js @@ -2,23 +2,20 @@ const runPrettier = require("../runPrettier"); -test("doesn't crash when --debug-check is passed", () => { - const result = runPrettier("cli/with-shebang", [ - "issue1890.js", - "--debug-check" - ]); - - expect(result.stdout).toEqual("issue1890.js\n"); - expect(result.stderr).toEqual(""); - expect(result.status).toEqual(0); -}); - -test("checks stdin with --debug-check", () => { - const result = runPrettier("cli/with-shebang", ["--debug-check"], { - input: "0" +describe("doesn't crash when --debug-check is passed", () => { + runPrettier("cli/with-shebang", ["issue1890.js", "--debug-check"]).test({ + stdout: "issue1890.js\n", + stderr: "", + status: 0 + }); +}); + +describe("checks stdin with --debug-check", () => { + runPrettier("cli/with-shebang", ["--debug-check"], { + input: "0" + }).test({ + stdout: "(stdin)\n", + stderr: "", + status: 0 }); - - expect(result.stdout).toEqual("(stdin)\n"); - expect(result.stderr).toEqual(""); - expect(result.status).toEqual(0); }); diff --git a/tests_integration/__tests__/debug-print-doc.js b/tests_integration/__tests__/debug-print-doc.js index 7e0d0d22..954b7284 100644 --- a/tests_integration/__tests__/debug-print-doc.js +++ b/tests_integration/__tests__/debug-print-doc.js @@ -2,12 +2,12 @@ const runPrettier = require("../runPrettier"); -test("prints doc with --debug-print-doc", () => { - const result = runPrettier("cli/with-shebang", ["--debug-print-doc"], { +describe("prints doc with --debug-print-doc", () => { + runPrettier("cli/with-shebang", ["--debug-print-doc"], { 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); }); diff --git a/tests_integration/__tests__/early-exit.js b/tests_integration/__tests__/early-exit.js index 19f73bea..43dedb85 100644 --- a/tests_integration/__tests__/early-exit.js +++ b/tests_integration/__tests__/early-exit.js @@ -4,24 +4,23 @@ const prettier = require("../../tests_config/require_prettier"); const runPrettier = require("../runPrettier"); const constant = require("../../src/cli-constant"); -test("show version with --version", () => { - const result = runPrettier("cli/with-shebang", ["--version"]); - - expect(result.stdout).toBe(prettier.version + "\n"); - expect(result.status).toEqual(0); +describe("show version with --version", () => { + runPrettier("cli/with-shebang", ["--version"]).test({ + stdout: prettier.version + "\n", + status: 0 + }); }); -test("show usage with --help", () => { - const result = runPrettier("cli", ["--help"]); - - expect(result.stdout).toMatchSnapshot(); - expect(result.status).toEqual(0); +describe("show usage with --help", () => { + runPrettier("cli", ["--help"]).test({ + status: 0 + }); }); -test(`show detailed usage with --help l (alias)`, () => { - const result = runPrettier("cli", ["--help", "l"]); - expect(result.stdout).toMatchSnapshot(); - expect(result.status).toEqual(0); +describe(`show detailed usage with --help l (alias)`, () => { + runPrettier("cli", ["--help", "l"]).test({ + status: 0 + }); }); constant.detailedOptions.forEach(option => { @@ -31,48 +30,40 @@ constant.detailedOptions.forEach(option => { ].filter(Boolean); optionNames.forEach(optionName => { - test(`show detailed usage with --help ${optionName}`, () => { - const result = runPrettier("cli", ["--help", optionName]); - expect(result.stdout).toMatchSnapshot(); - expect(result.status).toEqual(0); + describe(`show detailed usage with --help ${optionName}`, () => { + runPrettier("cli", ["--help", optionName]).test({ + status: 0 + }); }); }); }); -test("show warning with --help not-found", () => { - const result = runPrettier("cli", ["--help", "not-found"]); - - expect(result.stdout).toMatchSnapshot(); - expect(result.stderr).toMatchSnapshot(); - expect(result.status).toEqual(0); +describe("show warning with --help not-found", () => { + runPrettier("cli", ["--help", "not-found"]).test({ + status: 0 + }); }); -test("show warning with --help not-found (typo)", () => { - const result = runPrettier("cli", ["--help", "parserr"]); - - expect(result.stdout).toMatchSnapshot(); - expect(result.stderr).toMatchSnapshot(); - expect(result.status).toEqual(0); +describe("show warning with --help not-found (typo)", () => { + runPrettier("cli", ["--help", "parserr"]).test({ + status: 0 + }); }); -test("throw error with --write + --debug-check", () => { - const result = runPrettier("cli", ["--write", "--debug-check"]); - - expect(result.stderr).toMatchSnapshot(); - expect(result.status).toEqual(1); +describe("throw error with --write + --debug-check", () => { + runPrettier("cli", ["--write", "--debug-check"]).test({ + status: 1 + }); }); -test("throw error with --find-config-path + multiple files", () => { - const result = runPrettier("cli", ["--find-config-path", "abc.js", "def.js"]); - - expect(result.stderr).toMatchSnapshot(); - expect(result.status).toEqual(1); +describe("throw error with --find-config-path + multiple files", () => { + runPrettier("cli", ["--find-config-path", "abc.js", "def.js"]).test({ + status: 1 + }); }); -test("throw error and show usage with something unexpected", () => { - const result = runPrettier("cli", [], { isTTY: true }); - - expect(result.stdout).toMatchSnapshot(); - expect(result.stderr).toMatchSnapshot(); - expect(result.status).not.toEqual(0); +describe("throw error and show usage with something unexpected", () => { + runPrettier("cli", [], { isTTY: true }).test({ + status: "non-zero" + }); }); diff --git a/tests_integration/__tests__/ignore-absolute-path.js b/tests_integration/__tests__/ignore-absolute-path.js index 8e46de3f..a69714a7 100644 --- a/tests_integration/__tests__/ignore-absolute-path.js +++ b/tests_integration/__tests__/ignore-absolute-path.js @@ -3,14 +3,13 @@ const path = require("path"); const runPrettier = require("../runPrettier"); -test("support absolute filename", () => { - const result = runPrettier("cli/ignore-absolute-path", [ +describe("support absolute filename", () => { + runPrettier("cli/ignore-absolute-path", [ 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/regular-module.js"), "-l" - ]); - - expect(result.stdout).toMatchSnapshot(); - expect(result.status).toEqual(1); + ]).test({ + status: 1 + }); }); diff --git a/tests_integration/__tests__/ignore-path.js b/tests_integration/__tests__/ignore-path.js index fd7fba0e..f6a49363 100644 --- a/tests_integration/__tests__/ignore-path.js +++ b/tests_integration/__tests__/ignore-path.js @@ -2,21 +2,19 @@ const runPrettier = require("../runPrettier"); -test("ignore path", () => { - const result = runPrettier("cli/ignore-path", [ +describe("ignore path", () => { + runPrettier("cli/ignore-path", [ "**/*.js", "--ignore-path", ".gitignore", "-l" - ]); - - expect(result.stdout).toMatchSnapshot(); - expect(result.status).toEqual(1); + ]).test({ + status: 1 + }); }); -test("support .prettierignore", () => { - const result = runPrettier("cli/ignore-path", ["**/*.js", "-l"]); - - expect(result.stdout).toMatchSnapshot(); - expect(result.status).toEqual(1); +describe("support .prettierignore", () => { + runPrettier("cli/ignore-path", ["**/*.js", "-l"]).test({ + status: 1 + }); }); diff --git a/tests_integration/__tests__/invalid-ignore.js b/tests_integration/__tests__/invalid-ignore.js index 874fbe97..1d1fda68 100644 --- a/tests_integration/__tests__/invalid-ignore.js +++ b/tests_integration/__tests__/invalid-ignore.js @@ -4,9 +4,8 @@ const runPrettier = require("../runPrettier"); expect.addSnapshotSerializer(require("../path-serializer")); -test("throw error with invalid ignore", () => { - const result = runPrettier("cli/invalid-ignore", ["something.js"]); - - expect(result.stderr).toMatchSnapshot(); - expect(result.status).not.toEqual(0); +describe("throw error with invalid ignore", () => { + runPrettier("cli/invalid-ignore", ["something.js"]).test({ + status: "non-zero" + }); }); diff --git a/tests_integration/__tests__/list-different.js b/tests_integration/__tests__/list-different.js index 7ed2ee80..48b4d03f 100644 --- a/tests_integration/__tests__/list-different.js +++ b/tests_integration/__tests__/list-different.js @@ -2,12 +2,12 @@ const runPrettier = require("../runPrettier"); -test("checks stdin with --list-different", () => { - const result = runPrettier("cli/with-shebang", ["--list-different"], { +describe("checks stdin with --list-different", () => { + runPrettier("cli/with-shebang", ["--list-different"], { 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); }); diff --git a/tests_integration/__tests__/multiple-patterns.js b/tests_integration/__tests__/multiple-patterns.js index 06016ba4..772715cf 100644 --- a/tests_integration/__tests__/multiple-patterns.js +++ b/tests_integration/__tests__/multiple-patterns.js @@ -2,85 +2,79 @@ const runPrettier = require("../runPrettier"); -test("multiple patterns", () => { - const result = runPrettier("cli/multiple-patterns", [ +describe("multiple patterns", () => { + runPrettier("cli/multiple-patterns", [ "directory/**/*.js", "other-directory/**/*.js", "-l" - ]); - - expect(result.stdout).toMatchSnapshot(); - expect(result.status).toEqual(1); + ]).test({ + status: 1 + }); }); -test("multiple patterns with non exists pattern", () => { - const result = runPrettier("cli/multiple-patterns", [ +describe("multiple patterns with non exists pattern", () => { + runPrettier("cli/multiple-patterns", [ "directory/**/*.js", "non-existent.js", "-l" - ]); - - expect(result.stdout).toMatchSnapshot(); - expect(result.status).toEqual(1); + ]).test({ + status: 1 + }); }); -test("multiple patterns with ignore nested directories pattern", () => { - const result = runPrettier("cli/multiple-patterns", [ +describe("multiple patterns with ignore nested directories pattern", () => { + runPrettier("cli/multiple-patterns", [ "**/*.js", "!**/nested-directory/**", "-l" - ]); - - expect(result.stdout).toMatchSnapshot(); - expect(result.status).toEqual(1); + ]).test({ + status: 1 + }); }); -test("multiple patterns by with ignore pattern, ignores node_modules by default", () => { - const result = runPrettier("cli/multiple-patterns", [ +describe("multiple patterns by with ignore pattern, ignores node_modules by default", () => { + runPrettier("cli/multiple-patterns", [ "**/*.js", "!directory/**", "-l" - ]); - - expect(result.stdout).toMatchSnapshot(); - expect(result.status).toEqual(1); + ]).test({ + status: 1 + }); }); -test("multiple patterns by with ignore pattern, ignores node_modules by with ./**/*.js", () => { - const result = runPrettier("cli/multiple-patterns", [ +describe("multiple patterns by with ignore pattern, ignores node_modules by with ./**/*.js", () => { + runPrettier("cli/multiple-patterns", [ "./**/*.js", "!./directory/**", "-l" - ]); - - expect(result.stdout).toMatchSnapshot(); - expect(result.status).toEqual(1); + ]).test({ + status: 1 + }); }); -test("multiple patterns by with ignore pattern, doesn't ignore node_modules with --with-node-modules flag", () => { - const result = runPrettier("cli/multiple-patterns", [ +describe("multiple patterns by with ignore pattern, doesn't ignore node_modules with --with-node-modules flag", () => { + runPrettier("cli/multiple-patterns", [ "**/*.js", "!directory/**", "-l", "--with-node-modules" - ]); - - expect(result.stdout).toMatchSnapshot(); - expect(result.status).toEqual(1); + ]).test({ + status: 1 + }); }); -test("no errors on empty patterns", () => { - const result = runPrettier("cli/multiple-patterns"); - expect(result.status).toEqual(0); +describe("no errors on empty patterns", () => { + runPrettier("cli/multiple-patterns").test({ + status: 0 + }); }); -test("multiple patterns, throw error and exit with non zero code on non existing files", () => { - const result = runPrettier("cli/multiple-patterns", [ +describe("multiple patterns, throw error and exit with non zero code on non existing files", () => { + runPrettier("cli/multiple-patterns", [ "non-existent.js", "other-non-existent.js", "-l" - ]); - - expect(result.stderr).toMatchSnapshot(); - expect(result.status).toEqual(2); + ]).test({ + status: 2 + }); }); diff --git a/tests_integration/__tests__/parser-api.js b/tests_integration/__tests__/parser-api.js index 19bdea7d..104f79d1 100644 --- a/tests_integration/__tests__/parser-api.js +++ b/tests_integration/__tests__/parser-api.js @@ -29,12 +29,12 @@ test("allows usage of prettier's supported parsers", () => { expect(output).toEqual("bar();\n"); }); -test("allows passing a string to resolve a parser", () => { - const output = runPrettier("./custom-parsers/", [ +describe("allows passing a string to resolve a parser", () => { + runPrettier("./custom-parsers/", [ "./custom-rename-input.js", "--parser", "./custom-rename-parser" - ]); - expect(output.stdout).toMatchSnapshot(); - expect(output.status).toEqual(0); + ]).test({ + status: 0 + }); }); diff --git a/tests_integration/__tests__/stdin-filepath.js b/tests_integration/__tests__/stdin-filepath.js index ce708d91..b3b4a793 100644 --- a/tests_integration/__tests__/stdin-filepath.js +++ b/tests_integration/__tests__/stdin-filepath.js @@ -2,26 +2,22 @@ const runPrettier = require("../runPrettier"); -test("format correctly if stdin content compatible with stdin-filepath", () => { - const result = runPrettier( +describe("format correctly if stdin content compatible with stdin-filepath", () => { + runPrettier( "cli", ["--no-color", "--stdin-filepath", "abc.css"], { input: ".name { display: none; }" } // css - ); - - expect(result.stdout).toMatchSnapshot(); - expect(result.stderr).toMatchSnapshot(); - expect(result.status).toEqual(0); + ).test({ + status: 0 + }); }); -test("throw error if stdin content incompatible with stdin-filepath", () => { - const result = runPrettier( +describe("throw error if stdin content incompatible with stdin-filepath", () => { + runPrettier( "cli", ["--no-color", "--stdin-filepath", "abc.js"], { input: ".name { display: none; }" } // css - ); - - expect(result.stdout).toMatchSnapshot(); - expect(result.stderr).toMatchSnapshot(); - expect(result.status).not.toEqual(0); + ).test({ + status: "non-zero" + }); }); diff --git a/tests_integration/__tests__/syntax-error.js b/tests_integration/__tests__/syntax-error.js index 064b8805..a55f429d 100644 --- a/tests_integration/__tests__/syntax-error.js +++ b/tests_integration/__tests__/syntax-error.js @@ -2,10 +2,10 @@ const runPrettier = require("../runPrettier"); -test("exits with non-zero code when input has a syntax error", () => { - const result = runPrettier("cli/with-shebang", ["--stdin"], { +describe("exits with non-zero code when input has a syntax error", () => { + runPrettier("cli/with-shebang", ["--stdin", "--no-color"], { input: "a.2" + }).test({ + status: 2 }); - - expect(result.status).toEqual(2); }); diff --git a/tests_integration/__tests__/with-config-precedence.js b/tests_integration/__tests__/with-config-precedence.js index b367a96f..1120884b 100644 --- a/tests_integration/__tests__/with-config-precedence.js +++ b/tests_integration/__tests__/with-config-precedence.js @@ -2,50 +2,50 @@ const runPrettier = require("../runPrettier"); -test("CLI overrides take precedence without --config-precedence", () => { - const output = runPrettier("cli/config/", ["--print-width", "1", "**/*.js"]); - expect(output.stdout).toMatchSnapshot(); - expect(output.status).toEqual(0); +describe("CLI overrides take precedence without --config-precedence", () => { + runPrettier("cli/config/", ["--print-width", "1", "**/*.js"]).test({ + status: 0 + }); }); -test("CLI overrides take precedence with --config-precedence cli-override", () => { - const output = runPrettier("cli/config/", [ +describe("CLI overrides take precedence with --config-precedence cli-override", () => { + runPrettier("cli/config/", [ "--print-width", "1", "--config-precedence", "cli-override", "**/*.js" - ]); - expect(output.stdout).toMatchSnapshot(); - expect(output.status).toEqual(0); + ]).test({ + status: 0 + }); }); -test("CLI overrides take lower precedence with --config-precedence file-override", () => { - const output = runPrettier("cli/config/js/", [ +describe("CLI overrides take lower precedence with --config-precedence file-override", () => { + runPrettier("cli/config/js/", [ "--tab-width", "1", "--config-precedence", "file-override", "**/*.js" - ]); - expect(output.stdout).toMatchSnapshot(); - expect(output.status).toEqual(0); + ]).test({ + status: 0 + }); }); -test("CLI overrides are still applied when no config is found with --config-precedence file-override", () => { - const output = runPrettier("cli/config/no-config/", [ +describe("CLI overrides are still applied when no config is found with --config-precedence file-override", () => { + runPrettier("cli/config/no-config/", [ "--tab-width", "6", "--config-precedence", "file-override", "**/*.js" - ]); - expect(output.stdout).toMatchSnapshot(); - expect(output.status).toEqual(0); + ]).test({ + status: 0 + }); }); -test("CLI overrides gets ignored when config exists with --config-precedence prefer-file", () => { - const output = runPrettier("cli/config/js/", [ +describe("CLI overrides gets ignored when config exists with --config-precedence prefer-file", () => { + runPrettier("cli/config/js/", [ "--print-width", "1", "--tab-width", @@ -53,13 +53,13 @@ test("CLI overrides gets ignored when config exists with --config-precedence pre "--config-precedence", "prefer-file", "**/*.js" - ]); - expect(output.stdout).toMatchSnapshot(); - expect(output.status).toEqual(0); + ]).test({ + status: 0 + }); }); -test("CLI overrides gets applied when no config exists with --config-precedence prefer-file", () => { - const output = runPrettier("cli/config/no-config/", [ +describe("CLI overrides gets applied when no config exists with --config-precedence prefer-file", () => { + runPrettier("cli/config/no-config/", [ "--print-width", "1", "--tab-width", @@ -68,40 +68,40 @@ test("CLI overrides gets applied when no config exists with --config-precedence "--config-precedence", "prefer-file", "**/*.js" - ]); - expect(output.stdout).toMatchSnapshot(); - expect(output.status).toEqual(0); + ]).test({ + status: 0 + }); }); -test("CLI validate options with --config-precedence cli-override", () => { - const output = runPrettier("cli/config-precedence", [ +describe("CLI validate options with --config-precedence cli-override", () => { + runPrettier("cli/config-precedence", [ "--config-precedence", "cli-override" - ]); - expect(output.stderr).toMatchSnapshot(); - expect(output.status).not.toEqual(0); + ]).test({ + status: "non-zero" + }); }); -test("CLI validate options with --config-precedence file-override", () => { - const output = runPrettier("cli/config-precedence", [ +describe("CLI validate options with --config-precedence file-override", () => { + runPrettier("cli/config-precedence", [ "--config-precedence", "file-override" - ]); - expect(output.stderr).toMatchSnapshot(); - expect(output.status).not.toEqual(0); + ]).test({ + status: "non-zero" + }); }); -test("CLI validate options with --config-precedence prefer-file", () => { - const output = runPrettier("cli/config-precedence", [ +describe("CLI validate options with --config-precedence prefer-file", () => { + runPrettier("cli/config-precedence", [ "--config-precedence", "prefer-file" - ]); - expect(output.stderr).toMatchSnapshot(); - expect(output.status).not.toEqual(0); + ]).test({ + status: "non-zero" + }); }); -test("CLI --stdin-filepath works with --config-precedence prefer-file", () => { - const result = runPrettier( +describe("CLI --stdin-filepath works with --config-precedence prefer-file", () => { + runPrettier( "cli/config/", [ "--no-color", @@ -111,15 +111,14 @@ test("CLI --stdin-filepath works with --config-precedence prefer-file", () => { "--config-precedence=prefer-file" ], { input: "let x: keyof Y = foo()" } // typescript - ); - - expect(result.stdout).toMatchSnapshot(); - expect(result.stderr).toEqual(""); - expect(result.status).toEqual(0); + ).test({ + stderr: "", + status: 0 + }); }); -test("CLI --stdin-filepath works with --config-precedence file-override", () => { - const result = runPrettier( +describe("CLI --stdin-filepath works with --config-precedence file-override", () => { + runPrettier( "cli/config/", [ "--no-color", @@ -129,15 +128,14 @@ test("CLI --stdin-filepath works with --config-precedence file-override", () => "--config-precedence=file-override" ], { input: "let x: keyof Y = foo()" } // typescript - ); - - expect(result.stdout).toMatchSnapshot(); - expect(result.stderr).toEqual(""); - expect(result.status).toEqual(0); + ).test({ + stderr: "", + status: 0 + }); }); -test("CLI --stdin-filepath works with --config-precedence cli-override", () => { - const result = runPrettier( +describe("CLI --stdin-filepath works with --config-precedence cli-override", () => { + runPrettier( "cli/config/", [ "--no-color", @@ -147,9 +145,8 @@ test("CLI --stdin-filepath works with --config-precedence cli-override", () => { "--config-precedence=cli-override" ], { input: "let x: keyof Y = foo()" } // typescript - ); - - expect(result.stdout).toMatchSnapshot(); - expect(result.stderr).toEqual(""); - expect(result.status).toEqual(0); + ).test({ + stderr: "", + status: 0 + }); }); diff --git a/tests_integration/__tests__/with-node-modules.js b/tests_integration/__tests__/with-node-modules.js index 492e28c9..d1d7014b 100644 --- a/tests_integration/__tests__/with-node-modules.js +++ b/tests_integration/__tests__/with-node-modules.js @@ -2,52 +2,47 @@ const runPrettier = require("../runPrettier"); -test("ignores node_modules by default", () => { - const result = runPrettier("cli/with-node-modules", ["**/*.js", "-l"]); - - expect(result.stdout).toMatchSnapshot(); - expect(result.status).toEqual(1); +describe("ignores node_modules by default", () => { + runPrettier("cli/with-node-modules", ["**/*.js", "-l"]).test({ + status: 1 + }); }); -test("ignores node_modules by with ./**/*.js", () => { - const result = runPrettier("cli/with-node-modules", ["./**/*.js", "-l"]); - - expect(result.stdout).toMatchSnapshot(); - expect(result.status).toEqual(1); +describe("ignores node_modules by with ./**/*.js", () => { + runPrettier("cli/with-node-modules", ["./**/*.js", "-l"]).test({ + status: 1 + }); }); -test("doesn't ignore node_modules with --with-node-modules flag", () => { - const result = runPrettier("cli/with-node-modules", [ +describe("doesn't ignore node_modules with --with-node-modules flag", () => { + runPrettier("cli/with-node-modules", [ "**/*.js", "-l", "--with-node-modules" - ]); - - expect(result.stdout).toMatchSnapshot(); - expect(result.status).toEqual(1); + ]).test({ + status: 1 + }); }); -test("ignores node_modules by default for file list", () => { - const result = runPrettier("cli/with-node-modules", [ +describe("ignores node_modules by default for file list", () => { + runPrettier("cli/with-node-modules", [ "node_modules/node-module.js", "not_node_modules/file.js", "regular-module.js", "-l" - ]); - - expect(result.stdout).toMatchSnapshot(); - expect(result.status).toEqual(1); + ]).test({ + status: 1 + }); }); -test("doesn't ignore node_modules with --with-node-modules flag for file list", () => { - const result = runPrettier("cli/with-node-modules", [ +describe("doesn't ignore node_modules with --with-node-modules flag for file list", () => { + runPrettier("cli/with-node-modules", [ "node_modules/node-module.js", "not_node_modules/file.js", "regular-module.js", "-l", "--with-node-modules" - ]); - - expect(result.stdout).toMatchSnapshot(); - expect(result.status).toEqual(1); + ]).test({ + status: 1 + }); }); diff --git a/tests_integration/__tests__/with-parser-inference.js b/tests_integration/__tests__/with-parser-inference.js index f6acad02..c27646c7 100644 --- a/tests_integration/__tests__/with-parser-inference.js +++ b/tests_integration/__tests__/with-parser-inference.js @@ -2,19 +2,14 @@ const runPrettier = require("../runPrettier"); -test("infers postcss parser", () => { - const result = runPrettier("cli/with-parser-inference", ["*"]); - - expect(result.stdout).toMatchSnapshot(); - expect(result.status).toEqual(0); +describe("infers postcss parser", () => { + runPrettier("cli/with-parser-inference", ["*"]).test({ + status: 0 + }); }); -test("infers postcss parser with --list-different", () => { - const result = runPrettier("cli/with-parser-inference", [ - "--list-different", - "*" - ]); - - expect(result.stdout).toMatchSnapshot(); - expect(result.status).toEqual(0); +describe("infers postcss parser with --list-different", () => { + runPrettier("cli/with-parser-inference", ["--list-different", "*"]).test({ + status: 0 + }); }); diff --git a/tests_integration/__tests__/with-shebang.js b/tests_integration/__tests__/with-shebang.js index e3dfa2b5..e90f6363 100644 --- a/tests_integration/__tests__/with-shebang.js +++ b/tests_integration/__tests__/with-shebang.js @@ -2,9 +2,8 @@ const runPrettier = require("../runPrettier"); -test("preserves shebang", () => { - const result = runPrettier("cli/with-shebang", ["issue1890.js"]); - - expect(result.stdout).toMatchSnapshot(); - expect(result.status).toEqual(0); +describe("preserves shebang", () => { + runPrettier("cli/with-shebang", ["issue1890.js"]).test({ + status: 0 + }); }); diff --git a/tests_integration/__tests__/write.js b/tests_integration/__tests__/write.js index 002cb139..8f7405ef 100644 --- a/tests_integration/__tests__/write.js +++ b/tests_integration/__tests__/write.js @@ -2,28 +2,22 @@ const runPrettier = require("../runPrettier"); -test("write file with --write + unformated file", () => { - const result = runPrettier("cli/write", ["--write", "unformated.js"]); - - expect(result.write).toMatchSnapshot(); - expect(result.status).toEqual(0); +describe("write file with --write + unformated file", () => { + runPrettier("cli/write", ["--write", "unformated.js"]).test({ + status: 0 + }); }); -test("do not write file with --write + formated file", () => { - const result = runPrettier("cli/write", ["--write", "formated.js"]); - - expect(result.write).toHaveLength(0); - expect(result.status).toEqual(0); +describe("do not write file with --write + formated file", () => { + runPrettier("cli/write", ["--write", "formated.js"]).test({ + write: [], + status: 0 + }); }); -test("do not write file with --write + invalid file", () => { - const result = runPrettier("cli/write", [ - "--write", - "invalid.js", - "--no-color" - ]); - - expect(result.stderr).toMatchSnapshot(); - expect(result.write).toHaveLength(0); - expect(result.status).not.toEqual(0); +describe("do not write file with --write + invalid file", () => { + runPrettier("cli/write", ["--write", "invalid.js", "--no-color"]).test({ + write: [], + status: "non-zero" + }); }); diff --git a/tests_integration/runPrettier.js b/tests_integration/runPrettier.js index 1d2e4da0..91281886 100644 --- a/tests_integration/runPrettier.js +++ b/tests_integration/runPrettier.js @@ -81,7 +81,27 @@ function runPrettier(dir, args, options) { 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) { if (status === undefined) {