Skip to content

Commit

Permalink
bugfix(@nestjs/testing) await scan() operation
Browse files Browse the repository at this point in the history
  • Loading branch information
kamilmysliwiec committed Jul 4, 2018
1 parent bd3b102 commit a9204cb
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 21 deletions.
16 changes: 5 additions & 11 deletions integration/hello-world/e2e/fastify-adapter.spec.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,12 @@
import { expect } from 'chai';
import * as fastify from 'fastify';
import * as request from 'supertest';
import * as express from 'express';
import { Test } from '@nestjs/testing';
import { INestApplication } from '@nestjs/common';
import { ApplicationModule } from './../src/app.module';
import { FastifyAdapter } from '@nestjs/core/adapters/fastify-adapter';
import { ExpressAdapter } from '@nestjs/core/adapters/express-adapter';
import { HelloService } from '../src/hello/hello.service';
import { INestFastifyApplication } from '@nestjs/common/interfaces/nest-fastify-application.interface';
import { FastifyAdapter } from '@nestjs/core/adapters/fastify-adapter';
import { Test } from '@nestjs/testing';
import { expect } from 'chai';
import { ApplicationModule } from './../src/app.module';

describe('Hello world (fastify adapter)', () => {
let server;
let app: INestApplication & INestFastifyApplication
let app: INestApplication & INestFastifyApplication;

beforeEach(async () => {
const module = await Test.createTestingModule({
Expand Down
2 changes: 1 addition & 1 deletion packages/common/http/http.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,6 @@ export class HttpService {
}

get axiosRef() {
return axios;
return axios as any;
}
}
2 changes: 1 addition & 1 deletion packages/testing/testing-module.builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ export class TestingModuleBuilder {
this.applicationConfig,
);
this.module = this.createModule(metadata);
this.scanner.scan(this.module);
}

public overridePipe(typeOrToken): OverrideBy {
Expand Down Expand Up @@ -58,6 +57,7 @@ export class TestingModuleBuilder {

public async compile(): Promise<TestingModule> {
this.applyLogger();
await this.scanner.scan(this.module);

[...this.overloadsMap.entries()].map(([component, options]) => {
this.container.replace(component, options);
Expand Down
7 changes: 5 additions & 2 deletions packages/websockets/adapters/io-adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,11 @@ export class IoAdapter implements WebSocketAdapter {
handlers.forEach(({ message, callback }) =>
fromEvent(client, message)
.pipe(
mergeMap(data => transform(callback(data))),
filter(result => result && result.event),
mergeMap(data =>
transform(callback(data)).pipe(
filter((result: any) => result && result.event),
),
),
)
.subscribe(({ event, data }) => client.emit(event, data)),
);
Expand Down
10 changes: 6 additions & 4 deletions packages/websockets/adapters/ws-adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,11 @@ export class WsAdapter implements WebSocketAdapter {
) {
fromEvent(client, 'message')
.pipe(
mergeMap(data => this.bindMessageHandler(data, handlers, transform)),
filter(result => result),
mergeMap(data =>
this.bindMessageHandler(data, handlers, transform).pipe(
filter(result => result),
),
),
)
.subscribe(response => client.send(JSON.stringify(response)));
}
Expand All @@ -71,8 +74,7 @@ export class WsAdapter implements WebSocketAdapter {
);
const { callback } = messageHandler;
return transform(callback(message.data));
}
catch {
} catch {
return empty;
}
}
Expand Down
4 changes: 2 additions & 2 deletions packages/websockets/web-sockets-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { NestContainer } from '@nestjs/core/injector/container';
import { MetadataScanner } from '@nestjs/core/metadata-scanner';
import 'reflect-metadata';
import { from as fromPromise, Observable, of, Subject } from 'rxjs';
import { distinctUntilChanged, mergeMap } from 'rxjs/operators';
import { distinctUntilChanged, mergeAll } from 'rxjs/operators';
import { GATEWAY_OPTIONS, PORT_METADATA } from './constants';
import { WsContextCreator } from './context/ws-context-creator';
import { InvalidSocketPortException } from './exceptions/invalid-socket-port.exception';
Expand Down Expand Up @@ -146,7 +146,7 @@ export class WebSocketsController {
callback: callback.bind(instance, client),
}));
adapter.bindMessageHandlers(client, handlers, data =>
fromPromise(this.pickResult(data)).pipe(mergeMap(stream => stream)),
fromPromise(this.pickResult(data)).pipe(mergeAll()),
);
}

Expand Down

0 comments on commit a9204cb

Please sign in to comment.