Skip to content

Commit 42e1e79

Browse files
test(): fix e2e tests
1 parent a3fbb88 commit 42e1e79

16 files changed

Lines changed: 65 additions & 50 deletions

integration/hello-world/e2e/express-instance.spec.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1+
import { INestApplication } from '@nestjs/common';
2+
import { ExpressAdapter } from '@nestjs/platform-express';
3+
import { Test } from '@nestjs/testing';
14
import * as express from 'express';
25
import * as request from 'supertest';
3-
import { Test } from '@nestjs/testing';
4-
import { INestApplication } from '@nestjs/common';
56
import { ApplicationModule } from '../src/app.module';
67

78
describe('Hello world (express instance)', () => {
@@ -11,10 +12,9 @@ describe('Hello world (express instance)', () => {
1112
beforeEach(async () => {
1213
const module = await Test.createTestingModule({
1314
imports: [ApplicationModule],
14-
})
15-
.compile();
15+
}).compile();
1616

17-
app = module.createNestApplication(express());
17+
app = module.createNestApplication(new ExpressAdapter(express()));
1818
server = app.getHttpServer();
1919
await app.init();
2020
});

integration/hello-world/e2e/fastify-adapter.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { INestApplication } from '@nestjs/common';
22
import { INestFastifyApplication } from '@nestjs/common/interfaces/nest-fastify-application.interface';
3-
import { FastifyAdapter } from '@nestjs/core/adapters/fastify-adapter';
3+
import { FastifyAdapter } from '@nestjs/platform-fastify';
44
import { Test } from '@nestjs/testing';
55
import { expect } from 'chai';
66
import { ApplicationModule } from '../src/app.module';

integration/hello-world/src/errors/errors.controller.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Get, BadRequestException, Controller } from '@nestjs/common';
1+
import { BadRequestException, Controller, Get } from '@nestjs/common';
22

33
@Controller()
44
export class ErrorsController {
@@ -13,6 +13,10 @@ export class ErrorsController {
1313
}
1414

1515
throwError() {
16-
throw new BadRequestException('Integration test');
16+
throw new BadRequestException({
17+
statusCode: 400,
18+
error: 'Bad Request',
19+
message: 'Integration test',
20+
});
1721
}
1822
}

integration/microservices/e2e/broadcast-mqtt.spec.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
import * as express from 'express';
2-
import * as request from 'supertest';
3-
import { Test } from '@nestjs/testing';
41
import { INestApplication } from '@nestjs/common';
52
import { Transport } from '@nestjs/microservices';
3+
import { Test } from '@nestjs/testing';
4+
import * as request from 'supertest';
65
import { MqttBroadcastController } from '../src/mqtt/mqtt-broadcast.controller';
76

87
describe('MQTT transport', () => {
@@ -14,8 +13,9 @@ describe('MQTT transport', () => {
1413
controllers: [MqttBroadcastController],
1514
}).compile();
1615

17-
server = express();
18-
app = module.createNestApplication(server);
16+
app = module.createNestApplication();
17+
server = app.getHttpAdapter().getInstance();
18+
1919
app.connectMicroservice({
2020
transport: Transport.MQTT,
2121
});

integration/microservices/e2e/broadcast-nats.spec.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
import * as express from 'express';
2-
import * as request from 'supertest';
3-
import { Test } from '@nestjs/testing';
41
import { INestApplication } from '@nestjs/common';
52
import { Transport } from '@nestjs/microservices';
3+
import { Test } from '@nestjs/testing';
4+
import * as request from 'supertest';
65
import { NatsBroadcastController } from '../src/nats/nats-broadcast.controller';
76

87
describe('NATS transport', () => {
@@ -14,8 +13,9 @@ describe('NATS transport', () => {
1413
controllers: [NatsBroadcastController],
1514
}).compile();
1615

17-
server = express();
18-
app = module.createNestApplication(server);
16+
app = module.createNestApplication();
17+
server = app.getHttpAdapter().getInstance();
18+
1919
app.connectMicroservice({
2020
transport: Transport.NATS,
2121
});

integration/microservices/e2e/broadcast-redis.spec.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
import * as express from 'express';
2-
import * as request from 'supertest';
3-
import { Test } from '@nestjs/testing';
41
import { INestApplication } from '@nestjs/common';
52
import { Transport } from '@nestjs/microservices';
6-
import { RedisController } from '../src/redis/redis.controller';
3+
import { Test } from '@nestjs/testing';
4+
import * as request from 'supertest';
75
import { RedisBroadcastController } from '../src/redis/redis-broadcast.controller';
86

97
describe('REDIS transport', () => {
@@ -15,8 +13,9 @@ describe('REDIS transport', () => {
1513
controllers: [RedisBroadcastController],
1614
}).compile();
1715

18-
server = express();
19-
app = module.createNestApplication(server);
16+
app = module.createNestApplication();
17+
server = app.getHttpAdapter().getInstance();
18+
2019
app.connectMicroservice({
2120
transport: Transport.REDIS,
2221
});

integration/microservices/e2e/disconnected-client.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { INestApplication } from '@nestjs/common';
22
import { Transport } from '@nestjs/microservices';
33
import { Test } from '@nestjs/testing';
4-
import * as express from 'express';
54
import * as request from 'supertest';
65
import { DisconnectedClientController } from '../src/disconnected.controller';
76

@@ -14,8 +13,9 @@ describe('Disconnected client', () => {
1413
controllers: [DisconnectedClientController],
1514
}).compile();
1615

17-
server = express();
18-
app = module.createNestApplication(server);
16+
app = module.createNestApplication();
17+
server = app.getHttpAdapter().getInstance();
18+
1919
await app.init();
2020
});
2121

integration/microservices/e2e/sum-grpc.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { INestApplication } from '@nestjs/common';
22
import { Transport } from '@nestjs/microservices';
33
import { Test } from '@nestjs/testing';
4-
import * as express from 'express';
54
import { join } from 'path';
65
import * as request from 'supertest';
76
import { GrpcController } from '../src/grpc/grpc.controller';
@@ -15,8 +14,9 @@ describe('GRPC transport', () => {
1514
controllers: [GrpcController],
1615
}).compile();
1716

18-
server = express();
19-
app = module.createNestApplication(server);
17+
app = module.createNestApplication();
18+
server = app.getHttpAdapter().getInstance();
19+
2020
app.connectMicroservice({
2121
transport: Transport.GRPC,
2222
options: {

integration/microservices/e2e/sum-mqtt.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { INestApplication } from '@nestjs/common';
22
import { Transport } from '@nestjs/microservices';
33
import { Test } from '@nestjs/testing';
4-
import * as express from 'express';
54
import * as request from 'supertest';
65
import { MqttController } from '../src/mqtt/mqtt.controller';
76

@@ -14,8 +13,9 @@ describe('MQTT transport', () => {
1413
controllers: [MqttController],
1514
}).compile();
1615

17-
server = express();
18-
app = module.createNestApplication(server);
16+
app = module.createNestApplication();
17+
server = app.getHttpAdapter().getInstance();
18+
1919
app.connectMicroservice({
2020
transport: Transport.MQTT,
2121
});

integration/microservices/e2e/sum-nats.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { INestApplication } from '@nestjs/common';
22
import { Transport } from '@nestjs/microservices';
33
import { Test } from '@nestjs/testing';
4-
import * as express from 'express';
54
import * as request from 'supertest';
65
import { NatsController } from '../src/nats/nats.controller';
76

@@ -14,8 +13,9 @@ describe('NATS transport', () => {
1413
controllers: [NatsController],
1514
}).compile();
1615

17-
server = express();
18-
app = module.createNestApplication(server);
16+
app = module.createNestApplication();
17+
server = app.getHttpAdapter().getInstance();
18+
1919
app.connectMicroservice({
2020
transport: Transport.NATS,
2121
options: {

0 commit comments

Comments
 (0)