-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtests2.js
More file actions
125 lines (118 loc) · 3.13 KB
/
Copy pathtests2.js
File metadata and controls
125 lines (118 loc) · 3.13 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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
const {expect} = require('chai');
const consoleLog = console.log;
const init = require('./lib.js');
const createLogs = () => {
const logs = [];
return {
logs,
hooks: {
log: (arg)=> logs.push(arg),
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 t1 = async ()=>{
const {logs, hooks} = createLogs();
const {it, exec} = init(hooks);
it('should work');
try {
await exec();
expect(console.log).to.eql(consoleLog);
}catch(err){
console.error(err);
}
}
const t2 = async ()=>{
const {logs, hooks} = createLogs();
const {it, exec} = init(hooks);
it('should work');
try {
await exec();
expect(logs).to.deep.eql([
{ id: '0', name: 'Test root', type: 'GROUP', flag: 'START' },
{ id: '0.0', name: 'should work', type: 'TEST', flag: 'TODO' },
{ id: '0', name: 'Test root', type: 'GROUP', flag: 'END' }
]);
}catch(err){
console.error(err);
}
}
const t3 = async ()=>{
const {logs, hooks} = createLogs();
const {it, exec} = init(hooks);
it.todo('should work', () => {});
try {
await exec();
expect(logs).to.deep.eql([
{ id: '0', name: 'Test root', type: 'GROUP', flag: 'START' },
{ id: '0.0', name: 'should work', type: 'TEST', flag: 'TODO' },
{ id: '0', name: 'Test root', type: 'GROUP', flag: 'END' }
]);
}catch(err){
console.error(err);
}
}
const t4 = async ()=>{
const {logs, hooks} = createLogs();
const {it, exec} = init(hooks);
it.skip('should work', () => {});
try {
await exec();
expect(logs).to.deep.eql([
{ id: '0', name: 'Test root', type: 'GROUP', flag: 'START' },
{ id: '0.0', name: 'should work', type: 'TEST', flag: 'SKIP' },
{ id: '0', name: 'Test root', type: 'GROUP', flag: 'END' }
]);
}catch(err){
console.error(err);
}
}
const t5 = async ()=>{
const {logs, hooks} = createLogs();
const {it, exec} = init(hooks);
it('should work', () => Promise.reject());
try {
await exec();
expect(logs).to.deep.eql([
{ id: '0', name: 'Test root', type: 'GROUP', flag: 'START' },
{ id: '0.0', name: 'should work', flag: 'RUN' },
{ id: '0.0', flag: 'FAIL' },
{ id: '0', name: 'Test root', type: 'GROUP', flag: 'END' }
]);
}catch(err){
console.error(err);
}
}
const t6 = async ()=>{
const {logs, hooks} = createLogs();
const {define, exec} = init(hooks);
define('test', ({it}) => {
it('should work');
})
try {
await exec();
expect(logs).to.deep.eql([
{ id: '0', name: 'Test root', type: 'GROUP', flag: 'START' },
{ id: '0.0', name: 'test', type: 'GROUP', flag: 'START' },
{ id: '0.0.0', name: 'should work', type: 'TEST', flag: 'TODO' },
{ id: '0.0', name: 'test', type: 'GROUP', flag: 'END' },
{ id: '0', name: 'Test root', type: 'GROUP', flag: 'END' }
]);
}catch(err){
console.error(err);
}
}
(async ()=>{
await t1();
await t2();
await t3();
await t4();
await t5();
await t6();
})()