Skip to content

Commit fb38aed

Browse files
committed
WIP
1 parent 88eee44 commit fb38aed

File tree

6 files changed

+39
-43
lines changed

6 files changed

+39
-43
lines changed

dev-packages/node-integration-tests/suites/express/with-http/test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { afterAll, describe, test } from 'vitest';
1+
import { afterAll, describe } from 'vitest';
22
import { cleanupChildProcesses, createEsmAndCjsTests } from '../../../utils/runner';
33

4-
describe('express with http import xxx', () => {
4+
describe('express with http import', () => {
55
afterAll(() => {
66
cleanupChildProcesses();
77
});
@@ -10,7 +10,7 @@ describe('express with http import xxx', () => {
1010
__dirname,
1111
'scenario.mjs',
1212
'instrument.mjs',
13-
createRunner => {
13+
(createRunner, test) => {
1414
test('it works when importing the http module', async () => {
1515
const runner = createRunner()
1616
.expect({

dev-packages/node-integration-tests/suites/tracing/amqplib/test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { TransactionEvent } from '@sentry/core';
2-
import { afterAll, describe, expect, test } from 'vitest';
2+
import { afterAll, describe, expect } from 'vitest';
33
import { cleanupChildProcesses, createEsmAndCjsTests } from '../../../utils/runner';
44

55
const EXPECTED_MESSAGE_SPAN_PRODUCER = expect.objectContaining({
@@ -29,7 +29,7 @@ describe('amqplib auto-instrumentation', () => {
2929
cleanupChildProcesses();
3030
});
3131

32-
createEsmAndCjsTests(__dirname, 'scenario.mjs', 'instrument.mjs', createTestRunner => {
32+
createEsmAndCjsTests(__dirname, 'scenario.mjs', 'instrument.mjs', (createTestRunner, test) => {
3333
test('should be able to send and receive messages', async () => {
3434
await createTestRunner()
3535
.withDockerCompose({

dev-packages/node-integration-tests/suites/tracing/connect/test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { afterAll, describe, expect, test } from 'vitest';
1+
import { afterAll, describe, expect } from 'vitest';
22
import { cleanupChildProcesses, createEsmAndCjsTests } from '../../../utils/runner';
33

44
describe('connect auto-instrumentation', () => {
@@ -40,7 +40,7 @@ describe('connect auto-instrumentation', () => {
4040
__dirname,
4141
'scenario.mjs',
4242
'instrument.mjs',
43-
createTestRunner => {
43+
(createTestRunner, test) => {
4444
test('should auto-instrument `connect` package.', async () => {
4545
const runner = createTestRunner().expect({ transaction: EXPECTED_TRANSACTION }).start();
4646
runner.makeRequest('get', '/');

dev-packages/node-integration-tests/suites/tracing/dataloader/test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { afterAll, describe, expect, test } from 'vitest';
1+
import { afterAll, describe, expect } from 'vitest';
22
import { cleanupChildProcesses, createEsmAndCjsTests } from '../../../utils/runner';
33

44
describe('dataloader auto-instrumentation', () => {
@@ -36,7 +36,7 @@ describe('dataloader auto-instrumentation', () => {
3636
__dirname,
3737
'scenario.mjs',
3838
'instrument.mjs',
39-
createRunner => {
39+
(createRunner, test) => {
4040
test('should auto-instrument `dataloader` package.', async () => {
4141
const runner = createRunner().expect({ transaction: EXPECTED_TRANSACTION }).start();
4242
runner.makeRequest('get', '/');

dev-packages/node-integration-tests/suites/tracing/hapi/test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { afterAll, describe, expect, test } from 'vitest';
1+
import { afterAll, describe, expect } from 'vitest';
22
import { cleanupChildProcesses, createEsmAndCjsTests } from '../../../utils/runner';
33

44
describe('hapi auto-instrumentation', () => {
@@ -36,7 +36,7 @@ describe('hapi auto-instrumentation', () => {
3636
},
3737
};
3838

39-
createEsmAndCjsTests(__dirname, 'scenario.mjs', 'instrument.mjs', createRunner => {
39+
createEsmAndCjsTests(__dirname, 'scenario.mjs', 'instrument.mjs', (createRunner, test) => {
4040
test('should auto-instrument `@hapi/hapi` package.', async () => {
4141
const runner = createRunner().expect({ transaction: EXPECTED_TRANSACTION }).start();
4242
runner.makeRequest('get', '/');

dev-packages/node-integration-tests/utils/runner.ts

Lines changed: 28 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import axios from 'axios';
1616
import { execSync, spawn, spawnSync } from 'child_process';
1717
import { existsSync, readFileSync, unlinkSync, writeFileSync } from 'fs';
1818
import { join } from 'path';
19-
import { afterAll, describe } from 'vitest';
19+
import { afterAll, describe, test } from 'vitest';
2020
import {
2121
assertEnvelopeHeader,
2222
assertSentryCheckIn,
@@ -169,7 +169,11 @@ export function createEsmAndCjsTests(
169169
cwd: string,
170170
scenarioPath: string,
171171
instrumentPath: string,
172-
callback: (createTestRunner: () => ReturnType<typeof createRunner>, mode: 'esm' | 'cjs') => void,
172+
callback: (
173+
createTestRunner: () => ReturnType<typeof createRunner>,
174+
testFn: typeof test | typeof test.fails,
175+
mode: 'esm' | 'cjs',
176+
) => void,
173177
options?: { skipCjs?: boolean; skipEsm?: boolean },
174178
): void {
175179
const mjsScenarioPath = join(cwd, scenarioPath);
@@ -206,16 +210,14 @@ export function createEsmAndCjsTests(
206210
}
207211
});
208212

209-
const scenarios: [mode: 'esm' | 'cjs', getRunner: () => ReturnType<typeof createRunner>][] = [];
210-
if (!options?.skipEsm) {
211-
scenarios.push(['esm', () => createRunner(mjsScenarioPath).withFlags('--import', mjsInstrumentPath)]);
212-
}
213-
if (!options?.skipCjs) {
214-
scenarios.push(['cjs', () => createRunner(cjsScenarioPath).withFlags('--require', cjsInstrumentPath)]);
215-
}
213+
describe('esm', () => {
214+
const testFn = options?.skipEsm ? test.fails : test;
215+
callback(() => createRunner(mjsScenarioPath).withFlags('--import', mjsInstrumentPath), testFn, 'esm');
216+
});
216217

217-
describe.each(scenarios)('%s', (mode, getRunner) => {
218-
callback(getRunner, mode);
218+
describe('cjs', () => {
219+
const testFn = options?.skipCjs ? test.fails : test;
220+
callback(() => createRunner(cjsScenarioPath).withFlags('--require', cjsInstrumentPath), testFn, 'cjs');
219221
});
220222
});
221223
}
@@ -245,7 +247,6 @@ export function createRunner(...paths: string[]) {
245247
let dockerOptions: DockerOptions | undefined;
246248
let ensureNoErrorOutput = false;
247249
const logs: string[] = [];
248-
const cleanups: VoidFunction[] = [];
249250

250251
if (testPath.endsWith('.ts')) {
251252
flags.push('-r', 'ts-node/register');
@@ -282,10 +283,6 @@ export function createRunner(...paths: string[]) {
282283
flags.push('--import', instrumentPath);
283284
return this;
284285
},
285-
withCleanup: function (cleanup: VoidFunction) {
286-
cleanups.push(cleanup);
287-
return this;
288-
},
289286
withMockSentryServer: function () {
290287
withSentryServer = true;
291288
return this;
@@ -308,13 +305,10 @@ export function createRunner(...paths: string[]) {
308305
ensureNoErrorOutput = true;
309306
return this;
310307
},
311-
start: function (done?: (e?: unknown) => void): StartResult {
312-
let resolve: (value: void) => void;
313-
let reject: (reason?: unknown) => void;
314-
const completePromise = new Promise<void>((res, rej) => {
315-
resolve = res;
316-
reject = rej;
317-
});
308+
start: function (): StartResult {
309+
let isComplete = false;
310+
let completeError: Error | undefined;
311+
318312
const expectedEnvelopeCount = Math.max(expectedEnvelopes.length, (expectedEnvelopeHeaders || []).length);
319313

320314
let envelopeCount = 0;
@@ -323,15 +317,13 @@ export function createRunner(...paths: string[]) {
323317
let child: ReturnType<typeof spawn> | undefined;
324318

325319
function complete(error?: Error): void {
326-
cleanups.forEach(cleanup => cleanup());
320+
if (isComplete) {
321+
return;
322+
}
327323

324+
isComplete = true;
325+
completeError = error || undefined;
328326
child?.kill();
329-
done?.(normalize(error));
330-
if (error) {
331-
reject(error);
332-
} else {
333-
resolve();
334-
}
335327
}
336328

337329
/** Called after each expect callback to check if we're complete */
@@ -526,8 +518,12 @@ export function createRunner(...paths: string[]) {
526518
.catch(e => complete(e));
527519

528520
return {
529-
completed: function (): Promise<void> {
530-
return completePromise;
521+
completed: async function (): Promise<void> {
522+
await waitFor(() => isComplete);
523+
524+
if (completeError) {
525+
throw completeError;
526+
}
531527
},
532528
childHasExited: function (): boolean {
533529
return hasExited;

0 commit comments

Comments
 (0)