-
-
Notifications
You must be signed in to change notification settings - Fork 7.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1416 from BrunnerLivio/refactor/lifecycle-hooks
refactor(core) extract lifecycle hooks
- Loading branch information
Showing
21 changed files
with
595 additions
and
202 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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", | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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": [] | ||
} |
Oops, something went wrong.