Skip to content

Commit e8387ab

Browse files
committed
add hello-test
1 parent 3de6ae0 commit e8387ab

File tree

4 files changed

+121
-0
lines changed

4 files changed

+121
-0
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
{
2+
"version": "0.2.0",
3+
"configurations": [
4+
{
5+
"name": "Run",
6+
"type": "node",
7+
"request": "launch",
8+
"program": "${workspaceRoot}/hello.js",
9+
"stopOnEntry": false,
10+
"args": [],
11+
"cwd": "${workspaceRoot}",
12+
"preLaunchTask": null,
13+
"runtimeExecutable": null,
14+
"runtimeArgs": [
15+
"--nolazy"
16+
],
17+
"env": {
18+
"NODE_ENV": "development"
19+
},
20+
"externalConsole": false,
21+
"sourceMaps": false,
22+
"outDir": null
23+
},
24+
{
25+
"name": "Test",
26+
"type": "node",
27+
"request": "launch",
28+
"program": "${workspaceRoot}/node_modules/mocha/bin/mocha",
29+
"stopOnEntry": false,
30+
"args": [],
31+
"cwd": "${workspaceRoot}",
32+
"preLaunchTask": null,
33+
"runtimeExecutable": null,
34+
"runtimeArgs": [
35+
"--nolazy"
36+
],
37+
"env": {
38+
"NODE_ENV": "test"
39+
},
40+
"externalConsole": false,
41+
"sourceMaps": false,
42+
"outDir": null
43+
}
44+
]
45+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// hello.js
2+
console.log('init hello.js...');
3+
4+
// a simple function:
5+
// > sum(1, 2, 3)
6+
// 6
7+
module.exports = function (...rest) {
8+
var sum = 0;
9+
for (let n of rest) {
10+
sum += n;
11+
}
12+
return sum;
13+
};
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"name": "mocha-test",
3+
"version": "1.0.0",
4+
"description": "Mocha simple test",
5+
"main": "hello.js",
6+
"scripts": {
7+
"test": "mocha"
8+
},
9+
"keywords": [
10+
"mocha",
11+
"test"
12+
],
13+
"author": "Michael Liao",
14+
"license": "Apache-2.0",
15+
"repository": {
16+
"type": "git",
17+
"url": "https://github.com/michaelliao/learn-javascript.git"
18+
},
19+
"dependencies": {},
20+
"devDependencies": {
21+
"mocha": "3.0.2"
22+
}
23+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
const assert = require('assert');
2+
3+
const sum = require('../hello');
4+
5+
describe('#hello.js', () => {
6+
7+
describe('#sum()', () => {
8+
before(function () {
9+
console.log('before:');
10+
});
11+
12+
after(function () {
13+
console.log('after.');
14+
});
15+
16+
beforeEach(function () {
17+
console.log(' beforeEach:');
18+
});
19+
20+
afterEach(function () {
21+
console.log(' afterEach.');
22+
});
23+
24+
it('sum() should return 0', () => {
25+
assert.strictEqual(sum(), 0);
26+
});
27+
28+
it('sum(1) should return 1', () => {
29+
assert.strictEqual(sum(1), 1);
30+
});
31+
32+
it('sum(1, 2) should return 3', () => {
33+
assert.strictEqual(sum(1, 2), 3);
34+
});
35+
36+
it('sum(1, 2, 3) should return 6', () => {
37+
assert.strictEqual(sum(1, 2, 3), 6);
38+
});
39+
});
40+
});

0 commit comments

Comments
 (0)