2018-01-05 13:09:51 +03:00
|
|
|
"use strict";
|
|
|
|
|
|
|
|
const runPrettier = require("../runPrettier");
|
2018-01-22 21:20:50 +03:00
|
|
|
const EOL = require("os").EOL;
|
2018-01-05 13:09:51 +03:00
|
|
|
|
2018-05-09 14:17:12 +03:00
|
|
|
describe("automatically loads 'prettier-plugin-*'", () => {
|
2018-01-05 13:09:51 +03:00
|
|
|
runPrettier("plugins/automatic", ["file.txt", "--parser=foo"]).test({
|
2018-01-22 21:20:50 +03:00
|
|
|
stdout: "foo+contents" + EOL,
|
2018-01-05 13:09:51 +03:00
|
|
|
stderr: "",
|
|
|
|
status: 0,
|
|
|
|
write: []
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-05-09 14:17:12 +03:00
|
|
|
describe("automatically loads '@prettier/plugin-*'", () => {
|
2018-01-05 13:09:51 +03:00
|
|
|
runPrettier("plugins/automatic", ["file.txt", "--parser=bar"]).test({
|
2018-01-22 21:20:50 +03:00
|
|
|
stdout: "bar+contents" + EOL,
|
2018-01-05 13:09:51 +03:00
|
|
|
stderr: "",
|
|
|
|
status: 0,
|
|
|
|
write: []
|
|
|
|
});
|
|
|
|
});
|
2018-05-09 14:17:12 +03:00
|
|
|
|
|
|
|
describe("automatically loads 'prettier-plugin-*' from --plugin-search-dir (same as autoload dir)", () => {
|
|
|
|
runPrettier("plugins/automatic", [
|
|
|
|
"file.txt",
|
|
|
|
"--parser=foo",
|
2018-05-10 03:27:41 +03:00
|
|
|
"--plugin-search-dir=."
|
2018-05-09 14:17:12 +03:00
|
|
|
]).test({
|
|
|
|
stdout: "foo+contents" + EOL,
|
|
|
|
stderr: "",
|
|
|
|
status: 0,
|
|
|
|
write: []
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe("automatically loads '@prettier/plugin-*' from --plugin-search-dir (same as autoload dir)", () => {
|
|
|
|
runPrettier("plugins/automatic", [
|
|
|
|
"file.txt",
|
|
|
|
"--parser=bar",
|
2018-05-10 03:27:41 +03:00
|
|
|
"--plugin-search-dir=."
|
2018-05-09 14:17:12 +03:00
|
|
|
]).test({
|
|
|
|
stdout: "bar+contents" + EOL,
|
|
|
|
stderr: "",
|
|
|
|
status: 0,
|
|
|
|
write: []
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe("automatically loads 'prettier-plugin-*' from --plugin-search-dir (different to autoload dir)", () => {
|
|
|
|
runPrettier("plugins", [
|
|
|
|
"automatic/file.txt",
|
|
|
|
"--parser=foo",
|
2018-05-10 03:27:41 +03:00
|
|
|
"--plugin-search-dir=automatic"
|
2018-05-09 14:17:12 +03:00
|
|
|
]).test({
|
|
|
|
stdout: "foo+contents" + EOL,
|
|
|
|
stderr: "",
|
|
|
|
status: 0,
|
|
|
|
write: []
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe("automatically loads '@prettier/plugin-*' from --plugin-search-dir (different to autoload dir)", () => {
|
|
|
|
runPrettier("plugins", [
|
|
|
|
"automatic/file.txt",
|
|
|
|
"--parser=bar",
|
2018-05-10 03:27:41 +03:00
|
|
|
"--plugin-search-dir=automatic"
|
2018-05-09 14:17:12 +03:00
|
|
|
]).test({
|
|
|
|
stdout: "bar+contents" + EOL,
|
|
|
|
stderr: "",
|
|
|
|
status: 0,
|
|
|
|
write: []
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe("does not crash when --plugin-search-dir does not contain node_modules", () => {
|
|
|
|
runPrettier("plugins/extensions", [
|
|
|
|
"file.foo",
|
|
|
|
"--plugin=./plugin",
|
2018-05-10 03:27:41 +03:00
|
|
|
"--plugin-search-dir=."
|
2018-05-09 14:17:12 +03:00
|
|
|
]).test({
|
|
|
|
stdout: "!contents" + EOL,
|
|
|
|
stderr: "",
|
|
|
|
status: 0,
|
|
|
|
write: []
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe("crashes when one of --plugin-search-dir does not exist", () => {
|
|
|
|
runPrettier("plugins/automatic", [
|
|
|
|
"file.txt",
|
|
|
|
"--parser=foo",
|
2018-05-10 03:27:41 +03:00
|
|
|
"--plugin-search-dir=non-existing-dir",
|
|
|
|
"--plugin-search-dir=."
|
2018-05-09 14:17:12 +03:00
|
|
|
]).test({
|
|
|
|
stdout: "",
|
|
|
|
stderr: "non-existing-dir does not exist or is not a directory",
|
|
|
|
status: 1,
|
|
|
|
write: []
|
|
|
|
});
|
|
|
|
});
|
2018-05-10 03:27:41 +03:00
|
|
|
|
|
|
|
describe("loads --plugin by its relative path", () => {
|
|
|
|
runPrettier("plugins", [
|
|
|
|
"automatic/file.txt",
|
|
|
|
"--parser=bar",
|
|
|
|
"--plugin=./automatic/node_modules/prettier-plugin-bar/index.js"
|
|
|
|
]).test({
|
|
|
|
stdout: "bar+contents" + EOL,
|
|
|
|
stderr: "",
|
|
|
|
status: 0,
|
|
|
|
write: []
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe("loads --plugin by its relative path without leading ./", () => {
|
|
|
|
runPrettier("plugins", [
|
|
|
|
"automatic/file.txt",
|
|
|
|
"--parser=bar",
|
|
|
|
"--plugin=automatic/node_modules/prettier-plugin-bar/index.js"
|
|
|
|
]).test({
|
|
|
|
stdout: "bar+contents" + EOL,
|
|
|
|
stderr: "",
|
|
|
|
status: 0,
|
|
|
|
write: []
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe("loads --plugin by relative path to its directory (assuming index.js)", () => {
|
|
|
|
runPrettier("plugins", [
|
|
|
|
"automatic/file.txt",
|
|
|
|
"--parser=bar",
|
|
|
|
"--plugin=./automatic/node_modules/prettier-plugin-bar"
|
|
|
|
]).test({
|
|
|
|
stdout: "bar+contents" + EOL,
|
|
|
|
stderr: "",
|
|
|
|
status: 0,
|
|
|
|
write: []
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe("loads --plugin by relative path to its directory without leading ./ (assuming index.js)", () => {
|
|
|
|
runPrettier("plugins", [
|
|
|
|
"automatic/file.txt",
|
|
|
|
"--parser=bar",
|
|
|
|
"--plugin=automatic/node_modules/prettier-plugin-bar"
|
|
|
|
]).test({
|
|
|
|
stdout: "bar+contents" + EOL,
|
|
|
|
stderr: "",
|
|
|
|
status: 0,
|
|
|
|
write: []
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe("loads --plugin by bespoke plugin name (assuming it is installed in cwd)", () => {
|
|
|
|
runPrettier("plugins/bespoke", [
|
|
|
|
"../automatic/file.txt",
|
|
|
|
"--parser=bespoke",
|
|
|
|
"--plugin=@company/prettier-plugin-bespoke"
|
|
|
|
]).test({
|
|
|
|
stdout: "bespoke+contents" + EOL,
|
|
|
|
stderr: "",
|
|
|
|
status: 0,
|
|
|
|
write: []
|
|
|
|
});
|
|
|
|
});
|