Skip to content

Commit

Permalink
Merge pull request #140 from nestjs/fix/issue-119
Browse files Browse the repository at this point in the history
sample(000): Add e2e test for healthmodule
  • Loading branch information
BrunnerLivio authored Apr 22, 2019
2 parents dbc69ad + 019b14b commit 8010190
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 5 deletions.
27 changes: 22 additions & 5 deletions sample/000-dogs-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
"start": "ts-node src/main.ts",
"prestart:prod": "tsc",
"start:prod": "node dist/main.js",
"test": "jest --config=jest.json",
"test:watch": "jest --watch --config=jest.json",
"test:coverage": "jest --config=jest.json --coverage --coverageDirectory=coverage",
"e2e": "jest --config=e2e/jest-e2e.json --forceExit",
"e2e:watch": "jest --watch --config=e2e/jest-e2e.json"
"test": "jest",
"test:watch": "jest --watch",
"test:cov": "jest --coverage",
"test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
"test:e2e": "jest --config ./test/jest-e2e.json"
},
"dependencies": {
"@godaddy/terminus": "4.1.0",
Expand All @@ -35,5 +35,22 @@
"ts-jest": "24.0.2",
"ts-node": "8.1.0",
"tslint": "5.16.0"
},
"jest": {
"moduleFileExtensions": [
"js",
"json",
"ts"
],
"rootDir": "src",
"testRegex": ".spec.ts$",
"transform": {
"^.+\\.(t|j)s$": "ts-jest"
},
"collectCoverageFrom": [
"**/*.(t|j)s"
],
"coverageDirectory": "../coverage",
"testEnvironment": "node"
}
}
29 changes: 29 additions & 0 deletions sample/000-dogs-app/test/health.e2e-spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import * as request from 'supertest';
import { Test } from '@nestjs/testing';
import { HealthModule } from '../src/health/health.module';
import { INestApplication } from '@nestjs/common';

describe('HealthModule (e2e)', () => {
let app: INestApplication;

beforeAll(async () => {
const moduleFixture = await Test.createTestingModule({
imports: [HealthModule],
}).compile();

app = moduleFixture.createNestApplication();
await app.init();
});

it('/health (GET)', () => {
return request(app.getHttpServer())
.get('/health')
.expect(503)
.expect({
status: 'error',
error: {
dog: { status: 'down', badboys: 1 },
},
});
});
});
9 changes: 9 additions & 0 deletions sample/000-dogs-app/test/jest-e2e.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"moduleFileExtensions": ["js", "json", "ts"],
"rootDir": ".",
"testEnvironment": "node",
"testRegex": ".e2e-spec.ts$",
"transform": {
"^.+\\.(t|j)s$": "ts-jest"
}
}

0 comments on commit 8010190

Please sign in to comment.