mirror of
https://github.com/nestjs/nest.git
synced 2026-02-21 23:11:44 +00:00
test(sample-02): added e2e tests
This commit is contained in:
53
sample/02-gateways/e2e/events-gateway/gateway.e2e-spec.ts
Normal file
53
sample/02-gateways/e2e/events-gateway/gateway.e2e-spec.ts
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
import { INestApplication } from '@nestjs/common';
|
||||||
|
import { Test } from '@nestjs/testing';
|
||||||
|
import { AppModule } from '../../src/app.module';
|
||||||
|
import { io, Socket } from 'socket.io-client';
|
||||||
|
|
||||||
|
describe('EventsGateway', () => {
|
||||||
|
let app: INestApplication;
|
||||||
|
let socket: Socket;
|
||||||
|
|
||||||
|
beforeAll(async () => {
|
||||||
|
const moduleRef = await Test.createTestingModule({
|
||||||
|
imports: [AppModule],
|
||||||
|
}).compile();
|
||||||
|
|
||||||
|
app = moduleRef.createNestApplication();
|
||||||
|
await app.listen(3000);
|
||||||
|
});
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
socket = io('http://localhost:3000');
|
||||||
|
socket.connect();
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('findAll', () => {
|
||||||
|
it('should receive 3 numbers', done => {
|
||||||
|
let eventCount = 1;
|
||||||
|
socket.emit('events', { test: 'test' });
|
||||||
|
socket.on('events', data => {
|
||||||
|
expect(data).toBe(eventCount);
|
||||||
|
if (++eventCount > 3) {
|
||||||
|
done();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('identity', () => {
|
||||||
|
it('should return the same number has what was sent', done => {
|
||||||
|
socket.emit('identity', 0, response => {
|
||||||
|
expect(response).toBe(0);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
afterEach(() => {
|
||||||
|
socket.disconnect();
|
||||||
|
});
|
||||||
|
|
||||||
|
afterAll(async () => {
|
||||||
|
await app.close();
|
||||||
|
});
|
||||||
|
});
|
||||||
14
sample/02-gateways/e2e/jest-e2e.json
Normal file
14
sample/02-gateways/e2e/jest-e2e.json
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
{
|
||||||
|
"moduleFileExtensions": [
|
||||||
|
"ts",
|
||||||
|
"tsx",
|
||||||
|
"js",
|
||||||
|
"json"
|
||||||
|
],
|
||||||
|
"transform": {
|
||||||
|
"^.+\\.tsx?$": "ts-jest"
|
||||||
|
},
|
||||||
|
"testRegex": "/e2e/.*\\.(e2e-test|e2e-spec).(ts|tsx|js)$",
|
||||||
|
"collectCoverageFrom" : ["src/**/*.{js,jsx,tsx,ts}", "!**/node_modules/**", "!**/vendor/**"],
|
||||||
|
"coverageReporters": ["json", "lcov"]
|
||||||
|
}
|
||||||
@@ -16,7 +16,7 @@
|
|||||||
"test:watch": "jest --watch",
|
"test:watch": "jest --watch",
|
||||||
"test:cov": "jest --coverage",
|
"test:cov": "jest --coverage",
|
||||||
"test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
|
"test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
|
||||||
"test:e2e": "echo 'No e2e tests implemented yet.'"
|
"test:e2e": "jest --config ./e2e/jest-e2e.json"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@nestjs/common": "9.0.1",
|
"@nestjs/common": "9.0.1",
|
||||||
@@ -37,7 +37,7 @@
|
|||||||
"@nestjs/schematics": "9.0.1",
|
"@nestjs/schematics": "9.0.1",
|
||||||
"@nestjs/testing": "9.0.1",
|
"@nestjs/testing": "9.0.1",
|
||||||
"@types/express": "4.17.13",
|
"@types/express": "4.17.13",
|
||||||
"@types/jest": "^28.1.4",
|
"@types/jest": "28.1.4",
|
||||||
"@types/node": "18.0.3",
|
"@types/node": "18.0.3",
|
||||||
"@types/supertest": "2.0.12",
|
"@types/supertest": "2.0.12",
|
||||||
"@types/ws": "8.5.3",
|
"@types/ws": "8.5.3",
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ describe('EventsGateway', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('findAll', () => {
|
describe('findAll', () => {
|
||||||
it('should return an array of items', done => {
|
it('should return 3 numbers', done => {
|
||||||
gateway
|
gateway
|
||||||
.findAll({})
|
.findAll({})
|
||||||
.pipe(reduce((acc, item) => [...acc, item], []))
|
.pipe(reduce((acc, item) => [...acc, item], []))
|
||||||
|
|||||||
Reference in New Issue
Block a user