-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtestFramework.js
105 lines (93 loc) · 1.98 KB
/
testFramework.js
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
// Generated by CoffeeScript 2.7.0
var Asserts, Test, assert, assertSeq, idle, isFunction, logError, logFail, logInfo, queue, running, testEnd,
hasProp = {}.hasOwnProperty;
({logInfo, logError, isFunction} = require('./common'));
logFail = (description) => {
return (e) => {
logError(`Test ${description} failed`);
if (e != null) {
logError(e);
}
return false;
};
};
queue = [];
running = 0;
testEnd = () => {
running -= 1;
if (running < 1 && queue.length > 0) {
running += 1;
return queue.shift()();
}
};
Test = (description) => {
var fail, flag, key, ref, report, value;
fail = logFail(description);
flag = true;
report = {idle};
ref = Asserts();
for (key in ref) {
if (!hasProp.call(ref, key)) continue;
value = ref[key];
report[key] = ((value) => {
return (...args) => {
return value(...args).catch(fail).then((res) => {
return flag = flag && !!res;
});
};
})(value);
}
return (testFn) => {
running += 1;
return Promise.resolve().then(() => {
return testFn(report);
}).then(() => {
if (flag) {
return logInfo(`Test ${description} passed`);
} else {
return fail();
}
}).catch(fail).then(testEnd);
};
};
assert = async(flag, message = 'assert failed') => {
flag = (await flag);
if (!flag) {
throw new Error(message);
}
return true;
};
assertSeq = () => {
var count;
count = -2e308;
return async(c, message = 'wrong sequence') => {
c = (await c);
if (count > c) {
throw new Error(message);
} else {
if (isFinite(c) || c === 2e308) {
count = +c;
}
return true;
}
};
};
idle = (r, p) => {
if (running < 2) {
return;
}
p = new Promise((resolve) => {
return r = resolve;
});
running -= 1;
queue.push(r);
return p;
};
Asserts = () => {
return {
assert,
assertSeq: assertSeq()
};
};
module.exports = Test;
//# sourceMappingURL=testFramework.js.map