-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtests.js
More file actions
84 lines (77 loc) · 2.23 KB
/
tests.js
File metadata and controls
84 lines (77 loc) · 2.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
const {expect} = require('chai');
const createNode = require('./lib.js');
const logs = []
const node = createNode({
log: (arg)=> logs.push(arg),
beforeNodeHook: (tree, node, build) =>{
Object.keys(build).forEach(n => {
node['_bak_' + n] = global[n];
global[n] = build[n];
})
},
afterNodeHook: (tree, node, build) => {
Object.keys(build).forEach(n => {
global[n] = node['_bak_' + n];
delete node['_bak_' + n];
})
},
beforeHook: (tree, node, build) =>{
node._log = console.log;
console.log = (...args) => tree.log({id: node.id, data: args});
},
afterHook: (tree, node, build) => {
console.log = node._log;
},
});
const {define, exec} = node;
global.define = define;
require('./jestlike.spec');
(async () => {
try{
console.log(require('util').inspect(exec, {showHidden: false, depth: 6, colors: true}))
const ret = await exec();
console.log(require('util').inspect(logs, {showHidden: false, depth: 6, colors: true}))
expect(ret).to.be.eql(false);
expect(logs).to.deep.eql([
[ '0', 'Test root' ],
[ '0.0', 'First level' ],
[ '0.0', 'ba' ],
[ '0.0.0', 'failing' ],
[ '0.0.0', 'ba -- no -- THROW' ],
[ '0.0.0', 'err ? ', 'shit' ],
[ '0.0.1', 'second' ],
[ '0.0.1', 'ba =============================' ],
[ '0.0.1', 'be' ],
[ '0.0.1', 'be 2' ],
[ '0.0.1.0', '!', 'should work' ],
[ '0.0.1.0', '= PASS' ],
[ '0.0.1', 'ae 2' ],
[ '0.0.1', 'ae' ],
[ '0.0.1', 'be' ],
[ '0.0.1', 'be 2' ],
[ '0.0.1.1', 'This will have some test', 'TODO' ],
[ '0.0.1', 'ae 2' ],
[ '0.0.1', 'ae' ],
[ '0.0.1', 'be' ],
[ '0.0.1', 'be 2' ],
[ '0.0.1.2', '!', 'should fail' ],
[ '0.0.1.2', '? ', 'Nothing works' ],
[ '0.0.1.2', '= FAIL' ],
[ '0.0.1', 'ae 2' ],
[ '0.0.1', 'ae' ],
[ '0.0.1', 'aa =============================' ],
[ '0.0', 'be' ],
[ '0.0.2', '!', 'should work' ],
[ '0.0.2', '= PASS' ],
[ '0.0', 'ae' ],
[ '0.0', 'be' ],
[ '0.0.3', '!', 'should fail' ],
[ '0.0.3', '= FAIL' ],
[ '0.0', 'ae' ],
[ '0.0', 'aa' ]
]);
} catch(err) {
console.error(err);
process.exit(1);
}
})()