1+ import { Injectable , OnApplicationShutdown } from '@nestjs/common' ;
12import { Test } from '@nestjs/testing' ;
23import { expect } from 'chai' ;
3- import * as Sinon from 'sinon' ;
4- import { Injectable , OnApplicationShutdown , ShutdownSignal } from '@nestjs/common' ;
5- import { spawn , spawnSync } from 'child_process' ;
4+ import { spawnSync } from 'child_process' ;
65import { join } from 'path' ;
6+ import * as Sinon from 'sinon' ;
77
88@Injectable ( )
99class TestInjectable implements OnApplicationShutdown {
@@ -23,26 +23,41 @@ describe('OnApplicationShutdown', () => {
2323 } ) ;
2424
2525 it ( 'should call onApplicationShutdown if any shutdown signal gets invoked' , done => {
26- const result = spawnSync ( 'ts-node' , [ join ( __dirname , '../src/main.ts' ) , 'SIGHUP' ] ) ;
27- expect ( result . stdout . toString ( ) . trim ( ) ) . to . be . eq ( 'Signal SIGHUP' ) ;
26+ const result = spawnSync ( 'ts-node' , [
27+ join ( __dirname , '../src/main.ts' ) ,
28+ 'SIGHUP' ,
29+ ] ) ;
30+ expect ( result . stdout . toString ( ) . trim ( ) === 'Signal SIGHUP' ) . to . be . true ;
2831 done ( ) ;
29- } ) ;
32+ } ) . timeout ( 5000 ) ;
3033
3134 it ( 'should call onApplicationShutdown if a specific shutdown signal gets invoked' , done => {
32- const result = spawnSync ( 'ts-node' , [ join ( __dirname , '../src/main.ts' ) , 'SIGINT' , 'SIGINT' ] ) ;
35+ const result = spawnSync ( 'ts-node' , [
36+ join ( __dirname , '../src/main.ts' ) ,
37+ 'SIGINT' ,
38+ 'SIGINT' ,
39+ ] ) ;
3340 expect ( result . stdout . toString ( ) . trim ( ) ) . to . be . eq ( 'Signal SIGINT' ) ;
3441 done ( ) ;
35- } ) ;
42+ } ) . timeout ( 5000 ) ;
3643
3744 it ( 'should ignore system signals which are not specified' , done => {
38- const result = spawnSync ( 'ts-node' , [ join ( __dirname , '../src/main.ts' ) , 'SIGINT' , 'SIGHUP' ] ) ;
45+ const result = spawnSync ( 'ts-node' , [
46+ join ( __dirname , '../src/main.ts' ) ,
47+ 'SIGINT' ,
48+ 'SIGHUP' ,
49+ ] ) ;
3950 expect ( result . stdout . toString ( ) . trim ( ) ) . to . be . eq ( '' ) ;
4051 done ( ) ;
41- } ) ;
52+ } ) . timeout ( 5000 ) ;
4253
4354 it ( 'should ignore system signals if "enableShutdownHooks" was not called' , done => {
44- const result = spawnSync ( 'ts-node' , [ join ( __dirname , '../src/main.ts' ) , 'SIGINT' , 'NONE' ] ) ;
55+ const result = spawnSync ( 'ts-node' , [
56+ join ( __dirname , '../src/main.ts' ) ,
57+ 'SIGINT' ,
58+ 'NONE' ,
59+ ] ) ;
4560 expect ( result . stdout . toString ( ) . trim ( ) ) . to . be . eq ( '' ) ;
4661 done ( ) ;
47- } ) ;
62+ } ) . timeout ( 5000 ) ;
4863} ) ;
0 commit comments