1export const description = `
2Tests for getStackTrace.
3`;
4
5import { TestGroup, getStackTrace } from '../../framework/index.js';
6
7import { UnitTest } from './unit_test.js';
8
9export const g = new TestGroup(UnitTest);
10
11g.test('stacks', t => {
12  const lines: number = t.params._expectedLines;
13
14  const ex = new Error();
15  ex.stack = t.params._stack;
16  t.expect(ex.stack === t.params._stack);
17  const stringified = getStackTrace(ex);
18  const parts = stringified.split('\n');
19
20  t.expect(parts.length === lines);
21  const fst = parts[0];
22  const lst = parts[parts.length - 1];
23  t.expect(fst.indexOf('/suites/') !== -1 || fst.indexOf('\\suites\\') !== -1);
24  t.expect(lst.indexOf('/suites/') !== -1 || lst.indexOf('\\suites\\') !== -1);
25}).params([
26  {
27    case: 'node_fail',
28    _expectedLines: 1,
29    _stack: `Error:
30   at CaseRecorder.fail (/Users/kainino/src/cts-experiment/src/framework/logger.ts:99:30)
31   at RunCaseSpecific.exports.g.test.t [as fn] (/Users/kainino/src/cts-experiment/src/suites/unittests/logger.spec.ts:80:7)
32   at RunCaseSpecific.run (/Users/kainino/src/cts-experiment/src/framework/test_group.ts:121:18)
33   at processTicksAndRejections (internal/process/task_queues.js:86:5)`,
34  },
35  {
36    // TODO: make sure this test case actually matches what happens on windows
37    case: 'node_fail_backslash',
38    _expectedLines: 1,
39    _stack: `Error:
40   at CaseRecorder.fail (C:\\Users\\kainino\\src\\cts-experiment\\src\\framework\\logger.ts:99:30)
41   at RunCaseSpecific.exports.g.test.t [as fn] (C:\\Users\\kainino\\src\\cts-experiment\\src\\suites\\unittests\\logger.spec.ts:80:7)
42   at RunCaseSpecific.run (C:\\Users\\kainino\\src\\cts-experiment\\src\\framework\\test_group.ts:121:18)
43   at processTicksAndRejections (internal\\process\\task_queues.js:86:5)`,
44  },
45  {
46    case: 'node_fail_processTicksAndRejections',
47    _expectedLines: 3,
48    _stack: `Error: expectation had no effect: suite1:foo:
49    at Object.generateMinimalQueryList (/Users/kainino/src/cts/src/framework/generate_minimal_query_list.ts:72:24)
50    at testGenerateMinimalQueryList (/Users/kainino/src/cts/src/suites/unittests/loading.spec.ts:289:25)
51    at processTicksAndRejections (internal/process/task_queues.js:93:5)
52    at RunCaseSpecific.fn (/Users/kainino/src/cts/src/suites/unittests/loading.spec.ts:300:3)
53    at RunCaseSpecific.run (/Users/kainino/src/cts/src/framework/test_group.ts:144:9)
54    at /Users/kainino/src/cts/src/runtime/cmdline.ts:62:25
55    at async Promise.all (index 29)
56    at /Users/kainino/src/cts/src/runtime/cmdline.ts:78:5`,
57  },
58  {
59    case: 'node_throw',
60    _expectedLines: 1,
61    _stack: `Error: hello
62    at RunCaseSpecific.g.test.t [as fn] (/Users/kainino/src/cts-experiment/src/suites/unittests/test_group.spec.ts:51:11)
63    at RunCaseSpecific.run (/Users/kainino/src/cts-experiment/src/framework/test_group.ts:121:18)
64    at processTicksAndRejections (internal/process/task_queues.js:86:5)`,
65  },
66  {
67    case: 'firefox_fail',
68    _expectedLines: 1,
69    _stack: `fail@http://localhost:8080/out/framework/logger.js:104:30
70expect@http://localhost:8080/out/framework/default_fixture.js:59:16
71@http://localhost:8080/out/suites/unittests/util.spec.js:35:5
72run@http://localhost:8080/out/framework/test_group.js:119:18`,
73  },
74  {
75    case: 'firefox_throw',
76    _expectedLines: 1,
77    _stack: `@http://localhost:8080/out/suites/unittests/test_group.spec.js:48:11
78run@http://localhost:8080/out/framework/test_group.js:119:18`,
79  },
80  {
81    case: 'safari_fail',
82    _expectedLines: 1,
83    _stack: `fail@http://localhost:8080/out/framework/logger.js:104:39
84expect@http://localhost:8080/out/framework/default_fixture.js:59:20
85http://localhost:8080/out/suites/unittests/util.spec.js:35:11
86http://localhost:8080/out/framework/test_group.js:119:20
87asyncFunctionResume@[native code]
88[native code]
89promiseReactionJob@[native code]`,
90  },
91  {
92    case: 'safari_throw',
93    _expectedLines: 1,
94    _stack: `http://localhost:8080/out/suites/unittests/test_group.spec.js:48:20
95http://localhost:8080/out/framework/test_group.js:119:20
96asyncFunctionResume@[native code]
97[native code]
98promiseReactionJob@[native code]`,
99  },
100  {
101    case: 'chrome_fail',
102    _expectedLines: 1,
103    _stack: `Error
104    at CaseRecorder.fail (http://localhost:8080/out/framework/logger.js:104:30)
105    at DefaultFixture.expect (http://localhost:8080/out/framework/default_fixture.js:59:16)
106    at RunCaseSpecific.fn (http://localhost:8080/out/suites/unittests/util.spec.js:35:5)
107    at RunCaseSpecific.run (http://localhost:8080/out/framework/test_group.js:119:18)
108    at async runCase (http://localhost:8080/out/runtime/standalone.js:37:17)
109    at async http://localhost:8080/out/runtime/standalone.js:102:7`,
110  },
111  {
112    case: 'chrome_throw',
113    _expectedLines: 5,
114    _stack: `Error: hello
115    at RunCaseSpecific.fn (http://localhost:8080/out/suites/unittests/test_group.spec.js:48:11)
116    at RunCaseSpecific.run (http://localhost:8080/out/framework/test_group.js:119:18)"
117    at async Promise.all (index 0)
118    at async TestGroupTest.run (http://localhost:8080/out/suites/unittests/test_group_test.js:6:5)
119    at async RunCaseSpecific.fn (http://localhost:8080/out/suites/unittests/test_group.spec.js:53:15)
120    at async RunCaseSpecific.run (http://localhost:8080/out/framework/test_group.js:119:7)
121    at async runCase (http://localhost:8080/out/runtime/standalone.js:37:17)
122    at async http://localhost:8080/out/runtime/standalone.js:102:7`,
123  },
124  {
125    case: 'multiple_lines',
126    _expectedLines: 7,
127    _stack: `Error: hello
128    at RunCaseSpecific.fn (http://localhost:8080/out/suites/unittests/test_group.spec.js:48:11)
129    at RunCaseSpecific.fn (http://localhost:8080/out/suites/unittests/test_group.spec.js:48:11)
130    at RunCaseSpecific.fn (http://localhost:8080/out/suites/unittests/test_group.spec.js:48:11)
131    at RunCaseSpecific.run (http://localhost:8080/out/framework/test_group.js:119:18)"
132    at async Promise.all (index 0)
133    at async TestGroupTest.run (http://localhost:8080/out/suites/unittests/test_group_test.js:6:5)
134    at async RunCaseSpecific.fn (http://localhost:8080/out/suites/unittests/test_group.spec.js:53:15)
135    at async RunCaseSpecific.run (http://localhost:8080/out/framework/test_group.js:119:7)
136    at async runCase (http://localhost:8080/out/runtime/standalone.js:37:17)
137    at async http://localhost:8080/out/runtime/standalone.js:102:7`,
138  },
139]);
140