Skip to content

Commit bb300a5

Browse files
committed
test runner improvements
1 parent 293007c commit bb300a5

File tree

4 files changed

+199
-71
lines changed

4 files changed

+199
-71
lines changed

dev-packages/node-integration-tests/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@
2727
"dependencies": {
2828
"@aws-sdk/client-s3": "^3.552.0",
2929
"@hapi/hapi": "^21.3.10",
30-
"@nestjs/common": "10.4.5",
31-
"@nestjs/core": "10.4.5",
32-
"@nestjs/platform-express": "10.4.5",
30+
"@nestjs/common": "10.4.0",
31+
"@nestjs/core": "10.4.0",
32+
"@nestjs/platform-express": "10.4.0",
3333
"@prisma/client": "5.9.1",
3434
"@sentry/aws-serverless": "8.37.1",
3535
"@sentry/node": "8.37.1",

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

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import type {
1515
} from '@sentry/types';
1616
import axios from 'axios';
1717
import { createBasicSentryServer } from './server';
18+
import { normalize } from '@sentry/utils';
1819

1920
export function assertSentryEvent(actual: Event, expected: Event): void {
2021
expect(actual).toMatchObject({
@@ -130,8 +131,7 @@ async function runDockerCompose(options: DockerOptions): Promise<VoidFunction> {
130131
function newData(data: Buffer): void {
131132
const text = data.toString('utf8');
132133

133-
// eslint-disable-next-line no-console
134-
if (process.env.DEBUG) console.log(text);
134+
if (process.env.DEBUG) log(text);
135135

136136
for (const match of options.readyMatches) {
137137
if (text.includes(match)) {
@@ -254,7 +254,7 @@ export function createRunner(...paths: string[]) {
254254

255255
function complete(error?: Error): void {
256256
child?.kill();
257-
done?.(error);
257+
done?.(normalize(error));
258258
}
259259

260260
/** Called after each expect callback to check if we're complete */
@@ -379,6 +379,8 @@ export function createRunner(...paths: string[]) {
379379
? runDockerCompose(dockerOptions)
380380
: Promise.resolve(undefined);
381381

382+
log('before start');
383+
382384
const startup = Promise.all([dockerStartup, serverStartup]) as Promise<[DockerStartup, ServerStartup]>;
383385

384386
startup
@@ -397,8 +399,7 @@ export function createRunner(...paths: string[]) {
397399
? { ...process.env, ...withEnv, SENTRY_DSN: `http://public@localhost:${mockServerPort}/1337` }
398400
: { ...process.env, ...withEnv };
399401

400-
// eslint-disable-next-line no-console
401-
if (process.env.DEBUG) console.log('starting scenario', testPath, flags, env.SENTRY_DSN);
402+
if (process.env.DEBUG) log('starting scenario', testPath, flags, env.SENTRY_DSN);
402403

403404
child = spawn('node', [...flags, testPath], { env });
404405

@@ -425,8 +426,7 @@ export function createRunner(...paths: string[]) {
425426

426427
// Pass error to done to end the test quickly
427428
child.on('error', e => {
428-
// eslint-disable-next-line no-console
429-
if (process.env.DEBUG) console.log('scenario error', e);
429+
if (process.env.DEBUG) log('scenario error', e);
430430
complete(e);
431431
});
432432

@@ -465,8 +465,7 @@ export function createRunner(...paths: string[]) {
465465
logs.push(line.trim());
466466

467467
buffer = Buffer.from(buffer.subarray(splitIndex + 1));
468-
// eslint-disable-next-line no-console
469-
if (process.env.DEBUG) console.log('line', line);
468+
if (process.env.DEBUG) log('line', line);
470469
tryParseEnvelopeFromStdoutLine(line);
471470
}
472471
});
@@ -490,28 +489,34 @@ export function createRunner(...paths: string[]) {
490489
await waitFor(() => scenarioServerPort !== undefined);
491490
} catch (e) {
492491
complete(e as Error);
493-
return undefined;
492+
return;
494493
}
495494

496495
const url = `http://localhost:${scenarioServerPort}${path}`;
497-
if (expectError) {
498-
try {
499-
if (method === 'get') {
500-
await axios.get(url, { headers });
501-
} else {
502-
await axios.post(url, data, { headers });
503-
}
504-
} catch (e) {
496+
497+
try {
498+
if (method === 'post') {
499+
const res = await axios.post(url, data, { headers });
500+
return res.data;
501+
} else {
502+
const res = await axios.get(url, { headers });
503+
return res.data;
504+
}
505+
} catch (e) {
506+
if (expectError) {
505507
return;
506508
}
509+
510+
complete(e as Error);
507511
return;
508-
} else if (method === 'get') {
509-
return (await axios.get(url, { headers })).data;
510-
} else {
511-
return (await axios.post(url, data, { headers })).data;
512512
}
513513
},
514514
};
515515
},
516516
};
517517
}
518+
519+
function log(...args: unknown[]): void {
520+
// eslint-disable-next-line no-console
521+
console.log(...args.map(arg => normalize(arg)));
522+
}

packages/nestjs/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@
5050
"@sentry/utils": "8.37.1"
5151
},
5252
"devDependencies": {
53-
"@nestjs/common": "10.4.5",
54-
"@nestjs/core": "10.4.5"
53+
"@nestjs/common": "10.4.1",
54+
"@nestjs/core": "10.4.1"
5555
},
5656
"peerDependencies": {
5757
"@nestjs/common": "^8.0.0 || ^9.0.0 || ^10.0.0",

0 commit comments

Comments
 (0)