Skip to content

Commit cf494c8

Browse files
committed
test(shell): convertion from coffee to js
1 parent 2f16f93 commit cf494c8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+3336
-2252
lines changed

packages/shell/package.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
},
3131
"devDependencies": {
3232
"@eslint/js": "^9.15.0",
33-
"coffeescript": "^2.7.0",
3433
"dedent": "^1.5.3",
3534
"eslint": "^9.15.0",
3635
"eslint-config-prettier": "^9.1.0",
@@ -71,7 +70,6 @@
7170
"should"
7271
],
7372
"inline-diffs": true,
74-
"loader": "./test/loaders/coffee.js",
7573
"timeout": 10000,
7674
"reporter": "spec",
7775
"recursive": true
@@ -91,7 +89,7 @@
9189
"lint:staged": "npx lint-staged",
9290
"preversion": "yarn run test",
9391
"pretest": "npm run build",
94-
"test": "mocha 'test/**/*.coffee' 'test/**/*.js'"
92+
"test": "mocha 'test/**/*.js'"
9593
},
9694
"type": "module",
9795
"gitHead": "437629d1d64e73173408e67832c0c735b1225fdc"

packages/shell/test/api.load.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@ describe("api.load", function () {
88
const cwd = process.cwd();
99
process.chdir(os.tmpdir());
1010
await fs.writeFile(
11-
`${os.tmpdir()}/relative_module.coffee`,
11+
`${os.tmpdir()}/relative_module.js`,
1212
dedent`
13-
export default (params) -> params
13+
export default (params) => params
1414
`,
1515
);
16-
const mod = await shell().load(`${os.tmpdir()}/relative_module.coffee`);
16+
const mod = await shell().load(`${os.tmpdir()}/relative_module.js`);
1717
mod("my value").should.eql("my value");
1818
process.chdir(cwd);
19-
await fs.unlink(`${os.tmpdir()}/relative_module.coffee`);
19+
await fs.unlink(`${os.tmpdir()}/relative_module.js`);
2020
});
2121

