-
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathe2e.test.mjs
More file actions
121 lines (108 loc) · 3.37 KB
/
e2e.test.mjs
File metadata and controls
121 lines (108 loc) · 3.37 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
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
import { spawnSync } from 'node:child_process';
import { join } from 'node:path';
import { createStackParser, nodeStackLineParser } from '@sentry/core';
import { beforeAll, describe, expect, test } from 'vitest';
import { installTarballAsDependency } from './prepare.mjs';
const __dirname = import.meta.dirname || new URL('.', import.meta.url).pathname;
const defaultStackParser = createStackParser(nodeStackLineParser());
function parseStacks(stacks) {
return Object.fromEntries(
Object.entries(stacks).map(([id, stack]) => [id, defaultStackParser(stack)]),
);
}
describe('e2e Tests', { timeout: 20000 }, () => {
beforeAll(() => {
installTarballAsDependency(__dirname);
});
test('Capture stack trace from multiple threads', () => {
const testFile = join(__dirname, 'stack-traces.js');
const result = spawnSync('node', [testFile])
expect(result.status).toBe(0);
const stacks = parseStacks(JSON.parse(result.stdout.toString()));
expect(stacks['0']).toEqual(expect.arrayContaining([
{
function: 'pbkdf2Sync',
filename: expect.any(String),
lineno: expect.any(Number),
colno: expect.any(Number),
in_app: false,
module: undefined,
},
{
function: 'longWork',
filename: expect.stringMatching(/long-work.js$/),
lineno: expect.any(Number),
colno: expect.any(Number),
in_app: true,
module: undefined,
},
{
function: '?',
filename: expect.stringMatching(/stack-traces.js$/),
lineno: expect.any(Number),
colno: expect.any(Number),
in_app: true,
module: undefined,
},
]));
expect(stacks['2']).toEqual(expect.arrayContaining([
{
function: 'pbkdf2Sync',
filename: expect.any(String),
lineno: expect.any(Number),
colno: expect.any(Number),
in_app: false,
module: undefined,
},
{
function: 'longWork',
filename: expect.stringMatching(/long-work.js$/),
lineno: expect.any(Number),
colno: expect.any(Number),
in_app: true,
module: undefined,
},
{
function: '?',
filename: expect.stringMatching(/worker.js$/),
lineno: expect.any(Number),
colno: expect.any(Number),
in_app: true,
module: undefined,
},
]));
});
test('Detect stalled thread', { timeout: 20000 }, () => {
const testFile = join(__dirname, 'stalled.js');
const result = spawnSync('node', [testFile]);
expect(result.status).toBe(0);
const stacks = parseStacks(JSON.parse(result.stdout.toString()));
expect(stacks['0']).toEqual(expect.arrayContaining([
{
function: 'pbkdf2Sync',
filename: expect.any(String),
lineno: expect.any(Number),
colno: expect.any(Number),
in_app: false,
module: undefined,
},
{
function: 'longWork',
filename: expect.stringMatching(/long-work.js$/),
lineno: expect.any(Number),
colno: expect.any(Number),
in_app: true,
module: undefined,
},
{
function: '?',
filename: expect.stringMatching(/stalled.js$/),
lineno: expect.any(Number),
colno: expect.any(Number),
in_app: true,
module: undefined,
},
]));
expect(stacks['2'].length).toEqual(1);
});
});