Skip to content

Commit 4521c6e

Browse files
committed
test: add tests for tun command in pilot plugin
1 parent 6a2018b commit 4521c6e

File tree

6 files changed

+49
-6
lines changed

6 files changed

+49
-6
lines changed

packages/cli/__tests__/main.spec.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { LesyTestBed } from "@lesy/testbed";
22
import { resolve } from "path";
3+
// tslint:disable-next-line: import-name
4+
import * as PluginData from "../src";
35

46
describe("CLI", () => {
57
let testBed;
@@ -8,8 +10,8 @@ describe("CLI", () => {
810
isTypescriptApp: true,
911
loadDefaultPlugins: false,
1012
root: resolve(__dirname, "../"),
11-
commands: [resolve(__dirname, "../src/commands/default.command.ts")],
1213
features: [(f: any) => (f.pkg = { version: "1.0.0" })],
14+
...PluginData,
1315
});
1416
});
1517
it("should print greeting message", async () => {

packages/plugins/lesy-plugin-help/__tests__/help.command.test.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { LesyTestBed } from "@lesy/testbed";
22
import { resolve } from "path";
3+
// tslint:disable-next-line: import-name
4+
import PluginData from "../src";
35

46
describe("@lesy/lesy-plugin-help", () => {
57
let testBed;
@@ -8,8 +10,9 @@ describe("@lesy/lesy-plugin-help", () => {
810
isTypescriptApp: true,
911
loadDefaultPlugins: false,
1012
root: resolve(__dirname, "../"),
13+
1114
commands: [
12-
resolve(__dirname, "../src/help.command.ts"),
15+
...PluginData.commands,
1316
{
1417
name: "hello",
1518
description: "this is hello desc",
@@ -58,7 +61,7 @@ describe("@lesy/lesy-plugin-help", () => {
5861
},
5962
},
6063
],
61-
middlewares: [resolve(__dirname, "../src/help.middleware.ts")],
64+
middlewares: [...PluginData.middlewares],
6265
features: [resolve(__dirname, "./fixtures/help.feature.ts")],
6366
config: {
6467
defaultCmd: "default",
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
hello
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import { LesyTestBed } from "@lesy/testbed";
2+
import { resolve } from "path";
3+
// tslint:disable-next-line: import-name
4+
import PluginData from "../src";
5+
6+
(PluginData["features"] as any).push(
7+
(f: any) => (f.pkg = { name: "test_key" }),
8+
);
9+
10+
describe("@lesy/lesy-plugin-pilot", () => {
11+
let testBed;
12+
beforeEach(() => {
13+
testBed = new LesyTestBed({
14+
isTypescriptApp: true,
15+
loadDefaultPlugins: false,
16+
root: resolve(__dirname, "../"),
17+
...PluginData,
18+
});
19+
});
20+
21+
it("should execute the run command", async () => {
22+
const response = await testBed.run([
23+
"run",
24+
"ls packages/plugins/lesy-plugin-pilot/__tests__/fixtures",
25+
]);
26+
expect(response).toContain(
27+
"running > ls packages/plugins/lesy-plugin-pilot/__tests__/fixtures",
28+
);
29+
expect(response).toContain("hello.txt");
30+
});
31+
32+
it("should throw error on executing the run command", async () => {
33+
const response = await testBed.run(["run", "echos abc"]);
34+
expect(response).toContain("Error > Command failed with ENOENT: echos abc");
35+
});
36+
});

packages/plugins/lesy-plugin-pilot/src/run.command.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import execa from "execa";
2-
31
export default {
42
name: "run",
53
description: "Run shell command",
@@ -12,6 +10,7 @@ export default {
1210
visibleInList: false,
1311

1412
async run({ args, utils }) {
13+
const execa = require("execa");
1514
const chalk = utils.color();
1615
console.log(`${chalk.green("running")} > ${chalk.gray(args.command)}`);
1716
const [main, ...others] = args.command.split(" ");

packages/plugins/lesy-plugin-validator/__tests__/validator.middleware.test.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { LesyTestBed } from "@lesy/testbed";
22
import { resolve } from "path";
3+
// tslint:disable-next-line: import-name
4+
import PluginData from "../src";
35

46
describe("@lesy/lesy-plugin-validator", () => {
57
let testBed;
@@ -32,7 +34,7 @@ describe("@lesy/lesy-plugin-validator", () => {
3234
},
3335
},
3436
],
35-
middlewares: [resolve(__dirname, "../src/validator.middleware.ts")],
37+
...PluginData,
3638
});
3739

3840
mockExit = jest

0 commit comments

Comments
 (0)