2017-09-08 10:08:19 +03:00
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
|
|
const runPrettier = require("../runPrettier");
|
|
|
|
|
|
2017-10-02 19:08:34 +03:00
|
|
|
|
describe("format correctly if stdin content compatible with stdin-filepath", () => {
|
|
|
|
|
runPrettier(
|
2017-09-08 10:08:19 +03:00
|
|
|
|
"cli",
|
2017-10-02 20:56:34 +03:00
|
|
|
|
["--stdin-filepath", "abc.css"],
|
2017-09-08 10:08:19 +03:00
|
|
|
|
{ input: ".name { display: none; }" } // css
|
2017-10-02 19:08:34 +03:00
|
|
|
|
).test({
|
|
|
|
|
status: 0
|
|
|
|
|
});
|
2017-09-08 10:08:19 +03:00
|
|
|
|
});
|
|
|
|
|
|
2017-10-02 19:08:34 +03:00
|
|
|
|
describe("throw error if stdin content incompatible with stdin-filepath", () => {
|
|
|
|
|
runPrettier(
|
2017-09-08 10:08:19 +03:00
|
|
|
|
"cli",
|
2017-10-02 20:56:34 +03:00
|
|
|
|
["--stdin-filepath", "abc.js"],
|
2017-09-08 10:08:19 +03:00
|
|
|
|
{ input: ".name { display: none; }" } // css
|
2017-10-02 19:08:34 +03:00
|
|
|
|
).test({
|
|
|
|
|
status: "non-zero"
|
|
|
|
|
});
|
2017-09-08 10:08:19 +03:00
|
|
|
|
});
|
2017-11-23 13:54:04 +03:00
|
|
|
|
|
2019-11-02 17:56:26 +03:00
|
|
|
|
describe("gracefully handle stdin-filepath with nonexistent directory", () => {
|
|
|
|
|
runPrettier(
|
|
|
|
|
"cli",
|
|
|
|
|
["--stdin-filepath", "definitely/nonexistent/path.css"],
|
|
|
|
|
{ input: ".name { display: none; }" } // css
|
|
|
|
|
).test({
|
|
|
|
|
status: 0
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
describe("apply editorconfig for stdin-filepath with nonexistent file", () => {
|
|
|
|
|
runPrettier(
|
|
|
|
|
"cli",
|
|
|
|
|
["--stdin-filepath", "config/editorconfig/nonexistent.js"],
|
|
|
|
|
{
|
|
|
|
|
input: `
|
|
|
|
|
function f() {
|
|
|
|
|
console.log("should be indented with a tab");
|
|
|
|
|
}
|
|
|
|
|
`.trim() // js
|
|
|
|
|
}
|
|
|
|
|
).test({
|
|
|
|
|
status: 0
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
describe("apply editorconfig for stdin-filepath with nonexistent directory", () => {
|
|
|
|
|
runPrettier(
|
|
|
|
|
"cli",
|
|
|
|
|
["--stdin-filepath", "config/editorconfig/nonexistent/one/two/three.js"],
|
|
|
|
|
{
|
|
|
|
|
input: `
|
|
|
|
|
function f() {
|
|
|
|
|
console.log("should be indented with a tab");
|
|
|
|
|
}
|
|
|
|
|
`.trim() // js
|
|
|
|
|
}
|
|
|
|
|
).test({
|
|
|
|
|
status: 0
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
describe("don’t apply editorconfig outside project for stdin-filepath with nonexistent directory", () => {
|
|
|
|
|
runPrettier(
|
|
|
|
|
"cli",
|
|
|
|
|
[
|
|
|
|
|
"--stdin-filepath",
|
|
|
|
|
"config/editorconfig/repo-root/nonexistent/one/two/three.js"
|
|
|
|
|
],
|
|
|
|
|
{
|
|
|
|
|
input: `
|
|
|
|
|
function f() {
|
|
|
|
|
console.log("should be indented with 2 spaces");
|
|
|
|
|
}
|
|
|
|
|
`.trim() // js
|
|
|
|
|
}
|
|
|
|
|
).test({
|
|
|
|
|
status: 0
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2017-12-31 20:08:09 +03:00
|
|
|
|
describe("output file as-is if stdin-filepath matched patterns in ignore-path", () => {
|
2017-11-23 13:54:04 +03:00
|
|
|
|
runPrettier("cli/stdin-ignore", ["--stdin-filepath", "ignore/example.js"], {
|
2017-12-31 20:08:09 +03:00
|
|
|
|
input: "hello_world( );"
|
2017-11-23 13:54:04 +03:00
|
|
|
|
}).test({
|
2017-12-31 20:08:09 +03:00
|
|
|
|
stdout: "hello_world( );",
|
2017-11-23 13:54:04 +03:00
|
|
|
|
status: 0
|
|
|
|
|
});
|
|
|
|
|
});
|