Files

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

149 lines
3.3 KiB
JavaScript
Raw Permalink Normal View History

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
describe("format correctly if stdin content compatible with stdin-filepath", () => {
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
).test({
status: 0,
});
2017-09-08 15:08:19 +08:00
});
describe("throw error if stdin content incompatible with stdin-filepath", () => {
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
).test({
status: "non-zero",
});
2017-09-08 15:08:19 +08:00
});
describe("gracefully handle stdin-filepath with nonexistent directory", () => {
runCli(
"cli",
["--stdin-filepath", "definitely/nonexistent/path.css"],
2026-06-16 02:09:45 +08:00
{ input: ".name { display: none; }" }, // CSS
).test({
status: 0,
});
});
describe("apply editorconfig for stdin-filepath with nonexistent file", () => {
runCli("cli", ["--stdin-filepath", "config/editorconfig/nonexistent.js"], {
input: outdent`
function f() {
console.log("should be indented with a tab");
}
`, // js
}).test({
status: 0,
});
});
describe("apply editorconfig for stdin-filepath with nonexistent directory", () => {
runCli(
"cli",
["--stdin-filepath", "config/editorconfig/nonexistent/one/two/three.js"],
{
input: outdent`
function f() {
console.log("should be indented with a tab");
}
`, // js
},
).test({
status: 0,
});
});
2020-08-21 09:43:24 +08:00
describe("apply editorconfig for stdin-filepath with a deep path", () => {
runCli(
2020-08-21 09:43:24 +08:00
"cli",
["--stdin-filepath", "config/editorconfig/" + "a/".repeat(30) + "three.js"],
{
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", () => {
const code = outdent`
function f() {
console.log("should be indented with a tab");
}
`;
runCli("cli", ["--stdin-filepath", "/foo.js"], {
2020-08-21 09:43:24 +08:00
input: code, // js
}).test({
status: 0,
stdout: code,
2020-08-21 09:43:24 +08:00
stderr: "",
write: [],
});
});
}
describe("apply editorconfig for stdin-filepath with a deep path", () => {
runCli(
2020-08-21 09:43:24 +08:00
"cli",
["--stdin-filepath", "config/editorconfig/" + "a/".repeat(30) + "three.js"],
{
input: outdent`
function f() {
console.log("should be indented with a tab");
}
`, // js
2020-08-21 09:43:24 +08:00
},
).test({
status: 0,
});
});
describe("don’t apply editorconfig outside project for stdin-filepath with nonexistent directory", () => {
runCli(
"cli",
[
"--stdin-filepath",
"config/editorconfig/repo-root/nonexistent/one/two/three.js",
],
{
input: outdent`
function f() {
console.log("should be indented with 2 spaces");
}
`, // js
},
).test({
status: 0,
});
});
2017-12-31 14:08:09 -03:00
describe("output file as-is if stdin-filepath matched patterns in ignore-path", () => {
runCli("cli/stdin-ignore", ["--stdin-filepath", "ignore/example.js"], {
2017-12-31 14:08:09 -03:00
input: "hello_world( );",
}).test({
2017-12-31 14:08:09 -03:00
stdout: "hello_world( );",
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: [],
});
});