-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests(e2e): Refactor nestjs e2e applications into multiple smaller te…
…st 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.
- Loading branch information
1 parent
935bb61
commit d629991
Showing
60 changed files
with
690 additions
and
290 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
...sts/test-applications/nestjs/package.json → ...st-applications/nestjs-basic/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
{ | ||
"name": "nestjs", | ||
"name": "nestjs-basic", | ||
"version": "0.0.1", | ||
"private": true, | ||
"scripts": { | ||
|
File renamed without changes.
37 changes: 37 additions & 0 deletions
37
dev-packages/e2e-tests/test-applications/nestjs-basic/src/app.controller.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { Controller, Get, Param } from '@nestjs/common'; | ||
import { AppService } from './app.service'; | ||
|
||
@Controller() | ||
export class AppController { | ||
constructor(private readonly appService: AppService) {} | ||
|
||
@Get('test-transaction') | ||
testTransaction() { | ||
return this.appService.testTransaction(); | ||
} | ||
|
||
@Get('test-exception/:id') | ||
async testException(@Param('id') id: string) { | ||
return this.appService.testException(id); | ||
} | ||
|
||
@Get('test-expected-exception/:id') | ||
async testExpectedException(@Param('id') id: string) { | ||
return this.appService.testExpectedException(id); | ||
} | ||
|
||
@Get('test-span-decorator-async') | ||
async testSpanDecoratorAsync() { | ||
return { result: await this.appService.testSpanDecoratorAsync() }; | ||
} | ||
|
||
@Get('test-span-decorator-sync') | ||
async testSpanDecoratorSync() { | ||
return { result: await this.appService.testSpanDecoratorSync() }; | ||
} | ||
|
||
@Get('kill-test-cron') | ||
async killTestCron() { | ||
this.appService.killTestCron(); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
dev-packages/e2e-tests/test-applications/nestjs-basic/src/app.module.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { Module } from '@nestjs/common'; | ||
import { ScheduleModule } from '@nestjs/schedule'; | ||
import { AppController } from './app.controller'; | ||
import { AppService } from './app.service'; | ||
|
||
@Module({ | ||
imports: [ScheduleModule.forRoot()], | ||
controllers: [AppController], | ||
providers: [AppService], | ||
}) | ||
export class AppModule {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
dev-packages/e2e-tests/test-applications/nestjs-basic/src/instrument.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import * as Sentry from '@sentry/nestjs'; | ||
|
||
Sentry.init({ | ||
environment: 'qa', // dynamic sampling bias to keep transactions | ||
dsn: process.env.E2E_TEST_DSN, | ||
tunnel: `http://localhost:3031/`, // proxy server | ||
tracesSampleRate: 1, | ||
}); |
20 changes: 20 additions & 0 deletions
20
dev-packages/e2e-tests/test-applications/nestjs-basic/src/main.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// Import this first | ||
import './instrument'; | ||
|
||
// Import other modules | ||
import { BaseExceptionFilter, HttpAdapterHost, NestFactory } from '@nestjs/core'; | ||
import * as Sentry from '@sentry/nestjs'; | ||
import { AppModule } from './app.module'; | ||
|
||
const PORT = 3030; | ||
|
||
async function bootstrap() { | ||
const app = await NestFactory.create(AppModule); | ||
|
||
const { httpAdapter } = app.get(HttpAdapterHost); | ||
Sentry.setupNestErrorHandler(app, new BaseExceptionFilter(httpAdapter)); | ||
|
||
await app.listen(PORT); | ||
} | ||
|
||
bootstrap(); |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
56 changes: 56 additions & 0 deletions
56
dev-packages/e2e-tests/test-applications/nestjs-distributed-tracing/.gitignore
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
# compiled output | ||
/dist | ||
/node_modules | ||
/build | ||
|
||
# Logs | ||
logs | ||
*.log | ||
npm-debug.log* | ||
pnpm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
lerna-debug.log* | ||
|
||
# OS | ||
.DS_Store | ||
|
||
# Tests | ||
/coverage | ||
/.nyc_output | ||
|
||
# IDEs and editors | ||
/.idea | ||
.project | ||
.classpath | ||
.c9/ | ||
*.launch | ||
.settings/ | ||
*.sublime-workspace | ||
|
||
# IDE - VSCode | ||
.vscode/* | ||
!.vscode/settings.json | ||
!.vscode/tasks.json | ||
!.vscode/launch.json | ||
!.vscode/extensions.json | ||
|
||
# dotenv environment variable files | ||
.env | ||
.env.development.local | ||
.env.test.local | ||
.env.production.local | ||
.env.local | ||
|
||
# temp directory | ||
.temp | ||
.tmp | ||
|
||
# Runtime data | ||
pids | ||
*.pid | ||
*.seed | ||
*.pid.lock | ||
|
||
# Diagnostic reports (https://nodejs.org/api/report.html) | ||
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json |
2 changes: 2 additions & 0 deletions
2
dev-packages/e2e-tests/test-applications/nestjs-distributed-tracing/.npmrc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
@sentry:registry=http://127.0.0.1:4873 | ||
@sentry-internal:registry=http://127.0.0.1:4873 |
8 changes: 8 additions & 0 deletions
8
dev-packages/e2e-tests/test-applications/nestjs-distributed-tracing/nest-cli.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"$schema": "https://json.schemastore.org/nest-cli", | ||
"collection": "@nestjs/schematics", | ||
"sourceRoot": "src", | ||
"compilerOptions": { | ||
"deleteOutDir": true | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
dev-packages/e2e-tests/test-applications/nestjs-distributed-tracing/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
{ | ||
"name": "nestjs-distributed-tracing", | ||
"version": "0.0.1", | ||
"private": true, | ||
"scripts": { | ||
"build": "nest build", | ||
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"", | ||
"start": "nest start", | ||
"start:dev": "nest start --watch", | ||
"start:debug": "nest start --debug --watch", | ||
"start:prod": "node dist/main", | ||
"clean": "npx rimraf node_modules pnpm-lock.yaml", | ||
"test": "playwright test", | ||
"test:build": "pnpm install", | ||
"test:assert": "pnpm test" | ||
}, | ||
"dependencies": { | ||
"@nestjs/common": "^10.0.0", | ||
"@nestjs/core": "^10.0.0", | ||
"@nestjs/platform-express": "^10.0.0", | ||
"@sentry/nestjs": "latest || *", | ||
"@sentry/types": "latest || *", | ||
"reflect-metadata": "^0.2.0", | ||
"rxjs": "^7.8.1" | ||
}, | ||
"devDependencies": { | ||
"@playwright/test": "^1.44.1", | ||
"@sentry-internal/test-utils": "link:../../../test-utils", | ||
"@nestjs/cli": "^10.0.0", | ||
"@nestjs/schematics": "^10.0.0", | ||
"@nestjs/testing": "^10.0.0", | ||
"@types/express": "^4.17.17", | ||
"@types/node": "18.15.1", | ||
"@types/supertest": "^6.0.0", | ||
"@typescript-eslint/eslint-plugin": "^6.0.0", | ||
"@typescript-eslint/parser": "^6.0.0", | ||
"eslint": "^8.42.0", | ||
"eslint-config-prettier": "^9.0.0", | ||
"eslint-plugin-prettier": "^5.0.0", | ||
"prettier": "^3.0.0", | ||
"source-map-support": "^0.5.21", | ||
"supertest": "^6.3.3", | ||
"ts-loader": "^9.4.3", | ||
"tsconfig-paths": "^4.2.0", | ||
"typescript": "^4.9.5" | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
dev-packages/e2e-tests/test-applications/nestjs-distributed-tracing/playwright.config.mjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { getPlaywrightConfig } from '@sentry-internal/test-utils'; | ||
|
||
const config = getPlaywrightConfig({ | ||
startCommand: `pnpm start`, | ||
}); | ||
|
||
export default config; |
File renamed without changes.
25 changes: 25 additions & 0 deletions
25
dev-packages/e2e-tests/test-applications/nestjs-distributed-tracing/src/main.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// Import this first | ||
import './instrument'; | ||
|
||
// Import other modules | ||
import { BaseExceptionFilter, HttpAdapterHost, NestFactory } from '@nestjs/core'; | ||
import * as Sentry from '@sentry/nestjs'; | ||
import { TraceInitiatorModule } from './trace-initiator.module'; | ||
import { TraceReceiverModule } from './trace-receiver.module'; | ||
|
||
const TRACE_INITIATOR_PORT = 3030; | ||
const TRACE_RECEIVER_PORT = 3040; | ||
|
||
async function bootstrap() { | ||
const trace_initiator_app = await NestFactory.create(TraceInitiatorModule); | ||
|
||
const { httpAdapter } = trace_initiator_app.get(HttpAdapterHost); | ||
Sentry.setupNestErrorHandler(trace_initiator_app, new BaseExceptionFilter(httpAdapter)); | ||
|
||
await trace_initiator_app.listen(TRACE_INITIATOR_PORT); | ||
|
||
const trace_receiver_app = await NestFactory.create(TraceReceiverModule); | ||
await trace_receiver_app.listen(TRACE_RECEIVER_PORT); | ||
} | ||
|
||
bootstrap(); |
Oops, something went wrong.