Skip to content

Commit cbee658

Browse files
committed
Add basic tests using jest
1 parent 7643090 commit cbee658

File tree

4 files changed

+2892
-41
lines changed

4 files changed

+2892
-41
lines changed

package.json

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@
77
"fengaric": "./src/luac-cli.js"
88
},
99
"directories": {
10-
"lib": "src"
10+
"lib": "src",
11+
"test": "test"
1112
},
1213
"scripts": {
13-
"lint": "eslint src/"
14+
"lint": "eslint src/ test/",
15+
"test": "jest"
1416
},
1517
"repository": {
1618
"type": "git",
@@ -37,7 +39,8 @@
3739
"sprintf-js": "^1.1.1"
3840
},
3941
"devDependencies": {
40-
"eslint": "^4.17.0"
42+
"eslint": "^4.17.0",
43+
"jest": "^22.4.3"
4144
},
4245
"eslintConfig": {
4346
"env": {
@@ -62,6 +65,19 @@
6265
"error",
6366
"always"
6467
]
65-
}
68+
},
69+
"overrides": [
70+
{
71+
"files": [
72+
"test/*.js"
73+
],
74+
"env": {
75+
"jest": true
76+
},
77+
"parserOptions": {
78+
"sourceType": "module"
79+
}
80+
}
81+
]
6682
}
6783
}

test/lua-cli.test.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
const fengari = require("fengari");
2+
const child_process = require("child_process");
3+
4+
const lua_path = require.resolve("../src/lua-cli.js");
5+
6+
test('Has correct -v output', () => new Promise((resolve) => {
7+
const child = child_process.fork(lua_path, ["-E", "-v"], {
8+
silent: true
9+
});
10+
let output = '';
11+
child.stdout.on('data', (data) => {
12+
output += data;
13+
});
14+
child.on('close', (code) => {
15+
expect(code).toBe(0);
16+
expect(output).toBe(fengari.FENGARI_COPYRIGHT + "\n");
17+
resolve();
18+
});
19+
}));

test/luac-cli.test.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
const fengari = require("fengari");
2+
const child_process = require("child_process");
3+
4+
const luac_path = require.resolve("../src/luac-cli.js");
5+
6+
test('Has correct -v output', () => new Promise((resolve) => {
7+
const child = child_process.fork(luac_path, ["-v"], {
8+
silent: true
9+
});
10+
let output = '';
11+
child.stdout.on('data', (data) => {
12+
output += data;
13+
});
14+
child.on('close', (code) => {
15+
expect(code).toBe(0);
16+
expect(output).toBe(fengari.FENGARI_COPYRIGHT + "\n");
17+
resolve();
18+
});
19+
}));

0 commit comments

Comments
 (0)