Skip to content

Commit

Permalink
tests(e2e): Remove await timeout in nest e2e tests (#13243)
Browse files Browse the repository at this point in the history
Adding a separate flush endpoint that flushes the client in the
application so that we can remove the timeout await and speed up tests.
  • Loading branch information
nicohrubec authored Aug 6, 2024
1 parent 22905fe commit c8054cc
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Controller, Get, Param, ParseIntPipe, UseGuards, UseInterceptors } from '@nestjs/common';
import { flush } from '@sentry/nestjs';
import { AppService } from './app.service';
import { ExampleGuard } from './example.guard';
import { ExampleInterceptor } from './example.interceptor';
Expand Down Expand Up @@ -68,4 +69,9 @@ export class AppController {
async killTestCron() {
this.appService.killTestCron();
}

@Get('flush')
async flush() {
await flush();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ test('Does not send HttpExceptions to Sentry', async ({ baseURL }) => {
await transactionEventPromise400;
await transactionEventPromise500;

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

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

await transactionEventPromise;

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

expect(errorEventOccurred).toBe(false);
});
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Controller, Get, Param } from '@nestjs/common';
import { flush } from '@sentry/nestjs';
import { AppService } from './app.service';

@Controller()
Expand All @@ -14,4 +15,9 @@ export class AppController {
async testExpectedException(@Param('id') id: string) {
return this.appService.testExpectedException(id);
}

@Get('flush')
async flush() {
await flush();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ test('Does not send exception to Sentry if user-defined global exception filter

await transactionEventPromise;

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

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

await transactionEventPromise;

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

expect(errorEventOccurred).toBe(false);
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Controller, Get, Param, ParseIntPipe, UseGuards, UseInterceptors } from '@nestjs/common';
import { flush } from '@sentry/nestjs';
import { AppService } from './app.service';
import { ExampleGuard } from './example.guard';
import { ExampleInterceptor } from './example.interceptor';
Expand Down Expand Up @@ -68,4 +69,9 @@ export class AppController {
async killTestCron() {
this.appService.killTestCron();
}

@Get('flush')
async flush() {
await flush();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ test('Does not send HttpExceptions to Sentry', async ({ baseURL }) => {
await transactionEventPromise400;
await transactionEventPromise500;

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

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

await transactionEventPromise;

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

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

0 comments on commit c8054cc

Please sign in to comment.