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
132
133
134
135
136
137
138
|
export const description = `
Tests for getStackTrace.
`;
import { makeTestGroup } from '../common/framework/test_group.js';
import { extractImportantStackTrace } from '../common/internal/stack.js';
import { UnitTest } from './unit_test.js';
export const g = makeTestGroup(UnitTest);
g.test('stacks')
.paramsSimple([
{
case: 'node_fail',
_expectedLines: 3,
_stack: `Error:
at CaseRecorder.fail (/Users/kainino/src/cts/src/common/framework/logger.ts:99:30)
at RunCaseSpecific.exports.g.test.t [as fn] (/Users/kainino/src/cts/src/unittests/logger.spec.ts:80:7)
at RunCaseSpecific.run (/Users/kainino/src/cts/src/common/framework/test_group.ts:121:18)
at processTicksAndRejections (internal/process/task_queues.js:86:5)`,
},
{
// MAINTENANCE_TODO: make sure this test case actually matches what happens on windows
case: 'node_fail_backslash',
_expectedLines: 3,
_stack: `Error:
at CaseRecorder.fail (C:\\Users\\kainino\\src\\cts\\src\\common\\framework\\logger.ts:99:30)
at RunCaseSpecific.exports.g.test.t [as fn] (C:\\Users\\kainino\\src\\cts\\src\\unittests\\logger.spec.ts:80:7)
at RunCaseSpecific.run (C:\\Users\\kainino\\src\\cts\\src\\common\\framework\\test_group.ts:121:18)
at processTicksAndRejections (internal\\process\\task_queues.js:86:5)`,
},
{
case: 'node_fail_processTicksAndRejections',
_expectedLines: 5,
_stack: `Error: expectation had no effect: suite1:foo:
at Object.generateMinimalQueryList (/Users/kainino/src/cts/src/common/framework/generate_minimal_query_list.ts:72:24)
at testGenerateMinimalQueryList (/Users/kainino/src/cts/src/unittests/loading.spec.ts:289:25)
at processTicksAndRejections (internal/process/task_queues.js:93:5)
at RunCaseSpecific.fn (/Users/kainino/src/cts/src/unittests/loading.spec.ts:300:3)
at RunCaseSpecific.run (/Users/kainino/src/cts/src/common/framework/test_group.ts:144:9)
at /Users/kainino/src/cts/src/common/runtime/cmdline.ts:62:25
at async Promise.all (index 29)
at /Users/kainino/src/cts/src/common/runtime/cmdline.ts:78:5`,
},
{
case: 'node_throw',
_expectedLines: 2,
_stack: `Error: hello
at RunCaseSpecific.g.test.t [as fn] (/Users/kainino/src/cts/src/unittests/test_group.spec.ts:51:11)
at RunCaseSpecific.run (/Users/kainino/src/cts/src/common/framework/test_group.ts:121:18)
at processTicksAndRejections (internal/process/task_queues.js:86:5)`,
},
{
case: 'firefox_fail',
_expectedLines: 3,
_stack: `fail@http://localhost:8080/out/common/framework/logger.js:104:30
expect@http://localhost:8080/out/common/framework/default_fixture.js:59:16
@http://localhost:8080/out/unittests/util.spec.js:35:5
run@http://localhost:8080/out/common/framework/test_group.js:119:18`,
},
{
case: 'firefox_throw',
_expectedLines: 1,
_stack: `@http://localhost:8080/out/unittests/test_group.spec.js:48:11
run@http://localhost:8080/out/common/framework/test_group.js:119:18`,
},
{
case: 'safari_fail',
_expectedLines: 3,
_stack: `fail@http://localhost:8080/out/common/framework/logger.js:104:39
expect@http://localhost:8080/out/common/framework/default_fixture.js:59:20
http://localhost:8080/out/unittests/util.spec.js:35:11
http://localhost:8080/out/common/framework/test_group.js:119:20
asyncFunctionResume@[native code]
[native code]
promiseReactionJob@[native code]`,
},
{
case: 'safari_throw',
_expectedLines: 1,
_stack: `http://localhost:8080/out/unittests/test_group.spec.js:48:20
http://localhost:8080/out/common/framework/test_group.js:119:20
asyncFunctionResume@[native code]
[native code]
promiseReactionJob@[native code]`,
},
{
case: 'chrome_fail',
_expectedLines: 4,
_stack: `Error
at CaseRecorder.fail (http://localhost:8080/out/common/framework/logger.js:104:30)
at DefaultFixture.expect (http://localhost:8080/out/common/framework/default_fixture.js:59:16)
at RunCaseSpecific.fn (http://localhost:8080/out/unittests/util.spec.js:35:5)
at RunCaseSpecific.run (http://localhost:8080/out/common/framework/test_group.js:119:18)
at async runCase (http://localhost:8080/out/common/runtime/standalone.js:37:17)
at async http://localhost:8080/out/common/runtime/standalone.js:102:7`,
},
{
case: 'chrome_throw',
_expectedLines: 6,
_stack: `Error: hello
at RunCaseSpecific.fn (http://localhost:8080/out/unittests/test_group.spec.js:48:11)
at RunCaseSpecific.run (http://localhost:8080/out/common/framework/test_group.js:119:18)"
at async Promise.all (index 0)
at async TestGroupTest.run (http://localhost:8080/out/unittests/test_group_test.js:6:5)
at async RunCaseSpecific.fn (http://localhost:8080/out/unittests/test_group.spec.js:53:15)
at async RunCaseSpecific.run (http://localhost:8080/out/common/framework/test_group.js:119:7)
at async runCase (http://localhost:8080/out/common/runtime/standalone.js:37:17)
at async http://localhost:8080/out/common/runtime/standalone.js:102:7`,
},
{
case: 'multiple_lines',
_expectedLines: 8,
_stack: `Error: hello
at RunCaseSpecific.fn (http://localhost:8080/out/unittests/test_group.spec.js:48:11)
at RunCaseSpecific.fn (http://localhost:8080/out/unittests/test_group.spec.js:48:11)
at RunCaseSpecific.fn (http://localhost:8080/out/unittests/test_group.spec.js:48:11)
at RunCaseSpecific.run (http://localhost:8080/out/common/framework/test_group.js:119:18)"
at async Promise.all (index 0)
at async TestGroupTest.run (http://localhost:8080/out/unittests/test_group_test.js:6:5)
at async RunCaseSpecific.fn (http://localhost:8080/out/unittests/test_group.spec.js:53:15)
at async RunCaseSpecific.run (http://localhost:8080/out/common/framework/test_group.js:119:7)
at async runCase (http://localhost:8080/out/common/runtime/standalone.js:37:17)
at async http://localhost:8080/out/common/runtime/standalone.js:102:7`,
},
])
.fn(t => {
const ex = new Error();
ex.stack = t.params._stack;
t.expect(ex.stack === t.params._stack);
const stringified = extractImportantStackTrace(ex);
const parts = stringified.split('\n');
t.expect(parts.length === t.params._expectedLines);
const last = parts[parts.length - 1];
t.expect(last.indexOf('/unittests/') !== -1 || last.indexOf('\\unittests\\') !== -1);
});
|