diff --git a/tests_integration/__tests__/__snapshots__/early-exit.js.snap b/tests_integration/__tests__/__snapshots__/early-exit.js.snap index c802b58f..776d6921 100644 --- a/tests_integration/__tests__/__snapshots__/early-exit.js.snap +++ b/tests_integration/__tests__/__snapshots__/early-exit.js.snap @@ -58,6 +58,66 @@ Uncategorized options: " `; +exports[`throw error and show usage with something unexpected 1`] = ` +"Usage: prettier [opts] [filename ...] + +Config options: + + --config Path to a prettier configuration file (.prettierrc, package.json, prettier.config.js). + --config-precedence + Defines how config file should be evaluated in combination of CLI options + cli-override | default config => config file => CLI options + file-override | default config => CLI options => config file + prefer-file | default config => config file (if config file is found) or + default config => CLI options (if no config file is found) + Defaults to cli-override + --find-config-path + Finds and prints the path to a configuration file for a given input file. + --ignore-path Path to a file containing patterns that describe files to ignore. + Defaults to ./.prettierignore. + --no-config Do not look for a configuration file. + --with-node-modules Process files inside 'node_modules' directory. + +Format options: + + --jsx-bracket-same-line Put > on the last line instead of at a new line. + --no-bracket-spacing Do not print spaces between brackets. + --no-semi Do not print semicolons, except at the beginning of lines which may need them. + --parser + Specify which parse to use. Defaults to babylon. + --print-width Specify the length of line that the printer will wrap on. Defaults to 80. + --range-end Format code ending at a given character offset (exclusive). + The range will extend forwards to the end of the selected statement. + This option cannot be used with --cursor-offset. + Defaults to Infinity. + --range-start Format code starting at a given character offset. + The range will extend backwards to the start of the first line containing the selected statement. + This option cannot be used with --cursor-offset. + Defaults to 0. + --single-quote Use single quotes instead of double quotes. + --tab-width Specify the number of spaces per indentation-level. Defaults to 2. + --trailing-comma + Print trailing commas wherever possible when multi-line. Defaults to none. + --use-tabs Indent lines with tabs instead of spaces. + +Uncategorized options: + + --cursor-offset Print (to stderr) where a cursor at the given position would move to after formatting. + This option cannot be used with --range-start and --range-end + --help or -h Show help. + --list-different or -l Print filenames of files that are different from Prettier formatting. + --no-color Do not colorize error messages. + --stdin Read input from stdin. + --stdin-filepath Path to the file used to read from stdin. + --version or -v Print Prettier version. + --write Edit the file in-place. (Beware!) + + +" +`; + +exports[`throw error and show usage with something unexpected 2`] = `""`; + exports[`throw error with --find-config-path + multiple files 1`] = ` "Cannot use --find-config-path with multiple files " diff --git a/tests_integration/__tests__/early-exit.js b/tests_integration/__tests__/early-exit.js index 95bdc75b..f3f86cd5 100644 --- a/tests_integration/__tests__/early-exit.js +++ b/tests_integration/__tests__/early-exit.js @@ -30,3 +30,11 @@ test("throw error with --find-config-path + multiple files", () => { expect(result.stderr).toMatchSnapshot(); expect(result.status).toEqual(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); +}); diff --git a/tests_integration/runPrettier.js b/tests_integration/runPrettier.js index ec9f0022..86229e99 100644 --- a/tests_integration/runPrettier.js +++ b/tests_integration/runPrettier.js @@ -4,6 +4,9 @@ const fs = require("fs"); const path = require("path"); function runPrettier(dir, args, options) { + args = args || []; + options = options || {}; + let status; let stdout = ""; let stderr = ""; @@ -43,12 +46,12 @@ function runPrettier(dir, args, options) { const originalStdinIsTTY = process.stdin.isTTY; process.chdir(normalizeDir(dir)); - process.stdin.isTTY = false; - process.argv = ["path/to/node", "path/to/prettier/bin"].concat(args || []); + process.stdin.isTTY = !!options.isTTY; + process.argv = ["path/to/node", "path/to/prettier/bin"].concat(args); jest.resetModules(); jest.setMock("get-stream", () => ({ - then: handler => handler((options && options.input) || "") + then: handler => handler(options.input || "") })); try {