-
-
Notifications
You must be signed in to change notification settings - Fork 6.6k
Expand file tree
/
Copy pathutils.test.ts
More file actions
72 lines (54 loc) · 1.98 KB
/
utils.test.ts
File metadata and controls
72 lines (54 loc) · 1.98 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
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
import {runTest} from '../__mocks__/testUtils';
import {ROOT_DESCRIBE_BLOCK_NAME} from '../state';
import {makeDescribe, makeSingleTestResult, makeTest} from '../utils';
const makeFailedTestResult = (error: Error) => {
const rootDescribe = makeDescribe(ROOT_DESCRIBE_BLOCK_NAME);
const test = makeTest(
() => {},
undefined,
false,
'fails with cause',
rootDescribe,
undefined,
new Error('async error'),
false,
);
test.errors.push(error);
test.status = 'done';
return makeSingleTestResult(test);
};
test('makeTestResults does not thrown a stack overflow exception', () => {
let testString = 'describe("top level describe", () => {';
const numberOfTestBlocks = 150_000;
let currentTestIndex = 0;
while (currentTestIndex < numberOfTestBlocks) {
testString += `test("should do something #${currentTestIndex++}", () => {});`;
}
testString += '})';
const {stdout} = runTest(testString);
expect(stdout.split('\n')).toHaveLength(900_010);
});
test('makeSingleTestResult serializes nested Error.cause', () => {
const error = new Error('error during f', {
cause: new Error('error during g'),
});
const result = makeFailedTestResult(error);
expect(result.errors[0]).toContain('[cause]: Error: error during g');
});
test('makeSingleTestResult serializes string Error.cause', () => {
const error = new Error('error during f', {cause: 'here is the cause'});
const result = makeFailedTestResult(error);
expect(result.errors[0]).toContain('[cause]: here is the cause');
});
test('makeSingleTestResult protects against circular Error.cause', () => {
const error = new Error('error during f') as Error & {cause?: unknown};
error.cause = error;
const result = makeFailedTestResult(error);
expect(result.errors[0]).toContain('[Circular cause]');
});