-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.js
71 lines (68 loc) · 2.07 KB
/
run.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
import {objectEquals} from './compare.js';
export async function runTestCases(testCases, setupFunc) {
const results = [];
// Using a for loop instead of map, so we can block the loop when calling a asynchronous gotFunc.
for (const tc of testCases) {
const result = {
name: tc.name,
want: tc.wantErrSubstring ? `want error substring: ${tc.wantErrSubstring}` : tc.want,
got: tc.got,
errString: null,
stackTrace: null,
};
const tcContext = {
args: tc.args,
setup: {}
};
if (setupFunc) {
try {
const setupResult = await setupFunc(tcContext);
tcContext.setup = {...tcContext.setup, ...setupResult};
} catch (err) {
result.isSuccessful = false;
result.got = `common setup error: ${err.toString()}`;
result.errString = err.toString();
result.stackTrace = err.stack;
results.push(result);
continue;
}
}
if (tc.setupFunc) {
try {
const setupResult = await tc.setupFunc(tcContext);
tcContext.setup = {...tcContext.setup, ...setupResult};
} catch (err) {
result.isSuccessful = false;
result.got = `setup error: ${err.toString()}`;
result.errString = err.toString();
result.stackTrace = err.stack;
results.push(result);
continue;
}
}
if (tc.gotFunc) {
try {
result.got = await tc.gotFunc(tcContext);
if (tc.wantErrSubstring) {
result.isSuccessful = false;
results.push(result);
continue;
}
} catch (err) {
result.got = `got error: ${err.toString()}`;
result.errString = err.toString();
result.isSuccessful = result.got.includes(tc.wantErrSubstring);
if (!result.isSuccessful) {
result.stackTrace = err.stack;
}
results.push(result);
continue;
}
}
const comparisonFunc = tc.comparisonFunc || objectEquals;
result.isSuccessful = comparisonFunc(result.got, result.want);
results.push(result);
continue;
}
return results
}