-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest.js
More file actions
131 lines (106 loc) · 2.74 KB
/
test.js
File metadata and controls
131 lines (106 loc) · 2.74 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
126
127
128
129
130
131
const cli = require('./logger').cli;
const helper = require('./helper');
const util = require('util');
const assert = require('assert').strict;
let testSuites = [];
let currentDescribeInstance = null;
let describeStack = [];
let currentVisitedFilename = '';
function describe (title, describeInstance) {
if (describeInstance === undefined) {
describeInstance = title;
title = '';
}
if (currentVisitedFilename === '') {
throw new Error('Test file cannot be called without using efik test tools');
}
let _describeInstance = {
fn : describeInstance,
file : currentVisitedFilename,
title : title,
before : [],
beforeEach : [],
after : [],
afterEach : [],
test : []
};
if (currentDescribeInstance !== null) {
currentDescribeInstance.test.push(_describeInstance);
describeStack.push(currentDescribeInstance);
}
else {
testSuites.push(_describeInstance);
}
currentDescribeInstance = _describeInstance;
describeInstance();
currentDescribeInstance = describeStack.pop();
}
function it (title, itInstance) {
if (itInstance === undefined) {
itInstance = title;
title = '';
}
let _testInstance = {
fn : itInstance,
title : title
};
currentDescribeInstance.test.push(_testInstance);
}
it.only = function itOnly () {
}
function before (beforeFn) {
currentDescribeInstance.before.push({ fn : beforeFn });
}
function after (afterFn) {
currentDescribeInstance.after.push({ fn : afterFn });
}
function beforeEach (beforeEachFn) {
currentDescribeInstance.beforeEach.push({ fn :beforeEachFn });
}
function afterEach (afterEachFn) {
currentDescribeInstance.afterEach.push({ fn :afterEachFn });
}
assert.eq = function (actual, expected) {
assert.strictEqual(JSON.stringify(actual, null, 2), JSON.stringify(expected , null, 2));
};
function _run (options) {
console.log(testSuites)
for (let i = 0; i < testSuites.length; i++ ) {
let _testSuite = testSuites[i];
cli(_testSuite.file);
// execute before
helper.queue(_testSuite.before, () => {
// it is a it('should')
if (_testSuite.test === undefined) {
}
helper.queue(_testSuite.after, () => {
});
});
}
}
function nextTest (test, beforeEach, afterEach) {
for (let i = 0; i < testSuites.test.length; i++ ) {
let _test = testSuites.test[i];
helper.queue(_testSuite.beforeEach, () => {
_testSuite.test();
helper.queue(_testSuite.afterEach, () => {});
});
}
}
function _beforeRequire (filename) {
currentDescribeInstance = null;
currentVisitedFilename = filename;
stack = [];
}
module.exports = {
before,
after,
beforeEach,
afterEach,
describe,
it,
assert,
// private
_run,
_beforeRequire
};