Skip to content

Commit

Permalink
Merge branch 'master' into fix-ws-multi-servers-on-different-paths
Browse files Browse the repository at this point in the history
  • Loading branch information
kamilmysliwiec authored Apr 5, 2023
2 parents 081650b + aa2717b commit e46147e
Show file tree
Hide file tree
Showing 195 changed files with 48,084 additions and 45,040 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,6 @@ yarn-error.log
/packages/graphql
/benchmarks/memory
build/config\.gypi

.npmrc
pnpm-lock.yaml
35 changes: 35 additions & 0 deletions integration/cache/e2e/custom-ttl.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { INestApplication } from '@nestjs/common';
import { Test } from '@nestjs/testing';
import * as request from 'supertest';
import { CustomTtlModule } from '../src/custom-ttl/custom-ttl.module';

describe('Caching Custom TTL', () => {
let server;
let app: INestApplication;

beforeEach(async () => {
const module = await Test.createTestingModule({
imports: [CustomTtlModule],
}).compile();

app = module.createNestApplication();
server = app.getHttpServer();
await app.init();
});

it('should return a differnt value after the TTL is elapsed', async () => {
await request(server).get('/').expect(200, '0');
await new Promise(resolve => setTimeout(resolve, 500));
await request(server).get('/').expect(200, '1');
});

it('should return the cached value within the TTL', async () => {
await request(server).get('/').expect(200, '0');
await new Promise(resolve => setTimeout(resolve, 200));
await request(server).get('/').expect(200, '0');
});

afterEach(async () => {
await app.close();
});
});
20 changes: 20 additions & 0 deletions integration/cache/src/custom-ttl/custom-ttl.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import {
CacheInterceptor,
CacheTTL,
Controller,
Get,
UseInterceptors,
} from '@nestjs/common';

@Controller()
export class CustomTtlController {
counter = 0;
constructor() {}

@Get()
@CacheTTL(500)
@UseInterceptors(CacheInterceptor)
getNumber() {
return this.counter++;
}
}
8 changes: 8 additions & 0 deletions integration/cache/src/custom-ttl/custom-ttl.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { CacheModule, Module } from '@nestjs/common';
import { CustomTtlController } from './custom-ttl.controller';

