mirror of
https://github.com/nestjs/nest.git
synced 2026-02-21 23:11:44 +00:00
test: add microservice generic type explicitly
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import { ValidationPipe } from '@nestjs/common';
|
||||
import { Injector } from '@nestjs/core/injector/injector';
|
||||
import { SerializedGraph } from '@nestjs/core/inspector/serialized-graph';
|
||||
import { Transport } from '@nestjs/microservices';
|
||||
import { MicroserviceOptions, Transport } from '@nestjs/microservices';
|
||||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
import { expect } from 'chai';
|
||||
import { readFileSync, writeFileSync } from 'fs';
|
||||
@@ -45,7 +45,10 @@ describe('Graph inspector', () => {
|
||||
app.useGlobalFilters(new HttpExceptionFilter());
|
||||
app.useGlobalInterceptors(new TimeoutInterceptor());
|
||||
app.enableVersioning();
|
||||
app.connectMicroservice({ transport: Transport.TCP, options: {} });
|
||||
app.connectMicroservice<MicroserviceOptions>({
|
||||
transport: Transport.TCP,
|
||||
options: {},
|
||||
});
|
||||
await app.init();
|
||||
|
||||
const graph = testingModule.get(SerializedGraph);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { INestApplication } from '@nestjs/common';
|
||||
import { Transport } from '@nestjs/microservices';
|
||||
import { MicroserviceOptions, Transport } from '@nestjs/microservices';
|
||||
import { Test } from '@nestjs/testing';
|
||||
import * as request from 'supertest';
|
||||
import { MqttBroadcastController } from '../src/mqtt/mqtt-broadcast.controller';
|
||||
@@ -16,13 +16,13 @@ describe('MQTT transport', () => {
|
||||
app = module.createNestApplication();
|
||||
server = app.getHttpAdapter().getInstance();
|
||||
|
||||
app.connectMicroservice({
|
||||
app.connectMicroservice<MicroserviceOptions>({
|
||||
transport: Transport.MQTT,
|
||||
options: {
|
||||
host: '0.0.0.0',
|
||||
},
|
||||
});
|
||||
app.connectMicroservice({
|
||||
app.connectMicroservice<MicroserviceOptions>({
|
||||
transport: Transport.MQTT,
|
||||
options: {
|
||||
host: '0.0.0.0',
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { INestApplication } from '@nestjs/common';
|
||||
import { Transport } from '@nestjs/microservices';
|
||||
import { MicroserviceOptions, Transport } from '@nestjs/microservices';
|
||||
import { Test } from '@nestjs/testing';
|
||||
import * as request from 'supertest';
|
||||
import { NatsBroadcastController } from '../src/nats/nats-broadcast.controller';
|
||||
@@ -16,13 +16,13 @@ describe('NATS transport', () => {
|
||||
app = module.createNestApplication();
|
||||
server = app.getHttpAdapter().getInstance();
|
||||
|
||||
app.connectMicroservice({
|
||||
app.connectMicroservice<MicroserviceOptions>({
|
||||
transport: Transport.NATS,
|
||||
options: {
|
||||
servers: 'nats://0.0.0.0:4222',
|
||||
},
|
||||
});
|
||||
app.connectMicroservice({
|
||||
app.connectMicroservice<MicroserviceOptions>({
|
||||
transport: Transport.NATS,
|
||||
options: {
|
||||
servers: 'servers://0.0.0.0:4222',
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { INestApplication } from '@nestjs/common';
|
||||
import { Transport } from '@nestjs/microservices';
|
||||
import { MicroserviceOptions, Transport } from '@nestjs/microservices';
|
||||
import { Test } from '@nestjs/testing';
|
||||
import * as request from 'supertest';
|
||||
import { RedisBroadcastController } from '../src/redis/redis-broadcast.controller';
|
||||
@@ -16,16 +16,18 @@ describe('REDIS transport', () => {
|
||||
app = module.createNestApplication();
|
||||
server = app.getHttpAdapter().getInstance();
|
||||
|
||||
app.connectMicroservice({
|
||||
app.connectMicroservice<MicroserviceOptions>({
|
||||
transport: Transport.REDIS,
|
||||
options: {
|
||||
url: 'redis://0.0.0.0:6379',
|
||||
host: '0.0.0.0',
|
||||
port: 6379,
|
||||
},
|
||||
});
|
||||
app.connectMicroservice({
|
||||
app.connectMicroservice<MicroserviceOptions>({
|
||||
transport: Transport.REDIS,
|
||||
options: {
|
||||
url: 'redis://0.0.0.0:6379',
|
||||
host: '0.0.0.0',
|
||||
port: 6379,
|
||||
},
|
||||
});
|
||||
await app.startAllMicroservices();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { INestApplication, Logger } from '@nestjs/common';
|
||||
import { Transport } from '@nestjs/microservices';
|
||||
import { MicroserviceOptions, Transport } from '@nestjs/microservices';
|
||||
import { Test } from '@nestjs/testing';
|
||||
import { Admin, ITopicMetadata, Kafka } from 'kafkajs';
|
||||
import * as request from 'supertest';
|
||||
@@ -37,7 +37,7 @@ describe.skip('Kafka concurrent', function () {
|
||||
|
||||
const server = app.getHttpAdapter().getInstance();
|
||||
|
||||
app.connectMicroservice({
|
||||
app.connectMicroservice<MicroserviceOptions>({
|
||||
transport: Transport.KAFKA,
|
||||
options: {
|
||||
client: {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { INestApplication } from '@nestjs/common';
|
||||
import { Transport } from '@nestjs/microservices';
|
||||
import { MicroserviceOptions, Transport } from '@nestjs/microservices';
|
||||
import { Test } from '@nestjs/testing';
|
||||
import * as request from 'supertest';
|
||||
import { MqttController } from '../src/mqtt/mqtt.controller';
|
||||
@@ -16,7 +16,7 @@ describe('MQTT transport', () => {
|
||||
app = module.createNestApplication();
|
||||
server = app.getHttpAdapter().getInstance();
|
||||
|
||||
app.connectMicroservice({
|
||||
app.connectMicroservice<MicroserviceOptions>({
|
||||
transport: Transport.MQTT,
|
||||
options: {
|
||||
url: 'mqtt://0.0.0.0:1883',
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import * as GRPC from '@grpc/grpc-js';
|
||||
import * as ProtoLoader from '@grpc/proto-loader';
|
||||
import { INestApplication } from '@nestjs/common';
|
||||
import { Transport } from '@nestjs/microservices';
|
||||
import { MicroserviceOptions, Transport } from '@nestjs/microservices';
|
||||
import { ExpressAdapter } from '@nestjs/platform-express';
|
||||
import { Test } from '@nestjs/testing';
|
||||
import { fail } from 'assert';
|
||||
@@ -26,7 +26,7 @@ describe('Advanced GRPC transport', () => {
|
||||
/*
|
||||
* Create microservice configuration
|
||||
*/
|
||||
app.connectMicroservice({
|
||||
app.connectMicroservice<MicroserviceOptions>({
|
||||
transport: Transport.GRPC,
|
||||
options: {
|
||||
url: 'localhost:5001',
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import * as GRPC from '@grpc/grpc-js';
|
||||
import * as ProtoLoader from '@grpc/proto-loader';
|
||||
import { INestApplication } from '@nestjs/common';
|
||||
import { Transport } from '@nestjs/microservices';
|
||||
import { MicroserviceOptions, Transport } from '@nestjs/microservices';
|
||||
import { Test } from '@nestjs/testing';
|
||||
import { fail } from 'assert';
|
||||
import { expect } from 'chai';
|
||||
@@ -22,7 +22,7 @@ describe('GRPC transport', () => {
|
||||
app = module.createNestApplication();
|
||||
server = app.getHttpAdapter().getInstance();
|
||||
|
||||
app.connectMicroservice({
|
||||
app.connectMicroservice<MicroserviceOptions>({
|
||||
transport: Transport.GRPC,
|
||||
options: {
|
||||
package: ['math', 'math2'],
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { INestApplication } from '@nestjs/common';
|
||||
import { Transport } from '@nestjs/microservices';
|
||||
import { MicroserviceOptions, Transport } from '@nestjs/microservices';
|
||||
import { Test } from '@nestjs/testing';
|
||||
import { expect } from 'chai';
|
||||
import * as request from 'supertest';
|
||||
@@ -29,7 +29,7 @@ describe.skip('Kafka transport', function () {
|
||||
app = module.createNestApplication();
|
||||
server = app.getHttpAdapter().getInstance();
|
||||
|
||||
app.connectMicroservice({
|
||||
app.connectMicroservice<MicroserviceOptions>({
|
||||
transport: Transport.KAFKA,
|
||||
options: {
|
||||
client: {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { INestApplication } from '@nestjs/common';
|
||||
import { Transport } from '@nestjs/microservices';
|
||||
import { MicroserviceOptions, Transport } from '@nestjs/microservices';
|
||||
import { Test } from '@nestjs/testing';
|
||||
import { expect } from 'chai';
|
||||
import * as request from 'supertest';
|
||||
@@ -17,7 +17,7 @@ describe('MQTT transport', () => {
|
||||
app = module.createNestApplication();
|
||||
server = app.getHttpAdapter().getInstance();
|
||||
|
||||
app.connectMicroservice({
|
||||
app.connectMicroservice<MicroserviceOptions>({
|
||||
transport: Transport.MQTT,
|
||||
options: {
|
||||
url: 'mqtt://0.0.0.0:1883',
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { INestApplication } from '@nestjs/common';
|
||||
import { Transport } from '@nestjs/microservices';
|
||||
import { MicroserviceOptions, Transport } from '@nestjs/microservices';
|
||||
import { Test } from '@nestjs/testing';
|
||||
import { expect } from 'chai';
|
||||
import * as request from 'supertest';
|
||||
@@ -19,7 +19,7 @@ describe('NATS transport', () => {
|
||||
app = module.createNestApplication();
|
||||
server = app.getHttpAdapter().getInstance();
|
||||
|
||||
app.connectMicroservice({
|
||||
app.connectMicroservice<MicroserviceOptions>({
|
||||
transport: Transport.NATS,
|
||||
options: {
|
||||
servers: 'nats://0.0.0.0:4222',
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { INestApplication } from '@nestjs/common';
|
||||
import { Transport } from '@nestjs/microservices';
|
||||
import { MicroserviceOptions, Transport } from '@nestjs/microservices';
|
||||
import { Test } from '@nestjs/testing';
|
||||
import { expect } from 'chai';
|
||||
import * as request from 'supertest';
|
||||
@@ -17,10 +17,11 @@ describe('REDIS transport', () => {
|
||||
app = module.createNestApplication();
|
||||
server = app.getHttpAdapter().getInstance();
|
||||
|
||||
app.connectMicroservice({
|
||||
app.connectMicroservice<MicroserviceOptions>({
|
||||
transport: Transport.REDIS,
|
||||
options: {
|
||||
url: 'redis://0.0.0.0:6379',
|
||||
host: '0.0.0.0',
|
||||
port: 6379,
|
||||
},
|
||||
});
|
||||
await app.startAllMicroservices();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { INestApplication } from '@nestjs/common';
|
||||
import { Transport } from '@nestjs/microservices';
|
||||
import { MicroserviceOptions, Transport } from '@nestjs/microservices';
|
||||
import { Test } from '@nestjs/testing';
|
||||
import { expect } from 'chai';
|
||||
import * as request from 'supertest';
|
||||
@@ -17,7 +17,7 @@ describe('RabbitMQ transport', () => {
|
||||
app = module.createNestApplication();
|
||||
server = app.getHttpAdapter().getInstance();
|
||||
|
||||
app.connectMicroservice({
|
||||
app.connectMicroservice<MicroserviceOptions>({
|
||||
transport: Transport.RMQ,
|
||||
options: {
|
||||
urls: [`amqp://0.0.0.0:5672`],
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { INestApplication } from '@nestjs/common';
|
||||
import { Transport } from '@nestjs/microservices';
|
||||
import { MicroserviceOptions, Transport } from '@nestjs/microservices';
|
||||
import { Test } from '@nestjs/testing';
|
||||
import { expect } from 'chai';
|
||||
import * as request from 'supertest';
|
||||
@@ -18,7 +18,7 @@ describe('RPC transport', () => {
|
||||
app = module.createNestApplication();
|
||||
server = app.getHttpAdapter().getInstance();
|
||||
|
||||
app.connectMicroservice({
|
||||
app.connectMicroservice<MicroserviceOptions>({
|
||||
transport: Transport.TCP,
|
||||
options: {
|
||||
host: '0.0.0.0',
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { INestApplication } from '@nestjs/common';
|
||||
import { Transport } from '@nestjs/microservices';
|
||||
import { MicroserviceOptions, Transport } from '@nestjs/microservices';
|
||||
import { Test } from '@nestjs/testing';
|
||||
import { expect } from 'chai';
|
||||
import * as request from 'supertest';
|
||||
@@ -31,7 +31,7 @@ describe('Request scope (microservices)', () => {
|
||||
}).compile();
|
||||
|
||||
app = module.createNestApplication();
|
||||
app.connectMicroservice({ transport: Transport.TCP });
|
||||
app.connectMicroservice<MicroserviceOptions>({ transport: Transport.TCP });
|
||||
|
||||
server = app.getHttpServer();
|
||||
await app.init();
|
||||
|
||||
@@ -6,6 +6,7 @@ import { GraphInspector } from '../inspector/graph-inspector';
|
||||
import { NestApplication } from '../nest-application';
|
||||
import { mapToExcludeRoute } from './../middleware/utils';
|
||||
import { NoopHttpAdapter } from './utils/noop-adapter.spec';
|
||||
import { MicroserviceOptions } from '@nestjs/microservices';
|
||||
|
||||
describe('NestApplication', () => {
|
||||
describe('Hybrid Application', () => {
|
||||
@@ -25,7 +26,9 @@ describe('NestApplication', () => {
|
||||
{},
|
||||
);
|
||||
instance.useGlobalInterceptors(new Interceptor());
|
||||
const microservice = instance.connectMicroservice({});
|
||||
const microservice = instance.connectMicroservice<MicroserviceOptions>(
|
||||
{},
|
||||
);
|
||||
expect((instance as any).config.getGlobalInterceptors().length).to.equal(
|
||||
1,
|
||||
);
|
||||
@@ -44,7 +47,7 @@ describe('NestApplication', () => {
|
||||
{},
|
||||
);
|
||||
instance.useGlobalInterceptors(new Interceptor());
|
||||
const microservice = instance.connectMicroservice(
|
||||
const microservice = instance.connectMicroservice<MicroserviceOptions>(
|
||||
{},
|
||||
{ inheritAppConfig: true },
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user