Skip to content

Commit

Permalink
feat!: update libraries to support Nest 8 (#342)
Browse files Browse the repository at this point in the history
- Upgrade NestJS dependencies
- Refactored code to work with new rxjs 6 dependency
- The RabbitMQ integration project now shares the same @nestjs/* packages and has fewer dependencies
- Small cleanup and improvements around the code/JSDoc

BREAKING CHANGE: Nest dependencies have been bumped from 6.x -> 8.x and we will no longer be supporting versions older than 8.x for future development

Co-authored-by: Christophe BLIN <cblin@monkeyfactory.fr>
Co-authored-by: danocmx <glencocomaster@centrum.cz>
Co-authored-by: Rodrigo <monstawoodwow@gmail.com>
Co-authored-by: Jesse Carter <jesse.r.carter@gmail.com>
  • Loading branch information
5 people committed Jan 23, 2022
1 parent ef9c36f commit de7cd35
Show file tree
Hide file tree
Showing 41 changed files with 7,206 additions and 7,576 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module.exports = {
parser: '@typescript-eslint/parser',
extends: [
'plugin:@typescript-eslint/recommended',
'prettier/@typescript-eslint',
'prettier',
'plugin:sonarjs/recommended',
// 'plugin:prettier/recommended'
],
Expand Down
29 changes: 0 additions & 29 deletions .github/labeler.yml

This file was deleted.

13 changes: 0 additions & 13 deletions .github/workflows/labeler.yml

This file was deleted.

4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ npm-debug.log
packages/*/lib
.idea
coverage/
junit.xml
tsconfig.build.tsbuildinfo
tsconfig.build.tsbuildinfo
yarn-error.log
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ A collection of Badass modules and utilities to help you level up your NestJS ap
<p align="center">
</p>


| Package | Description | Version | Changelog |
| ----------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------- |
| [`@golevelup/nestjs-common`](./packages/common) | Common types, mixins | [![version](https://img.shields.io/npm/v/@golevelup/nestjs-common.svg)](https://www.npmjs.com/package/@golevelup/nestjs-common) | [changelog](./packages/common/CHANGELOG.md) |
Expand Down
64 changes: 0 additions & 64 deletions azure-pipelines.managed.yml

This file was deleted.

59 changes: 0 additions & 59 deletions azure-pipelines.yml

This file was deleted.

8 changes: 5 additions & 3 deletions integration/rabbitmq/e2e/configuration.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ import { RabbitMQConfig, RabbitMQModule } from '@golevelup/nestjs-rabbitmq';
import { Test, TestingModule } from '@nestjs/testing';
import * as amqplib from 'amqplib';

const rabbitHost = process.env.NODE_ENV === 'ci' ? process.env.RABBITMQ_HOST : 'localhost';
const rabbitPort = process.env.NODE_ENV === 'ci' ? process.env.RABBITMQ_PORT : '5672';
const rabbitHost =
process.env.NODE_ENV === 'ci' ? process.env.RABBITMQ_HOST : 'localhost';
const rabbitPort =
process.env.NODE_ENV === 'ci' ? process.env.RABBITMQ_PORT : '5672';
const uri = `amqp://rabbitmq:rabbitmq@${rabbitHost}:${rabbitPort}`;
const amqplibUri = `${uri}?heartbeat=5`;

Expand All @@ -22,7 +24,7 @@ describe('Module Configuration', () => {

afterEach(async () => {
jest.clearAllMocks();
await app.close();
await app?.close();
});

describe('forRoot', () => {
Expand Down
19 changes: 9 additions & 10 deletions integration/rabbitmq/e2e/execution-context.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class SubscribeService {
queue,
})
handleSubscribe(message: object) {
// tslint:disable-next-line:no-console
console.log(`RECEIVED MESSAGE: ${message}`);
}
}
Expand All @@ -42,8 +43,10 @@ describe('Rabbit Subscribe Without Register Handlers', () => {
let app: INestApplication;
let amqpConnection: AmqpConnection;

const rabbitHost = process.env.NODE_ENV === 'ci' ? process.env.RABBITMQ_HOST : 'localhost';
const rabbitPort = process.env.NODE_ENV === 'ci' ? process.env.RABBITMQ_PORT : '5672';
const rabbitHost =
process.env.NODE_ENV === 'ci' ? process.env.RABBITMQ_HOST : 'localhost';
const rabbitPort =
process.env.NODE_ENV === 'ci' ? process.env.RABBITMQ_PORT : '5672';
const uri = `amqp://rabbitmq:rabbitmq@${rabbitHost}:${rabbitPort}`;

beforeAll(async () => {
Expand All @@ -70,16 +73,12 @@ describe('Rabbit Subscribe Without Register Handlers', () => {
});

afterAll(async () => {
await app.close();
await app?.close();
});

it('should recognize a rabbit handler execution context and allow for interceptors to be skipped', async (done) => {
it('should recognize a rabbit handler execution context and allow for interceptors to be skipped', async () => {
await amqpConnection.publish(exchange, 'x', `test-message`);
expect.assertions(1);

setTimeout(() => {
expect(interceptorHandler).not.toHaveBeenCalled();
done();
}, 100);
await new Promise((resolve) => setTimeout(resolve, 100));
expect(interceptorHandler).not.toHaveBeenCalled();
});
});
10 changes: 6 additions & 4 deletions integration/rabbitmq/e2e/nack-and-requeue.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
import { INestApplication, Injectable } from '@nestjs/common';
import { Test } from '@nestjs/testing';

const sleep = ms => new Promise(resolve => setTimeout(resolve, ms));
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));

const exchange = 'testSubscribeExhange';
const nackRoutingKey = 'nackRoutingKey';
Expand Down Expand Up @@ -50,8 +50,10 @@ describe('Nack and Requeue', () => {
let app: INestApplication;
let amqpConnection: AmqpConnection;

const rabbitHost = process.env.NODE_ENV === 'ci' ? process.env.RABBITMQ_HOST : 'localhost';
const rabbitPort = process.env.NODE_ENV === 'ci' ? process.env.RABBITMQ_PORT : '5672';
const rabbitHost =
process.env.NODE_ENV === 'ci' ? process.env.RABBITMQ_HOST : 'localhost';
const rabbitPort =
process.env.NODE_ENV === 'ci' ? process.env.RABBITMQ_PORT : '5672';
const uri = `amqp://rabbitmq:rabbitmq@${rabbitHost}:${rabbitPort}`;

beforeAll(async () => {
Expand Down Expand Up @@ -83,7 +85,7 @@ describe('Nack and Requeue', () => {
});

afterAll(async () => {
await app.close();
await app?.close();
});

it('should nack the message when handler returns a Nack object', async () => {
Expand Down
86 changes: 86 additions & 0 deletions integration/rabbitmq/e2e/rmq-context.e2e-spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import {
AmqpConnection,
RabbitMQModule,
RabbitSubscribe,
} from '@golevelup/nestjs-rabbitmq';
import { CallHandler, ExecutionContext, NestInterceptor } from '@nestjs/common';
import { INestApplication, Injectable } from '@nestjs/common';
import { Test } from '@nestjs/testing';

const validRmqTypeHandler = jest.fn();

const exchange = 'contextExchange';
const queue = 'contextQueue';

@Injectable()
class TestInterceptor implements NestInterceptor {
intercept(context: ExecutionContext, next: CallHandler<any>) {
if ((context.getType() as string) !== 'rmq') {
return next.handle();
}

validRmqTypeHandler('invoked');
return next.handle();
}
}

@Injectable()
class SubscribeService {
@RabbitSubscribe({
exchange,
routingKey: '#',
queue,
})
handleSubscribe(message: object) {
// tslint:disable-next-line:no-console
console.log(`RECEIVED MESSAGE: ${message}`);
}
}

describe('RMQ Context in Global interceptor', () => {
let app: INestApplication;
let amqpConnection: AmqpConnection;

const rabbitHost =
process.env.NODE_ENV === 'ci' ? process.env.RABBITMQ_HOST : 'localhost';
const rabbitPort =
process.env.NODE_ENV === 'ci' ? process.env.RABBITMQ_PORT : '5672';
const uri = `amqp://rabbitmq:rabbitmq@${rabbitHost}:${rabbitPort}`;

beforeAll(async () => {
const moduleFixture = await Test.createTestingModule({
providers: [SubscribeService, TestInterceptor],
imports: [
RabbitMQModule.forRoot(RabbitMQModule, {
exchanges: [
{
name: exchange,
type: 'topic',
},
],
uri,
connectionInitOptions: { wait: true, reject: true, timeout: 3000 },
}),
],
}).compile();

app = moduleFixture.createNestApplication();
amqpConnection = app.get<AmqpConnection>(AmqpConnection);
app.useGlobalInterceptors(new TestInterceptor());
await app.init();
});

afterAll(async () => {
await app.close();
});

it('should recognize as rmq context type and not the default (HTTP)', (done) => {
amqpConnection.publish(exchange, 'x', `test-message`);
expect.assertions(1);

setTimeout(() => {
expect(validRmqTypeHandler).toHaveBeenCalled();
done();
}, 100);
});
});
Loading

0 comments on commit de7cd35

Please sign in to comment.