@@ -3,11 +3,38 @@ import { spawnSync } from 'child_process';
33import { join } from 'path' ;
44
55describe ( 'enableShutdownHooks' , ( ) => {
6+ const workspaceRoot = join ( __dirname , '../../..' ) ;
7+ const localPackageResolver = join (
8+ workspaceRoot ,
9+ 'integration/_support/register-local-packages.ts' ,
10+ ) ;
11+ const entrypoint = join ( __dirname , '../src/enable-shutdown-hooks-main.ts' ) ;
12+
13+ const runScript = ( ...args : string [ ] ) =>
14+ spawnSync (
15+ process . execPath ,
16+ [
17+ '-r' ,
18+ 'ts-node/register/transpile-only' ,
19+ '-r' ,
20+ localPackageResolver ,
21+ entrypoint ,
22+ ...args ,
23+ ] ,
24+ {
25+ cwd : workspaceRoot ,
26+ env : {
27+ ...process . env ,
28+ TS_NODE_PROJECT : join (
29+ workspaceRoot ,
30+ 'integration/hooks/tsconfig.json' ,
31+ ) ,
32+ } ,
33+ } ,
34+ ) ;
35+
636 it ( 'should call the correct hooks if any shutdown signal gets invoked' , done => {
7- const result = spawnSync ( 'ts-node' , [
8- join ( __dirname , '../src/enable-shutdown-hooks-main.ts' ) ,
9- 'SIGHUP' ,
10- ] ) ;
37+ const result = runScript ( 'SIGHUP' ) ;
1138 const calls = result . stdout
1239 . toString ( )
1340 . split ( '\n' )
@@ -18,11 +45,7 @@ describe('enableShutdownHooks', () => {
1845 } ) . timeout ( 10000 ) ;
1946
2047 it ( 'should call the correct hooks if a specific shutdown signal gets invoked' , done => {
21- const result = spawnSync ( 'ts-node' , [
22- join ( __dirname , '../src/enable-shutdown-hooks-main.ts' ) ,
23- 'SIGINT' ,
24- 'SIGINT' ,
25- ] ) ;
48+ const result = runScript ( 'SIGINT' , 'SIGINT' ) ;
2649 const calls = result . stdout
2750 . toString ( )
2851 . split ( '\n' )
@@ -33,32 +56,19 @@ describe('enableShutdownHooks', () => {
3356 } ) . timeout ( 10000 ) ;
3457
3558 it ( 'should ignore system signals which are not specified' , done => {
36- const result = spawnSync ( 'ts-node' , [
37- join ( __dirname , '../src/enable-shutdown-hooks-main.ts' ) ,
38- 'SIGINT' ,
39- 'SIGHUP' ,
40- ] ) ;
59+ const result = runScript ( 'SIGINT' , 'SIGHUP' ) ;
4160 expect ( result . stdout . toString ( ) . trim ( ) ) . to . be . eq ( '' ) ;
4261 done ( ) ;
4362 } ) . timeout ( 10000 ) ;
4463
4564 it ( 'should ignore system signals if "enableShutdownHooks" was not called' , done => {
46- const result = spawnSync ( 'ts-node' , [
47- join ( __dirname , '../src/enable-shutdown-hooks-main.ts' ) ,
48- 'SIGINT' ,
49- 'NONE' ,
50- ] ) ;
65+ const result = runScript ( 'SIGINT' , 'NONE' ) ;
5166 expect ( result . stdout . toString ( ) . trim ( ) ) . to . be . eq ( '' ) ;
5267 done ( ) ;
5368 } ) . timeout ( 10000 ) ;
5469
5570 it ( 'should call the correct hooks with useProcessExit option' , done => {
56- const result = spawnSync ( 'ts-node' , [
57- join ( __dirname , '../src/enable-shutdown-hooks-main.ts' ) ,
58- 'SIGHUP' ,
59- 'SIGHUP' ,
60- 'graceful' ,
61- ] ) ;
71+ const result = runScript ( 'SIGHUP' , 'SIGHUP' , 'graceful' ) ;
6272 const calls = result . stdout
6373 . toString ( )
6474 . split ( '\n' )
0 commit comments