Skip to content

Commit a9204cb

Browse files
bugfix(@nestjs/testing) await scan() operation
1 parent bd3b102 commit a9204cb

6 files changed

Lines changed: 20 additions & 21 deletions

File tree

integration/hello-world/e2e/fastify-adapter.spec.ts

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,12 @@
1-
import { expect } from 'chai';
2-
import * as fastify from 'fastify';
3-
import * as request from 'supertest';
4-
import * as express from 'express';
5-
import { Test } from '@nestjs/testing';
61
import { INestApplication } from '@nestjs/common';
7-
import { ApplicationModule } from './../src/app.module';
8-
import { FastifyAdapter } from '@nestjs/core/adapters/fastify-adapter';
9-
import { ExpressAdapter } from '@nestjs/core/adapters/express-adapter';
10-
import { HelloService } from '../src/hello/hello.service';
112
import { INestFastifyApplication } from '@nestjs/common/interfaces/nest-fastify-application.interface';
3+
import { FastifyAdapter } from '@nestjs/core/adapters/fastify-adapter';
4+
import { Test } from '@nestjs/testing';
5+
import { expect } from 'chai';
6+
import { ApplicationModule } from './../src/app.module';
127

138
describe('Hello world (fastify adapter)', () => {
14-
let server;
15-
let app: INestApplication & INestFastifyApplication
9+
let app: INestApplication & INestFastifyApplication;
1610

1711
beforeEach(async () => {
1812
const module = await Test.createTestingModule({

packages/common/http/http.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,6 @@ export class HttpService {
5252
}
5353

5454
get axiosRef() {
55-
return axios;
55+
return axios as any;
5656
}
5757
}

packages/testing/testing-module.builder.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ export class TestingModuleBuilder {
2525
this.applicationConfig,
2626
);
2727
this.module = this.createModule(metadata);
28-
this.scanner.scan(this.module);
2928
}
3029

3130
public overridePipe(typeOrToken): OverrideBy {
@@ -58,6 +57,7 @@ export class TestingModuleBuilder {
5857

5958
public async compile(): Promise<TestingModule> {
6059
this.applyLogger();
60+
await this.scanner.scan(this.module);
6161

6262
[...this.overloadsMap.entries()].map(([component, options]) => {
6363
this.container.replace(component, options);

packages/websockets/adapters/io-adapter.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,11 @@ export class IoAdapter implements WebSocketAdapter {
4848
handlers.forEach(({ message, callback }) =>
4949
fromEvent(client, message)
5050
.pipe(
51-
mergeMap(data => transform(callback(data))),
52-
filter(result => result && result.event),
51+
mergeMap(data =>
52+
transform(callback(data)).pipe(
53+
filter((result: any) => result && result.event),
54+
),
55+
),
5356
)
5457
.subscribe(({ event, data }) => client.emit(event, data)),
5558
);

packages/websockets/adapters/ws-adapter.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,11 @@ export class WsAdapter implements WebSocketAdapter {
5353
) {
5454
fromEvent(client, 'message')
5555
.pipe(
56-
mergeMap(data => this.bindMessageHandler(data, handlers, transform)),
57-
filter(result => result),
56+
mergeMap(data =>
57+
this.bindMessageHandler(data, handlers, transform).pipe(
58+
filter(result => result),
59+
),
60+
),
5861
)
5962
.subscribe(response => client.send(JSON.stringify(response)));
6063
}
@@ -71,8 +74,7 @@ export class WsAdapter implements WebSocketAdapter {
7174
);
7275
const { callback } = messageHandler;
7376
return transform(callback(message.data));
74-
}
75-
catch {
77+
} catch {
7678
return empty;
7779
}
7880
}

packages/websockets/web-sockets-controller.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { NestContainer } from '@nestjs/core/injector/container';
55
import { MetadataScanner } from '@nestjs/core/metadata-scanner';
66
import 'reflect-metadata';
77
import { from as fromPromise, Observable, of, Subject } from 'rxjs';
8-
import { distinctUntilChanged, mergeMap } from 'rxjs/operators';
8+
import { distinctUntilChanged, mergeAll } from 'rxjs/operators';
99
import { GATEWAY_OPTIONS, PORT_METADATA } from './constants';
1010
import { WsContextCreator } from './context/ws-context-creator';
1111
import { InvalidSocketPortException } from './exceptions/invalid-socket-port.exception';
@@ -146,7 +146,7 @@ export class WebSocketsController {
146146
callback: callback.bind(instance, client),
147147
}));
148148
adapter.bindMessageHandlers(client, handlers, data =>
149-
fromPromise(this.pickResult(data)).pipe(mergeMap(stream => stream)),
149+
fromPromise(this.pickResult(data)).pipe(mergeAll()),
150150
);
151151
}
152152

0 commit comments

Comments
 (0)