2025-10-09 22:00:33 +08:00
|
|
|
import { createTwoFilesPatch } from "diff";
|
|
|
|
|
|
2021-05-09 20:43:10 +08:00
|
|
|
test("show external options with `--help`", async () => {
|
2023-04-11 08:44:23 +08:00
|
|
|
const originalStdout = await runCli("plugins/options-string", ["--help"])
|
2019-11-02 04:52:49 -04:00
|
|
|
.stdout;
|
2023-04-11 08:44:23 +08:00
|
|
|
const pluggedStdout = await runCli("plugins/options-string", [
|
2019-11-02 04:52:49 -04:00
|
|
|
"--help",
|
2021-12-03 15:41:12 +08:00
|
|
|
"--plugin=./plugin.cjs",
|
2019-11-02 04:52:49 -04:00
|
|
|
]).stdout;
|
2025-10-09 22:00:33 +08:00
|
|
|
expect(
|
|
|
|
|
createTwoFilesPatch(
|
|
|
|
|
"Without plugin",
|
|
|
|
|
"With plugin",
|
|
|
|
|
originalStdout,
|
|
|
|
|
pluggedStdout,
|
|
|
|
|
),
|
|
|
|
|
).toMatchSnapshot();
|
2019-11-02 04:52:49 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
describe("show detailed external option with `--help foo-string`", () => {
|
2023-04-11 08:44:23 +08:00
|
|
|
runCli("plugins/options-string", [
|
2021-12-03 15:41:12 +08:00
|
|
|
"--plugin=./plugin.cjs",
|
2019-11-02 04:52:49 -04:00
|
|
|
"--help",
|
|
|
|
|
"foo-string",
|
|
|
|
|
]).test({
|
|
|
|
|
status: 0,
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
describe("external options from CLI should work", () => {
|
2023-04-11 08:44:23 +08:00
|
|
|
runCli(
|
2019-11-02 04:52:49 -04:00
|
|
|
"plugins/options-string",
|
|
|
|
|
[
|
2021-12-03 15:41:12 +08:00
|
|
|
"--plugin=./plugin.cjs",
|
2019-11-02 04:52:49 -04:00
|
|
|
"--stdin-filepath",
|
|
|
|
|
"example.foo",
|
|
|
|
|
"--foo-string",
|
|
|
|
|
"baz",
|
|
|
|
|
],
|
|
|
|
|
{ input: "hello-world" },
|
|
|
|
|
).test({
|
|
|
|
|
stdout: "foo:baz",
|
|
|
|
|
stderr: "",
|
|
|
|
|
status: 0,
|
|
|
|
|
write: [],
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
describe("external options from config file should work", () => {
|
2023-04-11 08:44:23 +08:00
|
|
|
runCli(
|
2019-11-02 04:52:49 -04:00
|
|
|
"plugins/options-string",
|
|
|
|
|
["--config=./config.json", "--stdin-filepath", "example.foo"],
|
|
|
|
|
{ input: "hello-world" },
|
|
|
|
|
).test({
|
|
|
|
|
stdout: "foo:baz",
|
|
|
|
|
stderr: "",
|
|
|
|
|
status: 0,
|
|
|
|
|
write: [],
|
|
|
|
|
});
|
|
|
|
|
});
|
2020-08-21 09:43:24 +08:00
|
|
|
|
|
|
|
|
describe("Non exists plugin", () => {
|
2023-04-11 08:44:23 +08:00
|
|
|
runCli(
|
2020-08-21 09:43:24 +08:00
|
|
|
"plugins/options-string",
|
|
|
|
|
["--plugin=--invalid--", "--stdin-filepath", "example.foo"],
|
|
|
|
|
{ input: "hello-world" },
|
|
|
|
|
).test({
|
|
|
|
|
stdout: "",
|
2025-12-21 23:44:08 +08:00
|
|
|
stderr: expect.stringMatching(/Cannot find package '--invalid--'/),
|
2020-08-21 09:43:24 +08:00
|
|
|
status: 1,
|
|
|
|
|
write: [],
|
|
|
|
|
});
|
|
|
|
|
});
|