2017-09-03 16:31:33 +03:00
|
|
|
"use strict";
|
|
|
|
|
2017-10-02 18:58:55 +03:00
|
|
|
const prettier = require("../../tests_config/require_prettier");
|
2017-09-03 16:31:33 +03:00
|
|
|
const runPrettier = require("../runPrettier");
|
2017-09-21 08:54:13 +03:00
|
|
|
const constant = require("../../src/cli-constant");
|
2017-09-03 16:31:33 +03:00
|
|
|
|
|
|
|
test("show version with --version", () => {
|
|
|
|
const result = runPrettier("cli/with-shebang", ["--version"]);
|
|
|
|
|
|
|
|
expect(result.stdout).toBe(prettier.version + "\n");
|
|
|
|
expect(result.status).toEqual(0);
|
|
|
|
});
|
|
|
|
|
|
|
|
test("show usage with --help", () => {
|
|
|
|
const result = runPrettier("cli", ["--help"]);
|
|
|
|
|
|
|
|
expect(result.stdout).toMatchSnapshot();
|
|
|
|
expect(result.status).toEqual(0);
|
|
|
|
});
|
|
|
|
|
2017-09-21 08:54:13 +03:00
|
|
|
test(`show detailed usage with --help l (alias)`, () => {
|
|
|
|
const result = runPrettier("cli", ["--help", "l"]);
|
|
|
|
expect(result.stdout).toMatchSnapshot();
|
|
|
|
expect(result.status).toEqual(0);
|
|
|
|
});
|
|
|
|
|
|
|
|
constant.detailedOptions.forEach(option => {
|
|
|
|
const optionNames = [
|
|
|
|
option.description ? option.name : null,
|
|
|
|
option.oppositeDescription ? `no-${option.name}` : null
|
|
|
|
].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);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
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);
|
|
|
|
});
|
|
|
|
|
|
|
|
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);
|
|
|
|
});
|
|
|
|
|
2017-09-03 16:31:33 +03:00
|
|
|
test("throw error with --write + --debug-check", () => {
|
|
|
|
const result = runPrettier("cli", ["--write", "--debug-check"]);
|
|
|
|
|
|
|
|
expect(result.stderr).toMatchSnapshot();
|
|
|
|
expect(result.status).toEqual(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);
|
|
|
|
});
|
2017-09-09 06:49:22 +03:00
|
|
|
|
|
|
|
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);
|
|
|
|
});
|