Skip to content

Commit fda7103

Browse files
authored
test(node-integration): Migrate to Vitest (#15499)
This PR: - Modifies all tests to: - Use Vitest imports - Use async rather than callback - Changes test runner and test server to be async - `runner.start(done)` becomes `await runner.start().completed()` - `createTestServer()` close function now throws any errors that occurred
1 parent f418e83 commit fda7103

File tree

175 files changed

+1730
-1323
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

175 files changed

+1730
-1323
lines changed

Diff for: dev-packages/node-integration-tests/jest.config.js

-9
This file was deleted.

Diff for: dev-packages/node-integration-tests/jest.setup.js

-8
This file was deleted.

Diff for: dev-packages/node-integration-tests/package.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@
2121
"fix": "eslint . --format stylish --fix",
2222
"type-check": "tsc",
2323
"pretest": "yarn express-v5-install",
24-
"test": "jest --config ./jest.config.js",
25-
"test:no-prisma": "jest --config ./jest.config.js",
24+
"test": "vitest run",
2625
"test:watch": "yarn test --watch"
2726
},
2827
"dependencies": {

Diff for: dev-packages/node-integration-tests/suites/anr/test.ts

+49-36
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { Event } from '@sentry/core';
2+
import { afterAll, describe, expect, test } from 'vitest';
23
import { cleanupChildProcesses, createRunner } from '../../utils/runner';
34

45
const ANR_EVENT = {
@@ -111,18 +112,23 @@ describe('should report ANR when event loop blocked', () => {
111112
cleanupChildProcesses();
112113
});
113114

114-
test('CJS', done => {
115-
createRunner(__dirname, 'basic.js').withMockSentryServer().expect({ event: ANR_EVENT_WITH_DEBUG_META }).start(done);
115+
test('CJS', async () => {
116+
await createRunner(__dirname, 'basic.js')
117+
.withMockSentryServer()
118+
.expect({ event: ANR_EVENT_WITH_DEBUG_META })
119+
.start()
120+
.completed();
116121
});
117122

118-
test('ESM', done => {
119-
createRunner(__dirname, 'basic.mjs')
123+
test('ESM', async () => {
124+
await createRunner(__dirname, 'basic.mjs')
120125
.withMockSentryServer()
121126
.expect({ event: ANR_EVENT_WITH_DEBUG_META })
122-
.start(done);
127+
.start()
128+
.completed();
123129
});
124130

125-
test('Custom appRootPath', done => {
131+
test('Custom appRootPath', async () => {
126132
const ANR_EVENT_WITH_SPECIFIC_DEBUG_META: Event = {
127133
...ANR_EVENT_WITH_SCOPE,
128134
debug_meta: {
@@ -136,52 +142,57 @@ describe('should report ANR when event loop blocked', () => {
136142
},
137143
};
138144

139-
createRunner(__dirname, 'app-path.mjs')
145+
await createRunner(__dirname, 'app-path.mjs')
140146
.withMockSentryServer()
141147
.expect({ event: ANR_EVENT_WITH_SPECIFIC_DEBUG_META })
142-
.start(done);
148+
.start()
149+
.completed();
143150
});
144151

145-
test('multiple events via maxAnrEvents', done => {
146-
createRunner(__dirname, 'basic-multiple.mjs')
152+
test('multiple events via maxAnrEvents', async () => {
153+
await createRunner(__dirname, 'basic-multiple.mjs')
147154
.withMockSentryServer()
148155
.expect({ event: ANR_EVENT_WITH_DEBUG_META })
149156
.expect({ event: ANR_EVENT_WITH_DEBUG_META })
150-
.start(done);
157+
.start()
158+
.completed();
151159
});
152160

153-
test('blocked indefinitely', done => {
154-
createRunner(__dirname, 'indefinite.mjs').withMockSentryServer().expect({ event: ANR_EVENT }).start(done);
161+
test('blocked indefinitely', async () => {
162+
await createRunner(__dirname, 'indefinite.mjs')
163+
.withMockSentryServer()
164+
.expect({ event: ANR_EVENT })
165+
.start()
166+
.completed();
155167
});
156168

157-
test("With --inspect the debugger isn't used", done => {
158-
createRunner(__dirname, 'basic.mjs')
169+
test("With --inspect the debugger isn't used", async () => {
170+
await createRunner(__dirname, 'basic.mjs')
159171
.withMockSentryServer()
160172
.withFlags('--inspect')
161173
.expect({ event: ANR_EVENT_WITHOUT_STACKTRACE })
162-
.start(done);
174+
.start()
175+
.completed();
163176
});
164177

165-
test('should exit', done => {
178+
test('should exit', async () => {
166179
const runner = createRunner(__dirname, 'should-exit.js').start();
167180

168-
setTimeout(() => {
169-
expect(runner.childHasExited()).toBe(true);
170-
done();
171-
}, 5_000);
181+
await new Promise(resolve => setTimeout(resolve, 5_000));
182+
183+
expect(runner.childHasExited()).toBe(true);
172184
});
173185

174-
test('should exit forced', done => {
186+
test('should exit forced', async () => {
175187
const runner = createRunner(__dirname, 'should-exit-forced.js').start();
176188

177-
setTimeout(() => {
178-
expect(runner.childHasExited()).toBe(true);
179-
done();
180-
}, 5_000);
189+
await new Promise(resolve => setTimeout(resolve, 5_000));
190+
191+
expect(runner.childHasExited()).toBe(true);
181192
});
182193

183-
test('With session', done => {
184-
createRunner(__dirname, 'basic-session.js')
194+
test('With session', async () => {
195+
await createRunner(__dirname, 'basic-session.js')
185196
.withMockSentryServer()
186197
.unignore('session')
187198
.expect({
@@ -194,15 +205,16 @@ describe('should report ANR when event loop blocked', () => {
194205
},
195206
})
196207
.expect({ event: ANR_EVENT_WITH_SCOPE })
197-
.start(done);
208+
.start()
209+
.completed();
198210
});
199211

200-
test('from forked process', done => {
201-
createRunner(__dirname, 'forker.js').expect({ event: ANR_EVENT_WITH_SCOPE }).start(done);
212+
test('from forked process', async () => {
213+
await createRunner(__dirname, 'forker.js').expect({ event: ANR_EVENT_WITH_SCOPE }).start().completed();
202214
});
203215

204-
test('worker can be stopped and restarted', done => {
205-
createRunner(__dirname, 'stop-and-start.js').expect({ event: ANR_EVENT_WITH_SCOPE }).start(done);
216+
test('worker can be stopped and restarted', async () => {
217+
await createRunner(__dirname, 'stop-and-start.js').expect({ event: ANR_EVENT_WITH_SCOPE }).start().completed();
206218
});
207219

208220
const EXPECTED_ISOLATED_EVENT = {
@@ -231,10 +243,11 @@ describe('should report ANR when event loop blocked', () => {
231243
},
232244
};
233245

234-
test('fetches correct isolated scope', done => {
235-
createRunner(__dirname, 'isolated.mjs')
246+
test('fetches correct isolated scope', async () => {
247+
await createRunner(__dirname, 'isolated.mjs')
236248
.withMockSentryServer()
237249
.expect({ event: EXPECTED_ISOLATED_EVENT })
238-
.start(done);
250+
.start()
251+
.completed();
239252
});
240253
});

Diff for: dev-packages/node-integration-tests/suites/aws-serverless/aws-integration/s3/test.ts

+9-4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { afterAll, describe, expect, test } from 'vitest';
12
import { cleanupChildProcesses, createRunner } from '../../../../utils/runner';
23

34
const EXPECTED_TRANSCATION = {
@@ -7,7 +8,7 @@ const EXPECTED_TRANSCATION = {
78
description: 'S3.PutObject',
89
op: 'rpc',
910
origin: 'auto.otel.aws',
10-
data: {
11+
data: expect.objectContaining({
1112
'sentry.origin': 'auto.otel.aws',
1213
'sentry.op': 'rpc',
1314
'rpc.system': 'aws-api',
@@ -16,7 +17,7 @@ const EXPECTED_TRANSCATION = {
1617
'aws.region': 'us-east-1',
1718
'aws.s3.bucket': 'ot-demo-test',
1819
'otel.kind': 'CLIENT',
19-
},
20+
}),
2021
}),
2122
]),
2223
};
@@ -26,7 +27,11 @@ describe('awsIntegration', () => {
2627
cleanupChildProcesses();
2728
});
2829

29-
test('should auto-instrument aws-sdk v2 package.', done => {
30-
createRunner(__dirname, 'scenario.js').ignore('event').expect({ transaction: EXPECTED_TRANSCATION }).start(done);
30+
test('should auto-instrument aws-sdk v2 package.', async () => {
31+
await createRunner(__dirname, 'scenario.js')
32+
.ignore('event')
33+
.expect({ transaction: EXPECTED_TRANSCATION })
34+
.start()
35+
.completed();
3136
});
3237
});

Diff for: dev-packages/node-integration-tests/suites/breadcrumbs/process-thread/test.ts

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { Event } from '@sentry/core';
2+
import { afterAll, expect, test } from 'vitest';
23
import { conditionalTest } from '../../../utils';
34
import { cleanupChildProcesses, createRunner } from '../../../utils/runner';
45

@@ -39,10 +40,11 @@ conditionalTest({ min: 20 })('should capture process and thread breadcrumbs', ()
3940
cleanupChildProcesses();
4041
});
4142

42-
test('ESM', done => {
43-
createRunner(__dirname, 'app.mjs')
43+
test('ESM', async () => {
44+
await createRunner(__dirname, 'app.mjs')
4445
.withMockSentryServer()
4546
.expect({ event: EVENT as Event })
46-
.start(done);
47+
.start()
48+
.completed();
4749
});
4850
});

Diff for: dev-packages/node-integration-tests/suites/child-process/test.ts

+9-8
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { Event } from '@sentry/core';
2+
import { afterAll, describe, expect, test } from 'vitest';
23
import { conditionalTest } from '../../utils';
34
import { cleanupChildProcesses, createRunner } from '../../utils/runner';
45

@@ -44,22 +45,22 @@ describe('should capture child process events', () => {
4445
});
4546

4647
conditionalTest({ min: 20 })('worker', () => {
47-
test('ESM', done => {
48-
createRunner(__dirname, 'worker.mjs').expect({ event: WORKER_EVENT }).start(done);
48+
test('ESM', async () => {
49+
await createRunner(__dirname, 'worker.mjs').expect({ event: WORKER_EVENT }).start().completed();
4950
});
5051

51-
test('CJS', done => {
52-
createRunner(__dirname, 'worker.js').expect({ event: WORKER_EVENT }).start(done);
52+
test('CJS', async () => {
53+
await createRunner(__dirname, 'worker.js').expect({ event: WORKER_EVENT }).start().completed();
5354
});
5455
});
5556

5657
conditionalTest({ min: 20 })('fork', () => {
57-
test('ESM', done => {
58-
createRunner(__dirname, 'fork.mjs').expect({ event: CHILD_EVENT }).start(done);
58+
test('ESM', async () => {
59+
await createRunner(__dirname, 'fork.mjs').expect({ event: CHILD_EVENT }).start().completed();
5960
});
6061

61-
test('CJS', done => {
62-
createRunner(__dirname, 'fork.js').expect({ event: CHILD_EVENT }).start(done);
62+
test('CJS', async () => {
63+
await createRunner(__dirname, 'fork.js').expect({ event: CHILD_EVENT }).start().completed();
6364
});
6465
});
6566
});

Diff for: dev-packages/node-integration-tests/suites/client-reports/drop-reasons/before-send/test.ts

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1+
import { afterAll, test } from 'vitest';
12
import { cleanupChildProcesses, createRunner } from '../../../../utils/runner';
23

34
afterAll(() => {
45
cleanupChildProcesses();
56
});
67

7-
test('should record client report for beforeSend', done => {
8-
createRunner(__dirname, 'scenario.ts')
8+
test('should record client report for beforeSend', async () => {
9+
await createRunner(__dirname, 'scenario.ts')
910
.unignore('client_report')
1011
.expect({
1112
client_report: {
@@ -29,5 +30,6 @@ test('should record client report for beforeSend', done => {
2930
],
3031
},
3132
})
32-
.start(done);
33+
.start()
34+
.completed();
3335
});

Diff for: dev-packages/node-integration-tests/suites/client-reports/drop-reasons/event-processors/test.ts

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1+
import { afterAll, test } from 'vitest';
12
import { cleanupChildProcesses, createRunner } from '../../../../utils/runner';
23

34
afterAll(() => {
45
cleanupChildProcesses();
56
});
67

7-
test('should record client report for event processors', done => {
8-
createRunner(__dirname, 'scenario.ts')
8+
test('should record client report for event processors', async () => {
9+
await createRunner(__dirname, 'scenario.ts')
910
.unignore('client_report')
1011
.expect({
1112
client_report: {
@@ -29,5 +30,6 @@ test('should record client report for event processors', done => {
2930
],
3031
},
3132
})
32-
.start(done);
33+
.start()
34+
.completed();
3335
});

Diff for: dev-packages/node-integration-tests/suites/client-reports/periodic-send/test.ts

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1+
import { afterAll, test } from 'vitest';
12
import { cleanupChildProcesses, createRunner } from '../../../utils/runner';
23

34
afterAll(() => {
45
cleanupChildProcesses();
56
});
67

7-
test('should flush client reports automatically after the timeout interval', done => {
8-
createRunner(__dirname, 'scenario.ts')
8+
test('should flush client reports automatically after the timeout interval', async () => {
9+
await createRunner(__dirname, 'scenario.ts')
910
.unignore('client_report')
1011
.expect({
1112
client_report: {
@@ -18,5 +19,6 @@ test('should flush client reports automatically after the timeout interval', don
1819
],
1920
},
2021
})
21-
.start(done);
22+
.start()
23+
.completed();
2224
});

Diff for: dev-packages/node-integration-tests/suites/contextLines/filename-with-spaces/test.ts

+9-6
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import { join } from 'path';
2+
import { describe, expect, test } from 'vitest';
23
import { createRunner } from '../../../utils/runner';
34

45
describe('ContextLines integration in ESM', () => {
5-
test('reads encoded context lines from filenames with spaces', done => {
6+
test('reads encoded context lines from filenames with spaces', async () => {
67
expect.assertions(1);
78
const instrumentPath = join(__dirname, 'instrument.mjs');
89

9-
createRunner(__dirname, 'scenario with space.mjs')
10+
await createRunner(__dirname, 'scenario with space.mjs')
1011
.withFlags('--import', instrumentPath)
1112
.expect({
1213
event: {
@@ -34,15 +35,16 @@ describe('ContextLines integration in ESM', () => {
3435
},
3536
},
3637
})
37-
.start(done);
38+
.start()
39+
.completed();
3840
});
3941
});
4042

4143
describe('ContextLines integration in CJS', () => {
42-
test('reads context lines from filenames with spaces', done => {
44+
test('reads context lines from filenames with spaces', async () => {
4345
expect.assertions(1);
4446

45-
createRunner(__dirname, 'scenario with space.cjs')
47+
await createRunner(__dirname, 'scenario with space.cjs')
4648
.expect({
4749
event: {
4850
exception: {
@@ -77,6 +79,7 @@ describe('ContextLines integration in CJS', () => {
7779
},
7880
},
7981
})
80-
.start(done);
82+
.start()
83+
.completed();
8184
});
8285
});

0 commit comments

Comments
 (0)