@Module({
imports: [CacheModule.register()],
controllers: [CustomTtlController],
})
export class CustomTtlModule {}
40 changes: 40 additions & 0 deletions integration/cache/src/custom-ttl/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"compilerOptions": {
"module": "commonjs",
"declaration": false,
"noImplicitAny": false,
"removeComments": true,
"noLib": false,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"target": "es6",
"sourceMap": true,
"allowJs": true,
"outDir": "./dist",
"paths": {
"@nestjs/common": ["../../packages/common"],
"@nestjs/common/*": ["../../packages/common/*"],
"@nestjs/core": ["../../packages/core"],
"@nestjs/core/*": ["../../packages/core/*"],
"@nestjs/microservices": ["../../packages/microservices"],
"@nestjs/microservices/*": ["../../packages/microservices/*"],
"@nestjs/websockets": ["../../packages/websockets"],
"@nestjs/websockets/*": ["../../packages/websockets/*"],
"@nestjs/testing": ["../../packages/testing"],
"@nestjs/testing/*": ["../../packages/testing/*"],
"@nestjs/platform-express": ["../../packages/platform-express"],
"@nestjs/platform-express/*": ["../../packages/platform-express/*"],
"@nestjs/platform-socket.io": ["../../packages/platform-socket.io"],
"@nestjs/platform-socket.io/*": ["../../packages/platform-socket.io/*"],
"@nestjs/platform-ws": ["../../packages/platform-ws"],
"@nestjs/platform-ws/*": ["../../packages/platform-ws/*"]
}
},
"include": [
"src/**/*",
"e2e/**/*"
],
"exclude": [
"node_modules",
]
}
6 changes: 3 additions & 3 deletions integration/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ services:
- "9001:9001"
restart: always
mysql:
image: mysql:8.0.30
image: mysql:8.0.32
environment:
MYSQL_ROOT_PASSWORD: root
MYSQL_DATABASE: test
Expand All @@ -50,7 +50,7 @@ services:
zookeeper:
container_name: test-zookeeper
hostname: zookeeper
image: confluentinc/cp-zookeeper:7.0.1
image: confluentinc/cp-zookeeper:7.3.2
ports:
- "2181:2181"
environment:
Expand All @@ -59,7 +59,7 @@ services:
kafka:
container_name: test-kafka
hostname: kafka
image: confluentinc/cp-kafka:7.0.1
image: confluentinc/cp-kafka:7.3.2
depends_on:
- zookeeper
ports:
Expand Down
11 changes: 9 additions & 2 deletions integration/graphql-code-first/e2e/pipes.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,23 @@ describe('GraphQL Pipes', () => {
errors: [
{
extensions: {
code: 'BAD_USER_INPUT',
response: {
code: 'BAD_REQUEST',
originalError: {
error: 'Bad Request',
message: [
'description must be longer than or equal to 30 characters',
],
statusCode: 400,
},
},
locations: [
{
column: 3,
line: 2,
},
],
message: 'Bad Request Exception',
path: ['addRecipe'],
},
],
});
Expand Down
2 changes: 1 addition & 1 deletion integration/graphql-code-first/schema.gql
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ input NewRecipeInput {

type Subscription {
recipeAdded: Recipe!
}
}
2 changes: 1 addition & 1 deletion integration/graphql-code-first/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { RecipesModule } from './recipes/recipes.module';
RecipesModule,
GraphQLModule.forRoot<ApolloDriverConfig>({
driver: ApolloDriver,
debug: false,
includeStacktraceInErrorResponses: false,
installSubscriptionHandlers: true,
autoSchemaFile: join(
process.cwd(),
Expand Down
4 changes: 2 additions & 2 deletions integration/graphql-code-first/src/main.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { ValidationPipe } from '@nestjs/common';
import { NestFactory } from '@nestjs/core';
import { ApplicationModule } from './app.module';
import { AppModule } from './app.module';

async function bootstrap() {
const app = await NestFactory.create(ApplicationModule);
const app = await NestFactory.create(AppModule);
app.useGlobalPipes(new ValidationPipe());
await app.listen(3000);
}
Expand Down
1 change: 1 addition & 0 deletions integration/graphql-schema-first/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { CatsModule } from './cats/cats.module';
CatsModule,
GraphQLModule.forRoot<ApolloDriverConfig>({
driver: ApolloDriver,
includeStacktraceInErrorResponses: true,
typePaths: [join(__dirname, '**', '*.graphql')],
}),
],
Expand Down
4 changes: 2 additions & 2 deletions integration/graphql-schema-first/src/main.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { NestFactory } from '@nestjs/core';
import { ApplicationModule } from './app.module';
import { AppModule } from './app.module';

async function bootstrap() {
const app = await NestFactory.create(ApplicationModule);
const app = await NestFactory.create(AppModule);
await app.listen(3000);
}
bootstrap();
3 changes: 2 additions & 1 deletion integration/inspector/e2e/fixtures/post-init-graph.json
Original file line number Diff line number Diff line change
Expand Up @@ -3166,5 +3166,6 @@
"nodeId": "-2007711503"
}
]
}
},
"status": "complete"
}
3 changes: 2 additions & 1 deletion integration/inspector/e2e/fixtures/pre-init-graph.json
Original file line number Diff line number Diff line change
Expand Up @@ -2624,5 +2624,6 @@
"nodeId": "-2007711503"
}
]
}
},
"status": "complete"
}
7 changes: 5 additions & 2 deletions integration/inspector/e2e/graph-inspector.spec.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions integration/microservices/e2e/broadcast-mqtt.spec.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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',
Expand Down
6 changes: 3 additions & 3 deletions integration/microservices/e2e/broadcast-nats.spec.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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',
Expand Down
12 changes: 7 additions & 5 deletions integration/microservices/e2e/broadcast-redis.spec.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions integration/microservices/e2e/concurrent-kafka.spec.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -37,7 +37,7 @@ describe.skip('Kafka concurrent', function () {

const server = app.getHttpAdapter().getInstance();

app.connectMicroservice({
app.connectMicroservice<MicroserviceOptions>({
transport: Transport.KAFKA,
options: {
client: {
Expand Down
4 changes: 2 additions & 2 deletions integration/microservices/e2e/mqtt-record-builder.spec.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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',
Expand Down
4 changes: 2 additions & 2 deletions integration/microservices/e2e/orders-grpc.spec.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -26,7 +26,7 @@ describe('Advanced GRPC transport', () => {
/*
* Create microservice configuration
*/
app.connectMicroservice({
app.connectMicroservice<MicroserviceOptions>({
transport: Transport.GRPC,
options: {
url: 'localhost:5001',
Expand Down
4 changes: 2 additions & 2 deletions integration/microservices/e2e/sum-grpc.spec.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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'],
Expand Down
Loading

0 comments on commit e46147e

Please sign in to comment.