Skip to content

Commit c8054cc

Browse files
authored
tests(e2e): Remove await timeout in nest e2e tests (#13243)
Adding a separate flush endpoint that flushes the client in the application so that we can remove the timeout await and speed up tests.
1 parent 22905fe commit c8054cc

File tree

6 files changed

+24
-6
lines changed

6 files changed

+24
-6
lines changed

dev-packages/e2e-tests/test-applications/nestjs-basic/src/app.controller.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { Controller, Get, Param, ParseIntPipe, UseGuards, UseInterceptors } from '@nestjs/common';
2+
import { flush } from '@sentry/nestjs';
23
import { AppService } from './app.service';
34
import { ExampleGuard } from './example.guard';
45
import { ExampleInterceptor } from './example.interceptor';
@@ -68,4 +69,9 @@ export class AppController {
6869
async killTestCron() {
6970
this.appService.killTestCron();
7071
}
72+
73+
@Get('flush')
74+
async flush() {
75+
await flush();
76+
}
7177
}

dev-packages/e2e-tests/test-applications/nestjs-basic/tests/errors.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ test('Does not send HttpExceptions to Sentry', async ({ baseURL }) => {
6565
await transactionEventPromise400;
6666
await transactionEventPromise500;
6767

68-
await new Promise(resolve => setTimeout(resolve, 10000));
68+
(await fetch(`${baseURL}/flush`)).text();
6969

7070
expect(errorEventOccurred).toBe(false);
7171
});
@@ -90,7 +90,7 @@ test('Does not send RpcExceptions to Sentry', async ({ baseURL }) => {
9090

9191
await transactionEventPromise;
9292

93-
await new Promise(resolve => setTimeout(resolve, 10000));
93+
(await fetch(`${baseURL}/flush`)).text();
9494

9595
expect(errorEventOccurred).toBe(false);
9696
});

dev-packages/e2e-tests/test-applications/nestjs-with-submodules/src/app.controller.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { Controller, Get, Param } from '@nestjs/common';
2+
import { flush } from '@sentry/nestjs';
23
import { AppService } from './app.service';
34

45
@Controller()
@@ -14,4 +15,9 @@ export class AppController {
1415
async testExpectedException(@Param('id') id: string) {
1516
return this.appService.testExpectedException(id);
1617
}
18+
19+
@Get('flush')
20+
async flush() {
21+
await flush();
22+
}
1723
}

dev-packages/e2e-tests/test-applications/nestjs-with-submodules/tests/errors.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ test('Does not send exception to Sentry if user-defined global exception filter
8181

8282
await transactionEventPromise;
8383

84-
await new Promise(resolve => setTimeout(resolve, 10000));
84+
(await fetch(`${baseURL}/flush`)).text();
8585

8686
expect(errorEventOccurred).toBe(false);
8787
});
@@ -111,7 +111,7 @@ test('Does not send exception to Sentry if user-defined local exception filter a
111111

112112
await transactionEventPromise;
113113

114-
await new Promise(resolve => setTimeout(resolve, 10000));
114+
(await fetch(`${baseURL}/flush`)).text();
115115

116116
expect(errorEventOccurred).toBe(false);
117117
});

dev-packages/e2e-tests/test-applications/node-nestjs-basic/src/app.controller.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { Controller, Get, Param, ParseIntPipe, UseGuards, UseInterceptors } from '@nestjs/common';
2+
import { flush } from '@sentry/nestjs';
23
import { AppService } from './app.service';
34
import { ExampleGuard } from './example.guard';
45
import { ExampleInterceptor } from './example.interceptor';
@@ -68,4 +69,9 @@ export class AppController {
6869
async killTestCron() {
6970
this.appService.killTestCron();
7071
}
72+
73+
@Get('flush')
74+
async flush() {
75+
await flush();
76+
}
7177
}

dev-packages/e2e-tests/test-applications/node-nestjs-basic/tests/errors.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ test('Does not send HttpExceptions to Sentry', async ({ baseURL }) => {
6565
await transactionEventPromise400;
6666
await transactionEventPromise500;
6767

68-
await new Promise(resolve => setTimeout(resolve, 10000));
68+
(await fetch(`${baseURL}/flush`)).text();
6969

7070
expect(errorEventOccurred).toBe(false);
7171
});
@@ -90,7 +90,7 @@ test('Does not send RpcExceptions to Sentry', async ({ baseURL }) => {
9090

9191
await transactionEventPromise;
9292

93-
await new Promise(resolve => setTimeout(resolve, 10000));
93+
(await fetch(`${baseURL}/flush`)).text();
9494

9595
expect(errorEventOccurred).toBe(false);
9696
});

0 commit comments

Comments
 (0)