diff --git a/integration/cors/e2e/express.spec.ts b/integration/cors/e2e/express.spec.ts index c13abf4d9a1..8e268c3166e 100644 --- a/integration/cors/e2e/express.spec.ts +++ b/integration/cors/e2e/express.spec.ts @@ -1,10 +1,10 @@ -import { NestFastifyApplication } from '@nestjs/platform-fastify'; +import { NestExpressApplication } from '@nestjs/platform-express'; import { Test } from '@nestjs/testing'; import * as request from 'supertest'; import { AppModule } from '../src/app.module'; describe('Express Cors', () => { - let app: NestFastifyApplication; + let app: NestExpressApplication; const configs = [ { origin: 'example.com', @@ -30,7 +30,7 @@ describe('Express Cors', () => { imports: [AppModule], }).compile(); - app = module.createNestApplication(); + app = module.createNestApplication(); let requestId = 0; const configDelegation = function (req, cb) { @@ -84,7 +84,7 @@ describe('Express Cors', () => { cb(null, config); }; - app = module.createNestApplication(null, { + app = module.createNestApplication({ cors: configDelegation, }); @@ -126,7 +126,7 @@ describe('Express Cors', () => { imports: [AppModule], }).compile(); - app = module.createNestApplication(); + app = module.createNestApplication(); app.enableCors(configs[0]); await app.init(); @@ -153,7 +153,7 @@ describe('Express Cors', () => { imports: [AppModule], }).compile(); - app = module.createNestApplication(null, { + app = module.createNestApplication({ cors: configs[0], }); await app.init(); diff --git a/integration/cors/e2e/fastify.spec.ts b/integration/cors/e2e/fastify.spec.ts index b98d1232848..0029e202833 100644 --- a/integration/cors/e2e/fastify.spec.ts +++ b/integration/cors/e2e/fastify.spec.ts @@ -1,4 +1,7 @@ -import { NestFastifyApplication } from '@nestjs/platform-fastify'; +import { + NestFastifyApplication, + FastifyAdapter, +} from '@nestjs/platform-fastify'; import { Test } from '@nestjs/testing'; import * as request from 'supertest'; import { AppModule } from '../src/app.module'; @@ -30,7 +33,9 @@ describe('Fastify Cors', () => { imports: [AppModule], }).compile(); - app = module.createNestApplication(); + app = module.createNestApplication( + new FastifyAdapter(), + ); let requestId = 0; const configDelegation = function (req, cb) { @@ -84,9 +89,12 @@ describe('Fastify Cors', () => { cb(null, config); }; - app = module.createNestApplication(null, { - cors: configDelegation, - }); + app = module.createNestApplication( + new FastifyAdapter(), + { + cors: configDelegation, + }, + ); await app.init(); }); @@ -127,7 +135,9 @@ describe('Fastify Cors', () => { imports: [AppModule], }).compile(); - app = module.createNestApplication(); + app = module.createNestApplication( + new FastifyAdapter(), + ); app.enableCors(configs[0]); await app.init(); @@ -147,16 +157,19 @@ describe('Fastify Cors', () => { after(async () => { await app.close(); }); - + describe('Application Options', () => { before(async () => { const module = await Test.createTestingModule({ imports: [AppModule], }).compile(); - app = module.createNestApplication(null, { - cors: configs[0], - }); + app = module.createNestApplication( + new FastifyAdapter(), + { + cors: configs[0], + }, + ); await app.init(); }); diff --git a/integration/nest-application/raw-body/e2e/express.spec.ts b/integration/nest-application/raw-body/e2e/express.spec.ts index 910a0785c2b..bc4501f3ed4 100644 --- a/integration/nest-application/raw-body/e2e/express.spec.ts +++ b/integration/nest-application/raw-body/e2e/express.spec.ts @@ -13,10 +13,9 @@ describe('Raw body (Express Application)', () => { imports: [ExpressModule], }).compile(); - app = moduleFixture.createNestApplication( - undefined, - { rawBody: true }, - ); + app = moduleFixture.createNestApplication({ + rawBody: true, + }); }); it('should return exact post body', async () => { diff --git a/package-lock.json b/package-lock.json index 1701f5ffd2b..65971fd68c7 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1390,9 +1390,9 @@ } }, "@fastify/cors": { - "version": "7.0.0", - "resolved": "https://registry.npmjs.org/@fastify/cors/-/cors-7.0.0.tgz", - "integrity": "sha512-nlo6ScwagBNJacAZD3KX90xjWLIoV0vN9QqoX1wUE9ZeZMdvkVkMZCGlxEtr00NshV0X5wDge4w5rwox7rRzSg==", + "version": "8.0.0", + "resolved": "https://registry.npmjs.org/@fastify/cors/-/cors-8.0.0.tgz", + "integrity": "sha512-mB2GsA7aVwq7XG6B2OM1FMpcaiXY69ZbM1h/xDJxLEVu5ITGcs5XYrBIYTMNU2dQtzO6mzXhGd2dEKaCnB7UgQ==", "dev": true, "requires": { "fastify-plugin": "^3.0.0", @@ -11444,10 +11444,6 @@ "concat-map": "0.0.1" } }, - "chownr": { - "version": "1.1.1", - "bundled": true - }, "code-point-at": { "version": "1.1.0", "bundled": true, @@ -11499,13 +11495,6 @@ "dev": true, "optional": true }, - "fs-minipass": { - "version": "1.2.5", - "bundled": true, - "requires": { - "minipass": "^2.2.1" - } - }, "fs.realpath": { "version": "1.0.0", "bundled": true, @@ -11612,21 +11601,6 @@ "dev": true, "optional": true }, - "minipass": { - "version": "2.3.5", - "bundled": true, - "requires": { - "safe-buffer": "^5.1.2", - "yallist": "^3.0.0" - } - }, - "minizlib": { - "version": "1.2.1", - "bundled": true, - "requires": { - "minipass": "^2.2.1" - } - }, "mkdirp": { "version": "0.5.1", "bundled": true, @@ -11810,7 +11784,9 @@ }, "safe-buffer": { "version": "5.1.2", - "bundled": true + "bundled": true, + "dev": true, + "optional": true }, "safer-buffer": { "version": "2.1.2", @@ -11897,10 +11873,6 @@ "bundled": true, "dev": true, "optional": true - }, - "yallist": { - "version": "3.0.3", - "bundled": true } } }, diff --git a/package.json b/package.json index 8785144d33a..0fe1840114f 100644 --- a/package.json +++ b/package.json @@ -74,7 +74,7 @@ "@codechecks/client": "0.1.12", "@commitlint/cli": "17.0.2", "@commitlint/config-angular": "17.0.0", - "@fastify/cors": "7.0.0", + "@fastify/cors": "^8.0.0", "@fastify/formbody": "7.0.1", "@fastify/middie": "8.0.0", "@fastify/multipart": "6.0.0", diff --git a/packages/testing/testing-module.ts b/packages/testing/testing-module.ts index e107acc52bc..ec632c4535c 100644 --- a/packages/testing/testing-module.ts +++ b/packages/testing/testing-module.ts @@ -29,20 +29,43 @@ export class TestingModule extends NestApplicationContext { super(container, scope, contextModule); } + private isHttpServer( + serverOrOptions: + | HttpServer + | AbstractHttpAdapter + | NestApplicationOptions + | undefined, + ): serverOrOptions is HttpServer | AbstractHttpAdapter { + return !!(serverOrOptions && (serverOrOptions as HttpServer).patch); + } + + public createNestApplication( + httpAdapter: HttpServer | AbstractHttpAdapter, + options?: NestApplicationOptions, + ): T; public createNestApplication( - httpAdapter?: HttpServer | AbstractHttpAdapter, + options?: NestApplicationOptions, + ): T; + public createNestApplication( + serverOrOptions: + | HttpServer + | AbstractHttpAdapter + | NestApplicationOptions + | undefined, options?: NestApplicationOptions, ): T { - httpAdapter = httpAdapter || this.createHttpAdapter(); + const [httpAdapter, appOptions] = this.isHttpServer(serverOrOptions) + ? [serverOrOptions, options] + : [this.createHttpAdapter(), serverOrOptions]; - this.applyLogger(options); + this.applyLogger(appOptions); this.container.setHttpAdapter(httpAdapter); const instance = new NestApplication( this.container, httpAdapter, this.applicationConfig, - options, + appOptions, ); return this.createAdapterProxy(instance, httpAdapter); }