Skip to content

Commit

Permalink
test(nestjs-tools-async-local-storage): remove supertest
Browse files Browse the repository at this point in the history
  • Loading branch information
getlarge committed Sep 13, 2024
1 parent 6f5c646 commit 03badfd
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 174 deletions.
161 changes: 0 additions & 161 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@
"@types/express": "^4.17.21",
"@types/jest": "29.5.13",
"@types/node": "^18.16.9",
"@types/supertest": "^6.0.2",
"@types/uuid": "^9.0.8",
"@typescript-eslint/eslint-plugin": "7.18.0",
"@typescript-eslint/parser": "7.18.0",
Expand All @@ -76,7 +75,6 @@
"mqtt": "^5.5.2",
"nx": "19.7.3",
"prettier": "^3.3.2",
"supertest": "^6.3.4",
"ts-jest": "^29.1.0",
"ts-node": "10.9.1",
"typescript": "5.5.4"
Expand Down
44 changes: 33 additions & 11 deletions packages/async-local-storage/test/async-local-storage.spec.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
/* eslint-disable max-lines-per-function */
import { INestApplication, Provider } from '@nestjs/common';
import { Provider } from '@nestjs/common';
import { APP_GUARD, APP_INTERCEPTOR } from '@nestjs/core';
import { FastifyAdapter } from '@nestjs/platform-fastify';
import { FastifyAdapter, NestFastifyApplication } from '@nestjs/platform-fastify';
import { Test, TestingModule } from '@nestjs/testing';
import { AsyncLocalStorage } from 'async_hooks';
import * as request from 'supertest';

import {
AsyncLocalStorageGuard,
Expand All @@ -22,18 +21,21 @@ declare module '../src/lib/async-local-storage.interfaces' {
}
}

const moduleFactory = async (options: AsyncLocalStorageModuleOptions, providers: Provider[] = []) => {
const module: TestingModule = await Test.createTestingModule({
const moduleFactory = async (
options: AsyncLocalStorageModuleOptions,
providers: Provider[] = [],
): Promise<NestFastifyApplication> => {
const moduleFixture: TestingModule = await Test.createTestingModule({
imports: [AsyncLocalStorageModule.forRoot(options)],
providers: [ExampleService, ...providers],
controllers: [ExampleController],
}).compile();

return module.createNestApplication(new FastifyAdapter());
return moduleFixture.createNestApplication(new FastifyAdapter()) as NestFastifyApplication;
};

describe('AsyncLocalStorageModule', () => {
let app: INestApplication;
let app: NestFastifyApplication;
const route = '/Example';
const expectedResponse = { type: 'http' };

Expand All @@ -50,7 +52,12 @@ describe('AsyncLocalStorageModule', () => {
[{ provide: APP_GUARD, useClass: AsyncLocalStorageGuard }],
).then((app) => app.init());
//
const { body } = await request(app.getHttpServer()).get(route);
const { payload } = await app.inject({
method: 'GET',
url: route,
});

const body = JSON.parse(payload);
expect(body).toEqual(expectedResponse);
});

Expand All @@ -61,7 +68,12 @@ describe('AsyncLocalStorageModule', () => {
useGuard: true,
}).then((app) => app.init());
//
const { body } = await request(app.getHttpServer()).get(route);
const { payload } = await app.inject({
method: 'GET',
url: route,
});

const body = JSON.parse(payload);
expect(body).toEqual(expectedResponse);
});

Expand All @@ -74,7 +86,12 @@ describe('AsyncLocalStorageModule', () => {
[{ provide: APP_INTERCEPTOR, useClass: AsyncLocalStorageInterceptor }],
).then((app) => app.init());
//
const { body } = await request(app.getHttpServer()).get(route);
const { payload } = await app.inject({
method: 'GET',
url: route,
});

const body = JSON.parse(payload);
expect(body).toEqual(expectedResponse);
});

Expand All @@ -85,7 +102,12 @@ describe('AsyncLocalStorageModule', () => {
useInterceptor: true,
}).then((app) => app.init());
//
const { body } = await request(app.getHttpServer()).get(route);
const { payload } = await app.inject({
method: 'GET',
url: route,
});

const body = JSON.parse(payload);
expect(body).toEqual(expectedResponse);
});

Expand Down

0 comments on commit 03badfd

Please sign in to comment.