Skip to content

Commit d629991

Browse files
authored
tests(e2e): Refactor nestjs e2e applications into multiple smaller test applications (#12948)
Refactor of the existing nestjs test applications. Before we had one sample application testing everything nest-related. This PR splits them up into three applications to make it more readable and easier to understand what is being tested. It also allows for iterating a bit quicker in local development. No new functionality was added. Will add more tests in a follow-up. The three new services are: - nestjs-basic: Simple nestjs application with no submodules and tests for basic functionality of the SDK like error monitoring and span instrumentation. - nestjs-with-submodules: NestJS application that is bit more complex including a submodule (and potentially multiple in the future) to have a more realistic setup for more advanced testing. - nestjs-distributed-tracing: Includes tests for trace propagation with multiple services.
1 parent 935bb61 commit d629991

Some content is hidden

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

60 files changed

+690
-290
lines changed

.github/workflows/build.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1037,7 +1037,9 @@ jobs:
10371037
'generic-ts3.8',
10381038
'node-fastify',
10391039
'node-hapi',
1040-
'nestjs',
1040+
'nestjs-basic',
1041+
'nestjs-distributed-tracing',
1042+
'nestjs-with-submodules',
10411043
'node-exports-test-app',
10421044
'node-koa',
10431045
'node-connect',

dev-packages/e2e-tests/test-applications/nestjs/package.json renamed to dev-packages/e2e-tests/test-applications/nestjs-basic/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "nestjs",
2+
"name": "nestjs-basic",
33
"version": "0.0.1",
44
"private": true,
55
"scripts": {
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import { Controller, Get, Param } from '@nestjs/common';
2+
import { AppService } from './app.service';
3+
4+
@Controller()
5+
export class AppController {
6+
constructor(private readonly appService: AppService) {}
7+
8+
@Get('test-transaction')
9+
testTransaction() {
10+
return this.appService.testTransaction();
11+
}
12+
13+
@Get('test-exception/:id')
14+
async testException(@Param('id') id: string) {
15+
return this.appService.testException(id);
16+
}
17+
18+
@Get('test-expected-exception/:id')
19+
async testExpectedException(@Param('id') id: string) {
20+
return this.appService.testExpectedException(id);
21+
}
22+
23+
@Get('test-span-decorator-async')
24+
async testSpanDecoratorAsync() {
25+
return { result: await this.appService.testSpanDecoratorAsync() };
26+
}
27+
28+
@Get('test-span-decorator-sync')
29+
async testSpanDecoratorSync() {
30+
return { result: await this.appService.testSpanDecoratorSync() };
31+
}
32+
33+
@Get('kill-test-cron')
34+
async killTestCron() {
35+
this.appService.killTestCron();
36+
}
37+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { Module } from '@nestjs/common';
2+
import { ScheduleModule } from '@nestjs/schedule';
3+
import { AppController } from './app.controller';
4+
import { AppService } from './app.service';
5+
6+
@Module({
7+
imports: [ScheduleModule.forRoot()],
8+
controllers: [AppController],
9+
providers: [AppService],
10+
})
11+
export class AppModule {}

dev-packages/e2e-tests/test-applications/nestjs/src/app.service.ts renamed to dev-packages/e2e-tests/test-applications/nestjs-basic/src/app.service.ts

Lines changed: 1 addition & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import { Cron, SchedulerRegistry } from '@nestjs/schedule';
33
import * as Sentry from '@sentry/nestjs';
44
import { SentryCron, SentryTraced } from '@sentry/nestjs';
55
import type { MonitorConfig } from '@sentry/types';
6-
import { makeHttpRequest } from './utils';
76

87
const monitorConfig: MonitorConfig = {
98
schedule: {
@@ -13,53 +12,15 @@ const monitorConfig: MonitorConfig = {
1312
};
1413

1514
@Injectable()
16-
export class AppService1 {
15+
export class AppService {
1716
constructor(private schedulerRegistry: SchedulerRegistry) {}
1817

19-
testSuccess() {
20-
return { version: 'v1' };
21-
}
22-
23-
testParam(id: string) {
24-
return {
25-
paramWas: id,
26-
};
27-
}
28-
29-
testInboundHeaders(headers: Record<string, string>, id: string) {
30-
return {
31-
headers,
32-
id,
33-
};
34-
}
35-
36-
async testOutgoingHttp(id: string) {
37-
const data = await makeHttpRequest(`http://localhost:3030/test-inbound-headers/${id}`);
38-
39-
return data;
40-
}
41-
42-
async testOutgoingFetch(id: string) {
43-
const response = await fetch(`http://localhost:3030/test-inbound-headers/${id}`);
44-
const data = await response.json();
45-
46-
return data;
47-
}
48-
4918
testTransaction() {
5019
Sentry.startSpan({ name: 'test-span' }, () => {
5120
Sentry.startSpan({ name: 'child-span' }, () => {});
5221
});
5322
}
5423

55-
async testError() {
56-
const exceptionId = Sentry.captureException(new Error('This is an error'));
57-
58-
await Sentry.flush(2000);
59-
60-
return { exceptionId };
61-
}
62-
6324
testException(id: string) {
6425
throw new Error(`This is an exception with id ${id}`);
6526
}
@@ -68,26 +29,6 @@ export class AppService1 {
6829
throw new HttpException(`This is an expected exception with id ${id}`, HttpStatus.FORBIDDEN);
6930
}
7031

71-
async testOutgoingFetchExternalAllowed() {
72-
const fetchResponse = await fetch('http://localhost:3040/external-allowed');
73-
74-
return fetchResponse.json();
75-
}
76-
77-
async testOutgoingFetchExternalDisallowed() {
78-
const fetchResponse = await fetch('http://localhost:3040/external-disallowed');
79-
80-
return fetchResponse.json();
81-
}
82-
83-
async testOutgoingHttpExternalAllowed() {
84-
return makeHttpRequest('http://localhost:3040/external-allowed');
85-
}
86-
87-
async testOutgoingHttpExternalDisallowed() {
88-
return makeHttpRequest('http://localhost:3040/external-disallowed');
89-
}
90-
9132
@SentryTraced('wait and return a string')
9233
async wait() {
9334
await new Promise(resolve => setTimeout(resolve, 500));
@@ -124,20 +65,3 @@ export class AppService1 {
12465
this.schedulerRegistry.deleteCronJob('test-cron-job');
12566
}
12667
}
127-
128-
@Injectable()
129-
export class AppService2 {
130-
externalAllowed(headers: Record<string, string>) {
131-
return {
132-
headers,
133-
route: 'external-allowed',
134-
};
135-
}
136-
137-
externalDisallowed(headers: Record<string, string>) {
138-
return {
139-
headers,
140-
route: 'external-disallowed',
141-
};
142-
}
143-
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import * as Sentry from '@sentry/nestjs';
2+
3+
Sentry.init({
4+
environment: 'qa', // dynamic sampling bias to keep transactions
5+
dsn: process.env.E2E_TEST_DSN,
6+
tunnel: `http://localhost:3031/`, // proxy server
7+
tracesSampleRate: 1,
8+
});

0 commit comments

Comments
 (0)