2021-12-02 10:19:32 +08:00
|
|
|
|
import { isCI } from "ci-info";
|
2022-03-17 21:32:14 +08:00
|
|
|
|
import { outdent } from "outdent";
|
2023-09-02 09:15:48 +08:00
|
|
|
|
|
2017-10-02 11:08:34 -05:00
|
|
|
|
describe("format correctly if stdin content compatible with stdin-filepath", () => {
|
2023-04-11 08:44:23 +08:00
|
|
|
|
runCli(
|
2017-09-08 15:08:19 +08:00
|
|
|
|
"cli",
|
2017-10-02 12:56:34 -05:00
|
|
|
|
["--stdin-filepath", "abc.css"],
|
2026-06-16 02:09:45 +08:00
|
|
|
|
{ input: ".name { display: none; }" }, // CSS
|
2017-10-02 11:08:34 -05:00
|
|
|
|
).test({
|
|
|
|
|
|
status: 0,
|
|
|
|
|
|
});
|
2017-09-08 15:08:19 +08:00
|
|
|
|
});
|
|
|
|
|
|
|
2017-10-02 11:08:34 -05:00
|
|
|
|
describe("throw error if stdin content incompatible with stdin-filepath", () => {
|
2023-04-11 08:44:23 +08:00
|
|
|
|
runCli(
|
2017-09-08 15:08:19 +08:00
|
|
|
|
"cli",
|
2017-10-02 12:56:34 -05:00
|
|
|
|
["--stdin-filepath", "abc.js"],
|
2026-06-16 02:09:45 +08:00
|
|
|
|
{ input: ".name { display: none; }" }, // CSS
|
2017-10-02 11:08:34 -05:00
|
|
|
|
).test({
|
|
|
|
|
|
status: "non-zero",
|
|
|
|
|
|
});
|
2017-09-08 15:08:19 +08:00
|
|
|
|
});
|
2017-11-23 18:54:04 +08:00
|
|
|
|
|
2019-11-02 07:56:26 -07:00
|
|
|
|
describe("gracefully handle stdin-filepath with nonexistent directory", () => {
|
2023-04-11 08:44:23 +08:00
|
|
|
|
runCli(
|
2019-11-02 07:56:26 -07:00
|
|
|
|
"cli",
|
|
|
|
|
|
["--stdin-filepath", "definitely/nonexistent/path.css"],
|
2026-06-16 02:09:45 +08:00
|
|
|
|
{ input: ".name { display: none; }" }, // CSS
|
2019-11-02 07:56:26 -07:00
|
|
|
|
).test({
|
|
|
|
|
|
status: 0,
|
|
|
|
|
|
});
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
describe("apply editorconfig for stdin-filepath with nonexistent file", () => {
|
2023-04-11 08:44:23 +08:00
|
|
|
|
runCli("cli", ["--stdin-filepath", "config/editorconfig/nonexistent.js"], {
|
|
|
|
|
|
input: outdent`
|
|
|
|
|
|
function f() {
|
|
|
|
|
|
console.log("should be indented with a tab");
|
|
|
|
|
|
}
|
|
|
|
|
|
`, // js
|
|
|
|
|
|
}).test({
|
2019-11-02 07:56:26 -07:00
|
|
|
|
status: 0,
|
|
|
|
|
|
});
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
describe("apply editorconfig for stdin-filepath with nonexistent directory", () => {
|
2023-04-11 08:44:23 +08:00
|
|
|
|
runCli(
|
2019-11-02 07:56:26 -07:00
|
|
|
|
"cli",
|
|
|
|
|
|
["--stdin-filepath", "config/editorconfig/nonexistent/one/two/three.js"],
|
|
|
|
|
|
{
|
2022-03-17 20:13:28 +08:00
|
|
|
|
input: outdent`
|
|
|
|
|
|
function f() {
|
|
|
|
|
|
console.log("should be indented with a tab");
|
|
|
|
|
|
}
|
|
|
|
|
|
`, // js
|
2019-11-02 07:56:26 -07:00
|
|
|
|
},
|
|
|
|
|
|
).test({
|
|
|
|
|
|
status: 0,
|
|
|
|
|
|
});
|
|
|
|
|
|
});
|
|
|
|
|
|
|
2020-08-21 09:43:24 +08:00
|
|
|
|
describe("apply editorconfig for stdin-filepath with a deep path", () => {
|
2023-04-11 08:44:23 +08:00
|
|
|
|
runCli(
|
2020-08-21 09:43:24 +08:00
|
|
|
|
"cli",
|
|
|
|
|
|
["--stdin-filepath", "config/editorconfig/" + "a/".repeat(30) + "three.js"],
|
|
|
|
|
|
{
|
2022-03-17 20:13:28 +08:00
|
|
|
|
input: outdent`
|
|
|
|
|
|
function f() {
|
|
|
|
|
|
console.log("should be indented with a tab");
|
|
|
|
|
|
}
|
|
|
|
|
|
`, // js
|
2020-08-21 09:43:24 +08:00
|
|
|
|
},
|
|
|
|
|
|
).test({
|
|
|
|
|
|
status: 0,
|
|
|
|
|
|
});
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
if (isCI) {
|
|
|
|
|
|
describe("apply editorconfig for stdin-filepath in root", () => {
|
2022-03-17 20:13:28 +08:00
|
|
|
|
const code = outdent`
|
|
|
|
|
|
function f() {
|
|
|
|
|
|
console.log("should be indented with a tab");
|
|
|
|
|
|
}
|
|
|
|
|
|
`;
|
2023-04-11 08:44:23 +08:00
|
|
|
|
runCli("cli", ["--stdin-filepath", "/foo.js"], {
|
2020-08-21 09:43:24 +08:00
|
|
|
|
input: code, // js
|
|
|
|
|
|
}).test({
|
|
|
|
|
|
status: 0,
|
2023-03-30 14:25:28 +08:00
|
|
|
|
stdout: code,
|
2020-08-21 09:43:24 +08:00
|
|
|
|
stderr: "",
|
|
|
|
|
|
write: [],
|
|
|
|
|
|
});
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
describe("apply editorconfig for stdin-filepath with a deep path", () => {
|
2023-04-11 08:44:23 +08:00
|
|
|
|
runCli(
|
2020-08-21 09:43:24 +08:00
|
|
|
|
"cli",
|
|
|
|
|
|
["--stdin-filepath", "config/editorconfig/" + "a/".repeat(30) + "three.js"],
|
|
|
|
|
|
{
|
2022-03-17 20:13:28 +08:00
|
|
|
|
input: outdent`
|
|
|
|
|
|
function f() {
|
|
|
|
|
|
console.log("should be indented with a tab");
|
|
|
|
|
|
}
|
|
|
|
|
|
`, // js
|
2020-08-21 09:43:24 +08:00
|
|
|
|
},
|
|
|
|
|
|
).test({
|
|
|
|
|
|
status: 0,
|
|
|
|
|
|
});
|
|
|
|
|
|
});
|
|
|
|
|
|
|
2019-11-02 07:56:26 -07:00
|
|
|
|
describe("don’t apply editorconfig outside project for stdin-filepath with nonexistent directory", () => {
|
2023-04-11 08:44:23 +08:00
|
|
|
|
runCli(
|
2019-11-02 07:56:26 -07:00
|
|
|
|
"cli",
|
|
|
|
|
|
[
|
|
|
|
|
|
"--stdin-filepath",
|
|
|
|
|
|
"config/editorconfig/repo-root/nonexistent/one/two/three.js",
|
|
|
|
|
|
],
|
|
|
|
|
|
{
|
2022-03-17 20:13:28 +08:00
|
|
|
|
input: outdent`
|
|
|
|
|
|
function f() {
|
|
|
|
|
|
console.log("should be indented with 2 spaces");
|
|
|
|
|
|
}
|
|
|
|
|
|
`, // js
|
2019-11-02 07:56:26 -07:00
|
|
|
|
},
|
|
|
|
|
|
).test({
|
|
|
|
|
|
status: 0,
|
|
|
|
|
|
});
|
|
|
|
|
|
});
|
|
|
|
|
|
|
2017-12-31 14:08:09 -03:00
|
|
|
|
describe("output file as-is if stdin-filepath matched patterns in ignore-path", () => {
|
2023-04-11 08:44:23 +08:00
|
|
|
|
runCli("cli/stdin-ignore", ["--stdin-filepath", "ignore/example.js"], {
|
2017-12-31 14:08:09 -03:00
|
|
|
|
input: "hello_world( );",
|
2017-11-23 18:54:04 +08:00
|
|
|
|
}).test({
|
2017-12-31 14:08:09 -03:00
|
|
|
|
stdout: "hello_world( );",
|
2017-11-23 18:54:04 +08:00
|
|
|
|
status: 0,
|
|
|
|
|
|
});
|
|
|
|
|
|
});
|
2023-09-02 09:15:48 +08:00
|
|
|
|
|
|
|
|
|
|
describe("Should format stdin even if it's empty", () => {
|
|
|
|
|
|
runCli("cli", ["--stdin-filepath", "example.js"], {
|
|
|
|
|
|
isTTY: true,
|
|
|
|
|
|
}).test({
|
|
|
|
|
|
stdout: "",
|
|
|
|
|
|
status: 0,
|
|
|
|
|
|
stderr: "",
|
|
|
|
|
|
write: [],
|
|
|
|
|
|
});
|
|
|
|
|
|
});
|