From a7ea36340e56699663dc1fef0cefb72ebd34e194 Mon Sep 17 00:00:00 2001 From: Guillaume Ongenae Date: Thu, 26 Oct 2023 14:51:50 +0200 Subject: [PATCH 1/2] test: replace delay by node setTimeout --- .../test/GooglePubSubClient.test.ts | 4 ++-- .../test/GooglePubSubServer.test.ts | 12 ++++++------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/packages/google-pubsub-client/test/GooglePubSubClient.test.ts b/packages/google-pubsub-client/test/GooglePubSubClient.test.ts index d65fc775..74ebf162 100644 --- a/packages/google-pubsub-client/test/GooglePubSubClient.test.ts +++ b/packages/google-pubsub-client/test/GooglePubSubClient.test.ts @@ -2,7 +2,7 @@ const Emulator = require('google-pubsub-emulator'); import { GCPubSubServer } from '@algoan/nestjs-google-pubsub-microservice'; import { INestApplication, INestMicroservice } from '@nestjs/common'; import { TestingModule } from '@nestjs/testing'; -import * as delay from 'delay'; +import { setTimeout } from 'node:timers/promises'; import * as request from 'supertest'; import { getTestingApplication } from './client-app/main'; import { AppService } from './server-app/app.service'; @@ -64,7 +64,7 @@ describe('GooglePubSubServer', () => { const spy: jest.SpyInstance = jest.spyOn(appService, 'handleTestEvent'); await request(server.getHttpServer()).post('/emit').send({}).expect(201); - await delay(1000); + await setTimeout(1000); expect(spy).toHaveBeenCalledTimes(1); }); diff --git a/packages/google-pubsub-microservice/test/GooglePubSubServer.test.ts b/packages/google-pubsub-microservice/test/GooglePubSubServer.test.ts index 133c7008..17fa6aa2 100644 --- a/packages/google-pubsub-microservice/test/GooglePubSubServer.test.ts +++ b/packages/google-pubsub-microservice/test/GooglePubSubServer.test.ts @@ -1,4 +1,4 @@ -import * as delay from 'delay'; +import { setTimeout } from 'node:timers/promises'; import { GCPubSubServer } from '../src'; import { @@ -48,7 +48,7 @@ describe('GooglePubSubServer', () => { */ await app.listen(); - await delay(1000); + await setTimeout(1000); expect(server.gcClient.subscriptions.get(SUBSCRIPTION_NAME)).toBeDefined(); expect(await server.gcClient.client.subscription(SUBSCRIPTION_NAME).exists()).toEqual([true]); @@ -77,7 +77,7 @@ describe('GooglePubSubServer', () => { * After launching the application, ensure that all subscriptions have been created */ await app.listen(); - await delay(1000); + await setTimeout(1000); expect(server.gcClient.subscriptions.get(subscriptionName)).toBeDefined(); expect(await server.gcClient.client.subscription(subscriptionName).exists()).toEqual([true]); @@ -101,14 +101,14 @@ describe('GooglePubSubServer', () => { await server.gcClient.emit(SUBSCRIPTION_NAME, { hello: 'world', }); - await delay(100); + await setTimeout(100); expect(spy).toHaveBeenCalledTimes(1); await app.close(); await server.gcClient.emit(SUBSCRIPTION_NAME, { hello: 'world', }); - await delay(100); + await setTimeout(100); expect(spy).toHaveBeenCalledTimes(1); }); @@ -158,7 +158,7 @@ describe('GooglePubSubServer', () => { await server.gcClient.emit(TOPIC_NAME, { hello: 'world', }); - await delay(2000); + await setTimeout(2000); /** * Since we have two listeners on the same topic, the spy must be called twice From b870655dbc4a39673b2dbb98f4097513f34d09a5 Mon Sep 17 00:00:00 2001 From: Guillaume Ongenae Date: Thu, 26 Oct 2023 14:52:12 +0200 Subject: [PATCH 2/2] chore(deps-dev): remove delay --- package-lock.json | 19 ------------------- package.json | 1 - 2 files changed, 20 deletions(-) diff --git a/package-lock.json b/package-lock.json index 129019b1..60bb93d3 100644 --- a/package-lock.json +++ b/package-lock.json @@ -43,7 +43,6 @@ "class-validator": "^0.14.0", "commitizen": "^4.3.0", "cz-conventional-changelog": "^3.3.0", - "delay": "^5.0.0", "express": "^4.18.2", "google-pubsub-emulator": "^5.0.0", "husky": "^8.0.3", @@ -6163,18 +6162,6 @@ "node": ">=8" } }, - "node_modules/delay": { - "version": "5.0.0", - "resolved": "https://registry.npmjs.org/delay/-/delay-5.0.0.tgz", - "integrity": "sha512-ReEBKkIfe4ya47wlPYf/gu5ib6yUG0/Aez0JQZQz94kiWtRQvZIQbTiehsnwHvLSWJnQdhVeqYue7Id1dKr0qw==", - "dev": true, - "engines": { - "node": ">=10" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, "node_modules/delayed-stream": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz", @@ -21115,12 +21102,6 @@ "integrity": "sha512-Ds09qNh8yw3khSjiJjiUInaGX9xlqZDY7JVryGxdxV7NPeuqQfplOpQ66yJFZut3jLa5zOwkXw1g9EI2uKh4Og==", "dev": true }, - "delay": { - "version": "5.0.0", - "resolved": "https://registry.npmjs.org/delay/-/delay-5.0.0.tgz", - "integrity": "sha512-ReEBKkIfe4ya47wlPYf/gu5ib6yUG0/Aez0JQZQz94kiWtRQvZIQbTiehsnwHvLSWJnQdhVeqYue7Id1dKr0qw==", - "dev": true - }, "delayed-stream": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz", diff --git a/package.json b/package.json index 8d378bfd..95146c8c 100644 --- a/package.json +++ b/package.json @@ -60,7 +60,6 @@ "class-validator": "^0.14.0", "commitizen": "^4.3.0", "cz-conventional-changelog": "^3.3.0", - "delay": "^5.0.0", "express": "^4.18.2", "google-pubsub-emulator": "^5.0.0", "husky": "^8.0.3",