2017-09-03 21:31:33 +08:00
|
|
|
"use strict";
|
|
|
|
|
|
2018-05-27 21:36:12 +10:00
|
|
|
const prettier = require("prettier/local");
|
2017-09-03 21:31:33 +08:00
|
|
|
const runPrettier = require("../runPrettier");
|
|
|
|
|
|
2017-10-02 11:08:34 -05:00
|
|
|
describe("show version with --version", () => {
|
|
|
|
|
runPrettier("cli/with-shebang", ["--version"]).test({
|
|
|
|
|
stdout: prettier.version + "\n",
|
2020-03-21 22:07:52 +02:00
|
|
|
status: 0,
|
2017-10-02 11:08:34 -05:00
|
|
|
});
|
2017-09-03 21:31:33 +08:00
|
|
|
});
|
|
|
|
|
|
2017-10-02 11:08:34 -05:00
|
|
|
describe("show usage with --help", () => {
|
|
|
|
|
runPrettier("cli", ["--help"]).test({
|
2020-03-21 22:07:52 +02:00
|
|
|
status: 0,
|
2017-10-02 11:08:34 -05:00
|
|
|
});
|
2017-09-03 21:31:33 +08:00
|
|
|
});
|
|
|
|
|
|
2020-01-14 18:58:20 +08:00
|
|
|
describe("show detailed usage with --help l (alias)", () => {
|
2017-10-02 11:08:34 -05:00
|
|
|
runPrettier("cli", ["--help", "l"]).test({
|
2020-03-21 22:07:52 +02:00
|
|
|
status: 0,
|
2017-10-02 11:08:34 -05:00
|
|
|
});
|
2017-09-21 13:54:13 +08:00
|
|
|
});
|
|
|
|
|
|
2020-01-14 18:58:20 +08:00
|
|
|
describe("show detailed usage with plugin options (automatic resolution)", () => {
|
2018-02-27 14:20:02 +01:00
|
|
|
runPrettier("plugins/automatic", [
|
|
|
|
|
"--help",
|
|
|
|
|
"tab-width",
|
2018-05-09 12:17:12 +01:00
|
|
|
"--parser=bar",
|
2020-03-21 22:07:52 +02:00
|
|
|
"--plugin-search-dir=.",
|
2018-02-27 14:20:02 +01:00
|
|
|
]).test({
|
2020-03-21 22:07:52 +02:00
|
|
|
status: 0,
|
2018-02-27 14:20:02 +01:00
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2020-01-14 18:58:20 +08:00
|
|
|
describe("show detailed usage with plugin options (manual resolution)", () => {
|
2018-02-27 14:20:02 +01:00
|
|
|
runPrettier("cli", [
|
|
|
|
|
"--help",
|
|
|
|
|
"tab-width",
|
|
|
|
|
"--plugin=../plugins/automatic/node_modules/prettier-plugin-bar",
|
2020-03-21 22:07:52 +02:00
|
|
|
"--parser=bar",
|
2018-02-27 14:20:02 +01:00
|
|
|
]).test({
|
2020-03-21 22:07:52 +02:00
|
|
|
status: 0,
|
2018-02-27 14:20:02 +01:00
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2018-09-08 07:40:09 +08:00
|
|
|
describe("throw error with --help not-found", () => {
|
2017-10-02 11:08:34 -05:00
|
|
|
runPrettier("cli", ["--help", "not-found"]).test({
|
2020-03-21 22:07:52 +02:00
|
|
|
status: 1,
|
2017-10-02 11:08:34 -05:00
|
|
|
});
|
2017-09-21 13:54:13 +08:00
|
|
|
});
|
|
|
|
|
|
2017-10-02 11:08:34 -05:00
|
|
|
describe("show warning with --help not-found (typo)", () => {
|
2020-04-12 01:19:00 +08:00
|
|
|
runPrettier("cli", [
|
|
|
|
|
"--help",
|
|
|
|
|
// cspell:disable-next-line
|
|
|
|
|
"parserr",
|
|
|
|
|
]).test({
|
2020-03-21 22:07:52 +02:00
|
|
|
status: 0,
|
2017-10-02 11:08:34 -05:00
|
|
|
});
|
2017-09-21 13:54:13 +08:00
|
|
|
});
|
|
|
|
|
|
2018-12-19 14:03:30 +00:00
|
|
|
describe("throw error with --check + --list-different", () => {
|
|
|
|
|
runPrettier("cli", ["--check", "--list-different"]).test({
|
2020-03-21 22:07:52 +02:00
|
|
|
status: 1,
|
2018-12-19 14:03:30 +00:00
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2017-10-02 11:08:34 -05:00
|
|
|
describe("throw error with --write + --debug-check", () => {
|
|
|
|
|
runPrettier("cli", ["--write", "--debug-check"]).test({
|
2020-03-21 22:07:52 +02:00
|
|
|
status: 1,
|
2017-10-02 11:08:34 -05:00
|
|
|
});
|
2017-09-03 21:31:33 +08:00
|
|
|
});
|
|
|
|
|
|
2017-10-02 11:08:34 -05:00
|
|
|
describe("throw error with --find-config-path + multiple files", () => {
|
|
|
|
|
runPrettier("cli", ["--find-config-path", "abc.js", "def.js"]).test({
|
2020-03-21 22:07:52 +02:00
|
|
|
status: 1,
|
2017-10-02 11:08:34 -05:00
|
|
|
});
|
2017-09-03 21:31:33 +08:00
|
|
|
});
|
2017-09-09 11:49:22 +08:00
|
|
|
|
2018-05-09 17:53:44 +01:00
|
|
|
describe("throw error with --file-info + multiple files", () => {
|
|
|
|
|
runPrettier("cli", ["--file-info", "abc.js", "def.js"]).test({
|
2020-03-21 22:07:52 +02:00
|
|
|
status: 1,
|
2018-05-09 17:53:44 +01:00
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2017-10-02 11:08:34 -05:00
|
|
|
describe("throw error and show usage with something unexpected", () => {
|
|
|
|
|
runPrettier("cli", [], { isTTY: true }).test({
|
2020-03-21 22:07:52 +02:00
|
|
|
status: "non-zero",
|
2017-10-02 11:08:34 -05:00
|
|
|
});
|
2017-09-09 11:49:22 +08:00
|
|
|
});
|
2020-03-23 03:32:05 +02:00
|
|
|
|
|
|
|
|
describe("node version error", () => {
|
|
|
|
|
const originalProcessVersion = process.version;
|
|
|
|
|
try {
|
|
|
|
|
Object.defineProperty(process, "version", {
|
|
|
|
|
value: "v8.0.0",
|
|
|
|
|
writable: false,
|
|
|
|
|
});
|
|
|
|
|
runPrettier("cli", ["--help"]).test({ status: 1 });
|
|
|
|
|
} finally {
|
|
|
|
|
Object.defineProperty(process, "version", {
|
|
|
|
|
value: originalProcessVersion,
|
|
|
|
|
writable: false,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
});
|