2222
it("load is not a string", async function () {

packages/shell/test/args/api.compile.coffee

Lines changed: 0 additions & 42 deletions
This file was deleted.
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
import { shell } from "../../lib/index.js";
2+
3+
describe("api.compile", function () {
4+
it("validate", function () {
5+
(function () {
6+
shell().compile({}, "invalid");
7+
}).should.throw(
8+
'Invalid Compile Arguments: 2nd argument option must be an object, got "invalid"',
9+
);
10+
});
11+
12+
it("command string is converted to a 1 element array internally", function () {
13+
shell({
14+
commands: {
15+
start: {},
16+
},
17+
})
18+
.compile({
19+
command: "start",
20+
})
21+
.should.eql(["start"]);
22+
});
23+
24+
it("catch main argument with type of string", function () {
25+
(function () {
26+
shell({
27+
main: "leftover",
28+
}).compile({
29+
leftover: "my value",
30+
});
31+
}).should.throw(
32+
'Invalid Parameter Type: expect main to be an array, got "my value"',
33+
);
34+
});
35+
36+
it("check a command is registered", function () {
37+
(function () {
38+
shell({
39+
commands: {
40+
start: {},
41+
stop: {},
42+
},
43+
}).compile({
44+
command: ["status"],
45+
});
46+
}).should.throw(
47+
'Invalid Command Parameter: command "status" is not registed, expect one of ["help","start","stop"]',
48+
);
49+
50+
(function () {
51+
shell({
52+
commands: {
53+
server: {
54+
commands: {
55+
start: {},
56+
stop: {},
57+
},
58+
},
59+
},
60+
}).compile({
61+
command: ["server", "status"],
62+
});
63+
}).should.throw(
64+
'Invalid Command Parameter: command "status" is not registed, expect one of ["start","stop"] in command "server"',
65+
);
66+
});
67+
});

packages/shell/test/args/api.compile.script.coffee

Lines changed: 0 additions & 15 deletions
This file was deleted.
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import { shell } from "../../lib/index.js";
2+
3+
describe("api.compile.script", function () {
4+
it("should prefix with node path and executed script", function () {
5+
shell({
6+
commands: {
7+
start: {
8+
options: {
9+
myparam: {},
10+
},
11+
},
12+
},
13+
})
14+
.compile(
15+
{
16+
command: "start",
17+
myparam: "my value",
18+
},
19+
{
20+
script: "./bin/myscript",
21+
},
22+
)
23+
.should.eql([
24+
process.execPath,
25+
"./bin/myscript",
26+
"start",
27+
"--myparam",
28+
"my value",
29+
]);
30+
});
31+
});

packages/shell/test/args/api.parse.coffee

Lines changed: 0 additions & 55 deletions
This file was deleted.

packages/shell/test/args/api.parse.extended.coffee

Lines changed: 0 additions & 17 deletions
This file was deleted.
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { shell } from "../../lib/index.js";
2+
3+
describe("api.parse.extended", function () {
4+
it("overwrite flatten mode", function () {
5+
shell({
6+
options: {
7+
my_option: {},
8+
},
9+
})
10+
.parse(["--my_option", "my value"], { extended: true })
11+
.should.eql([{ my_option: "my value" }]);
12+
});
13+
14+
it("overwrite extended mode", function () {
15+
shell({
16+
options: {
17+
my_option: {},
18+
},
19+
extended: true,
20+
})
21+
.parse(["--my_option", "my value"], { extended: false })
22+
.should.eql({ my_option: "my value" });
23+
});
24+
});
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
import { shell } from "../../lib/index.js";
2+
3+
describe("api.parse", function () {
4+
it("does not alter input arguments", function () {
5+
const app = shell({
6+
commands: {
7+
start: {
8+
options: {
9+
my_option: {
10+
shortcut: "w",
11+
},
12+
},
13+
},
14+
},
15+
});
16+
const argv = ["start", "--my_option", "my value"];
17+
app.parse(argv);
18+
argv.should.eql(["start", "--my_option", "my value"]);
19+
});
20+
21+
it("catch argument without a value because end of argv", function () {
22+
const app = shell({
23+
commands: {
24+
start: {
25+
options: {
26+
an_int: {
27+
type: "integer",
28+
},
29+
a_string: {
30+
type: "string",
31+
},
32+
an_array: {
33+
type: "array",
34+
},
35+
},
36+
},
37+
},
38+
});
39+
(function () {
40+
app.parse(["start", "--an_int"]);
41+
}).should.throw('Invalid Option: no value found for option "an_int"');
42+
(function () {
43+
app.parse(["start", "--a_string"]);
44+
}).should.throw('Invalid Option: no value found for option "a_string"');
45+
(function () {
46+
app.parse(["start", "--an_array"]);
47+
}).should.throw('Invalid Option: no value found for option "an_array"');
48+
});
49+
50+
it("catch argument without a value because next argv is a shortcut", function () {
51+
const app = shell({
52+
commands: {
53+
start: {
54+
options: {
55+
an_int: {
56+
type: "integer",
57+
},
58+
a_string: {
59+
type: "string",
60+
},
61+
an_array: {
62+
type: "array",
63+
},
64+
some: {
65+
type: "string",
66+
},
67+
},
68+
},
69+
},
70+
});
71+
(function () {
72+
app.parse(["start", "--an_int", "--some", "thing"]);
73+
}).should.throw('Invalid Option: no value found for option "an_int"');
74+
(function () {
75+
app.parse(["start", "--a_string", "--some", "thing"]);
76+
}).should.throw('Invalid Option: no value found for option "a_string"');
77+
(function () {
78+
app.parse(["start", "--an_array", "--some", "thing"]);
79+
}).should.throw('Invalid Option: no value found for option "an_array"');
80+
});
81+
});

0 commit comments

Comments
 (0)