Skip to content

Commit

Permalink
Merge pull request #785 from g-ongenae/fixture/replace-delay-by-setti…
Browse files Browse the repository at this point in the history
…meout

[DEPS] Replace delay by node setTimeout
  • Loading branch information
g-ongenae authored Oct 26, 2023
2 parents 9779144 + b870655 commit 778c670
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 28 deletions.
19 changes: 0 additions & 19 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions packages/google-pubsub-client/test/GooglePubSubClient.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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);
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as delay from 'delay';
import { setTimeout } from 'node:timers/promises';

import { GCPubSubServer } from '../src';
import {
Expand Down Expand Up @@ -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]);

Expand Down Expand Up @@ -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]);
Expand All @@ -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);
});

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 778c670

Please sign in to comment.