Skip to content

Commit

Permalink
Merge pull request #1416 from BrunnerLivio/refactor/lifecycle-hooks
Browse files Browse the repository at this point in the history
refactor(core) extract lifecycle hooks
  • Loading branch information
kamilmysliwiec authored Jan 30, 2019
2 parents e4179eb + c735dc6 commit ad6dd43
Show file tree
Hide file tree
Showing 21 changed files with 595 additions and 202 deletions.
21 changes: 21 additions & 0 deletions integration/hooks/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# dependencies
/node_modules

# IDE
/.idea
/.awcache
/.vscode

# misc
npm-debug.log

# example
/quick-start

# tests
/test
/coverage
/.nyc_output

# dist
/dist
22 changes: 22 additions & 0 deletions integration/hooks/e2e/on-app-boostrap.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { Test } from '@nestjs/testing';
import { expect } from 'chai';
import * as Sinon from 'sinon';
import { Injectable, OnApplicationBootstrap } from '@nestjs/common';

@Injectable()
class TestInjectable implements OnApplicationBootstrap {
onApplicationBootstrap = Sinon.spy();
}

describe('OnApplicationBootstrap', () => {
it('should call onApplicationBootstrap when application starts', async () => {
const module = await Test.createTestingModule({
providers: [TestInjectable],
}).compile();

const app = module.createNestApplication();
await app.init();
const instance = module.get(TestInjectable);
expect(instance.onApplicationBootstrap.called).to.be.true;
});
});
23 changes: 23 additions & 0 deletions integration/hooks/e2e/on-app-shutdown.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { Test } from '@nestjs/testing';
import { expect } from 'chai';
import * as Sinon from 'sinon';
import { Injectable, OnApplicationShutdown } from '@nestjs/common';
import { spawn } from 'child_process';

@Injectable()
class TestInjectable implements OnApplicationShutdown {
onApplicationShutdown = Sinon.spy();
}

describe('OnApplicationShutdown', () => {
it('should call onApplicationShutdown when application closes', async () => {
const module = await Test.createTestingModule({
providers: [TestInjectable],
}).compile();

const app = module.createNestApplication();
await app.close();
const instance = module.get(TestInjectable);
expect(instance.onApplicationShutdown.called).to.be.true;
});
});
22 changes: 22 additions & 0 deletions integration/hooks/e2e/on-module-destroy.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { Test } from '@nestjs/testing';
import { expect } from 'chai';
import * as Sinon from 'sinon';
import { Injectable, OnModuleDestroy } from '@nestjs/common';

@Injectable()
class TestInjectable implements OnModuleDestroy {
onModuleDestroy = Sinon.spy();
}

describe('OnModuleDestroy', () => {
it('should call onModuleDestroy when application closes', async () => {
const module = await Test.createTestingModule({
providers: [TestInjectable],
}).compile();

const app = module.createNestApplication();
await app.close();
const instance = module.get(TestInjectable);
expect(instance.onModuleDestroy.called).to.be.true;
});
});
22 changes: 22 additions & 0 deletions integration/hooks/e2e/on-module-init.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { Test } from '@nestjs/testing';
import { expect } from 'chai';
import * as Sinon from 'sinon';
import { Injectable, OnModuleInit } from '@nestjs/common';

@Injectable()
class TestInjectable implements OnModuleInit {
onModuleInit = Sinon.spy();
}

describe('OnModuleInit', () => {
it('should call onModuleInit when application starts', async () => {
const module = await Test.createTestingModule({
providers: [TestInjectable],
}).compile();

const app = module.createNestApplication();
await app.init();
const instance = module.get(TestInjectable);
expect(instance.onModuleInit.called).to.be.true;
});
});
23 changes: 23 additions & 0 deletions integration/hooks/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"name": "nest-typescript-starter",
"version": "1.0.0",
"description": "Nest TypeScript starter repository",
"license": "MIT",
"scripts": {
"start": "ts-node src/main"
},
"dependencies": {
"@nestjs/common": "^5.0.0",
"@nestjs/core": "^5.0.0",
"class-transformer": "^0.1.7",
"class-validator": "^0.7.2",
"reflect-metadata": "^0.1.12",
"rxjs": "^6.0.0",
"typescript": "^3.1.0"
},
"devDependencies": {
"@types/node": "^7.0.41",
"supertest": "^3.0.0",
"ts-node": "^6.0.0"
}
}
22 changes: 22 additions & 0 deletions integration/hooks/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"compilerOptions": {
"module": "commonjs",
"declaration": false,
"noImplicitAny": false,
"removeComments": true,
"noLib": false,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"target": "es6",
"sourceMap": true,
"allowJs": true,
"outDir": "./dist"
},
"include": [
"src/**/*",
"e2e/**/*"
],
"exclude": [
"node_modules",
]
}
53 changes: 53 additions & 0 deletions integration/hooks/tslint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
{
"defaultSeverity": "error",
"extends": [
"tslint:recommended"
],
"jsRules": {
"no-unused-expression": true
},
"rules": {
"eofline": false,
"quotemark": [
true,
"single"
],
"ordered-imports": [
false
],
"max-line-length": [
150
],
"member-ordering": [
false
],
"curly": false,
"interface-name": [
false
],
"array-type": [
false
],
"member-access": [
false
],
"no-empty-interface": false,
"no-empty": false,
"arrow-parens": false,
"object-literal-sort-keys": false,
"no-unused-expression": false,
"max-classes-per-file": [
false
],
"variable-name": [
false
],
"one-line": [
false
],
"one-variable-per-declaration": [
false
]
},
"rulesDirectory": []
}
Loading

0 comments on commit ad6dd43

Please sign in to comment.