Skip to content

Commit 623d399

Browse files
committed
test: rename old TestCli to TestBaseCli and introduce new TestCli
1 parent 2672ffd commit 623d399

File tree

8 files changed

+62
-60
lines changed

8 files changed

+62
-60
lines changed

packages/clerc/test/clerc.test.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ import { TestCli } from "@clerc/test-utils";
22
import { afterAll, afterEach, describe, expect, it } from "vitest";
33
import { mockConsole } from "vitest-console";
44

5-
import { Clerc } from "../src";
6-
75
describe("clerc", () => {
86
const { clearConsole, restoreConsole } = mockConsole({ quiet: true });
97

@@ -13,11 +11,11 @@ describe("clerc", () => {
1311

1412
it("should extend BaseClerc", async () => {
1513
expect(async () => {
16-
await TestCli(Clerc as any).parse([]);
17-
await TestCli(Clerc as any).parse(["help"]);
18-
await TestCli(Clerc as any).parse(["--help"]);
19-
await TestCli(Clerc as any).parse(["version"]);
20-
await TestCli(Clerc as any).parse(["--version"]);
14+
await TestCli().parse([]);
15+
await TestCli().parse(["help"]);
16+
await TestCli().parse(["--help"]);
17+
await TestCli().parse(["version"]);
18+
await TestCli().parse(["--version"]);
2119
}).not.toThrow();
2220
});
2321
});

packages/core/test/cli.test.ts

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import { TestCli } from "@clerc/test-utils";
1+
import { TestBaseCli } from "@clerc/test-utils";
22
import { describe, expect, it } from "vitest";
33

44
import { defineCommand } from "../src";
55

66
describe("cli", () => {
77
it("should parse", () => {
8-
TestCli()
8+
TestBaseCli()
99
.command("foo", "foo")
1010
.on("foo", (ctx) => {
1111
expect(ctx.command.name).toBe("foo");
@@ -26,21 +26,21 @@ describe("cli", () => {
2626
});
2727

2828
it("should handle scriptName and name", () => {
29-
const cli = TestCli().name("test name").scriptName("test");
29+
const cli = TestBaseCli().name("test name").scriptName("test");
3030

3131
expect(cli._name).toBe("test name");
3232
expect(cli._scriptName).toBe("test");
3333
});
3434

3535
it("should handle return scriptName when name is not set", () => {
36-
const cli = TestCli();
36+
const cli = TestBaseCli();
3737

3838
expect(cli._name).toBe("test");
3939
expect(cli._scriptName).toBe("test");
4040
});
4141

4242
it("should handle root", () => {
43-
TestCli()
43+
TestBaseCli()
4444
.command("", "root", {
4545
flags: {
4646
foo: {
@@ -89,7 +89,7 @@ describe("cli", () => {
8989
})
9090
.parse(["bar", "--foo", "baz", "qux"]);
9191

92-
TestCli()
92+
TestBaseCli()
9393
.command("", "root", {
9494
flags: {
9595
foo: {
@@ -133,7 +133,7 @@ describe("cli", () => {
133133
});
134134

135135
it("should parse parameters", () => {
136-
TestCli()
136+
TestBaseCli()
137137
.command("foo", "foo", {
138138
parameters: ["[optional...]"],
139139
})
@@ -145,7 +145,7 @@ describe("cli", () => {
145145
});
146146

147147
it("should parse boolean flag", () => {
148-
TestCli()
148+
TestBaseCli()
149149
.command("foo", "foo", {
150150
flags: {
151151
foo: {
@@ -178,7 +178,7 @@ describe("cli", () => {
178178
});
179179

180180
it("should parse string flag", () => {
181-
TestCli()
181+
TestBaseCli()
182182
.command("foo", "foo", {
183183
flags: {
184184
foo: {
@@ -197,7 +197,7 @@ describe("cli", () => {
197197
});
198198

199199
it("should parse number flag", () => {
200-
TestCli()
200+
TestBaseCli()
201201
.command("foo", "foo", {
202202
flags: {
203203
foo: {
@@ -216,7 +216,7 @@ describe("cli", () => {
216216
});
217217

218218
it("should parse dot-nested flag", () => {
219-
TestCli()
219+
TestBaseCli()
220220
.command("foo", "foo", {
221221
flags: {
222222
foo: {
@@ -238,7 +238,7 @@ describe("cli", () => {
238238
});
239239

240240
it("should parse shorthand flag", () => {
241-
TestCli()
241+
TestBaseCli()
242242
.command("foo", "foo")
243243
.on("foo", (ctx) => {
244244
expect(ctx.command.name).toBe("foo");
@@ -249,7 +249,7 @@ describe("cli", () => {
249249
});
250250

251251
it("should parse array flag", () => {
252-
TestCli()
252+
TestBaseCli()
253253
.command("foo", "foo", {
254254
flags: {
255255
abc: {
@@ -269,7 +269,7 @@ describe("cli", () => {
269269

270270
it("should handle interceptor", () => {
271271
let count = 0;
272-
TestCli()
272+
TestBaseCli()
273273
.command("foo", "foo")
274274
.interceptor(() => {})
275275
.on("foo", () => {
@@ -282,7 +282,7 @@ describe("cli", () => {
282282

283283
it("should next", () => {
284284
let count = 0;
285-
TestCli()
285+
TestBaseCli()
286286
.command("foo", "foo")
287287
.interceptor((_ctx, next) => {
288288
next();
@@ -305,12 +305,12 @@ describe("cli", () => {
305305
it("should have exact one command", () => {
306306
expect(() => {
307307
// @ts-expect-error testing
308-
TestCli().command("foo", "foo").command("foo", "foo");
308+
TestBaseCli().command("foo", "foo").command("foo", "foo");
309309
}).toThrow();
310310
});
311311

312312
it("should parse nested command", () => {
313-
TestCli()
313+
TestBaseCli()
314314
.command("foo bar", "foo bar", {
315315
flags: {
316316
aa: {
@@ -329,7 +329,7 @@ describe("cli", () => {
329329
});
330330

331331
it("shouldn't parse nested command when parent command is called", () => {
332-
TestCli()
332+
TestBaseCli()
333333
.command("foo bar", "foo bar", {
334334
flags: {
335335
aa: {
@@ -357,7 +357,7 @@ describe("cli", () => {
357357
});
358358

359359
it("shouldn't parse when command is after command", () => {
360-
TestCli()
360+
TestBaseCli()
361361
.command("foo bar", "foo bar", {
362362
flags: {
363363
aa: {
@@ -385,7 +385,7 @@ describe("cli", () => {
385385
});
386386

387387
it("should parse subcommand", () => {
388-
TestCli()
388+
TestBaseCli()
389389
.command("foo bar", "foo")
390390
.on("foo bar", (ctx) => {
391391
expect(ctx.command.name).toBe("foo bar");
@@ -423,7 +423,7 @@ describe("cli", () => {
423423

424424
it("should run matched command", () => {
425425
let count = 0;
426-
TestCli()
426+
TestBaseCli()
427427
.command("foo", "foo")
428428
.on("foo", () => {
429429
count++;
@@ -435,7 +435,7 @@ describe("cli", () => {
435435
});
436436

437437
it("should resolve parameter with alias correctly", () => {
438-
TestCli()
438+
TestBaseCli()
439439
.command("foo", "foo", {
440440
alias: "bar baz",
441441
parameters: ["<param>"],
@@ -448,7 +448,7 @@ describe("cli", () => {
448448

449449
it("shouldn't run matched command", () => {
450450
let count = 0;
451-
TestCli()
451+
TestBaseCli()
452452
.command("foo", "foo")
453453
.on("foo", () => {
454454
count++;
@@ -459,7 +459,7 @@ describe("cli", () => {
459459
});
460460

461461
it("should parse global flag", () => {
462-
TestCli()
462+
TestBaseCli()
463463
.globalFlag("foo", "foo", {
464464
type: String,
465465
default: "bar",
@@ -472,7 +472,7 @@ describe("cli", () => {
472472
});
473473

474474
it("should parse global flag with default value", () => {
475-
TestCli()
475+
TestBaseCli()
476476
.globalFlag("foo", "foo", {
477477
type: String,
478478
default: "bar",
@@ -485,7 +485,7 @@ describe("cli", () => {
485485
});
486486

487487
it("should override global flag", () => {
488-
TestCli()
488+
TestBaseCli()
489489
.globalFlag("foo", "foo", {
490490
type: String,
491491
default: "bar",
@@ -506,7 +506,7 @@ describe("cli", () => {
506506
});
507507

508508
it("should parse parameter with space", () => {
509-
TestCli()
509+
TestBaseCli()
510510
.command("foo", "foo", {
511511
parameters: ["<foo bar>"],
512512
})

packages/plugin-friendly-error/test/plugin-friendly-error.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { TestCli } from "@clerc/test-utils";
1+
import { TestBaseCli } from "@clerc/test-utils";
22
import { beforeAll, describe, expect, it, vi } from "vitest";
33

44
import { friendlyErrorPlugin } from "../src";
@@ -9,7 +9,7 @@ describe("plugin-friendly-error", () => {
99
});
1010

1111
it("should catch error", async () => {
12-
TestCli()
12+
TestBaseCli()
1313
.use(
1414
friendlyErrorPlugin({
1515
target: (s) => {
@@ -21,7 +21,7 @@ describe("plugin-friendly-error", () => {
2121
});
2222

2323
it("should catch async error", () => {
24-
TestCli()
24+
TestBaseCli()
2525
.use(
2626
friendlyErrorPlugin({
2727
target: (s) => expect(s).toMatchInlineSnapshot(`"foo error"`),

packages/plugin-help/test/plugin-help.test.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { TestCli, getConsoleMock } from "@clerc/test-utils";
1+
import { TestBaseCli, getConsoleMock } from "@clerc/test-utils";
22
import { afterAll, afterEach, describe, expect, it } from "vitest";
33
import { mockConsole } from "vitest-console";
44

@@ -12,25 +12,25 @@ describe("plugin-help", () => {
1212
afterAll(restoreConsole);
1313

1414
it("should show help", () => {
15-
TestCli().use(helpPlugin()).parse(["help"]);
15+
TestBaseCli().use(helpPlugin()).parse(["help"]);
1616

1717
expect(getConsoleMock("log").mock.calls).toMatchSnapshot();
1818
});
1919

2020
it("should show --help", () => {
21-
TestCli().use(helpPlugin()).parse(["--help"]);
21+
TestBaseCli().use(helpPlugin()).parse(["--help"]);
2222

2323
expect(getConsoleMock("log").mock.calls).toMatchSnapshot();
2424
});
2525

2626
it("should show help when no command", () => {
27-
TestCli().use(helpPlugin()).parse([]);
27+
TestBaseCli().use(helpPlugin()).parse([]);
2828

2929
expect(getConsoleMock("log").mock.calls).toMatchSnapshot();
3030
});
3131

3232
it("should not show commands which set `show` to false", () => {
33-
TestCli()
33+
TestBaseCli()
3434
.use(helpPlugin())
3535
.command("test", "", {
3636
help: {
@@ -44,7 +44,7 @@ describe("plugin-help", () => {
4444

4545
describe("grouping", () => {
4646
it("should group commands", () => {
47-
TestCli()
47+
TestBaseCli()
4848
.use(
4949
helpPlugin({
5050
groups: {
@@ -71,7 +71,7 @@ describe("plugin-help", () => {
7171
});
7272

7373
it("should group global flags", () => {
74-
TestCli()
74+
TestBaseCli()
7575
.use(
7676
helpPlugin({
7777
groups: {
@@ -98,7 +98,7 @@ describe("plugin-help", () => {
9898
});
9999

100100
it("should group command flags", () => {
101-
TestCli()
101+
TestBaseCli()
102102
.use(
103103
helpPlugin({
104104
groups: {
@@ -131,7 +131,7 @@ describe("plugin-help", () => {
131131

132132
it("should throw error for undefined group", async () => {
133133
await expect(async () => {
134-
await TestCli()
134+
await TestBaseCli()
135135
.use(
136136
helpPlugin({
137137
groups: {
@@ -149,7 +149,7 @@ describe("plugin-help", () => {
149149
});
150150

151151
it("should not add group headers when no groups defined", () => {
152-
TestCli()
152+
TestBaseCli()
153153
.use(helpPlugin())
154154
.command("init", "Initialize project")
155155
.command("build", "Build project")

packages/plugin-not-found/test/plugin-not-found.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { TestCli } from "@clerc/test-utils";
1+
import { TestBaseCli } from "@clerc/test-utils";
22
import { beforeAll, describe, expect, it, vi } from "vitest";
33

44
import { notFoundPlugin } from "../src";
@@ -10,15 +10,15 @@ describe("plugin-not-found", () => {
1010

1111
it("should show commands", async () => {
1212
await expect(async () => {
13-
await TestCli().use(notFoundPlugin()).parse([]);
13+
await TestBaseCli().use(notFoundPlugin()).parse([]);
1414
}).rejects.toThrowErrorMatchingInlineSnapshot(
1515
"[Error: No command specified.]",
1616
);
1717
});
1818

1919
it("should show closest command", async () => {
2020
await expect(async () => {
21-
await TestCli()
21+
await TestBaseCli()
2222
.use(notFoundPlugin())
2323
.command("foo", "foo command")
2424
.parse(["fo"]);

0 commit comments

Comments
 (0)