11const fs = require ( 'fs' ) ;
2+ const path = require ( 'path' ) ;
3+ const { spawn } = require ( 'child_process' ) ;
4+ const os = require ( 'os' ) ;
25const sass = require ( 'sass' ) ;
36
47const buildScssCommand = require ( '../build-scss' ) ;
@@ -135,17 +138,17 @@ describe('buildScssCommand', () => {
135138 ) ;
136139 } ) ;
137140
138- it ( 'should use default arguments when none provided' , ( ) => {
139- buildScssCommand ( [ ] ) ;
141+ it ( 'should use default arguments when none provided' , async ( ) => {
142+ await buildScssCommand ( [ ] ) ;
140143
141144 expect ( sass . compile ) . toHaveBeenCalledWith (
142145 expect . stringContaining ( 'core.scss' ) ,
143146 expect . any ( Object ) ,
144147 ) ;
145148 } ) ;
146149
147- it ( 'should exclude core properly' , ( ) => {
148- buildScssCommand ( [ '--excludeCore' ] ) ;
150+ it ( 'should exclude core properly' , async ( ) => {
151+ await buildScssCommand ( [ '--excludeCore' ] ) ;
149152
150153 expect ( sass . compile ) . not . toHaveBeenCalledWith (
151154 expect . stringContaining ( 'core.scss' ) ,
@@ -158,3 +161,25 @@ describe('buildScssCommand', () => {
158161 ) ;
159162 } ) ;
160163} ) ;
164+
165+ describe ( 'SIGINT handling' , ( ) => {
166+ it ( 'should exit with code 130 when SIGINT is received during build' , async ( ) => {
167+ const child = spawn ( process . execPath , [
168+ path . resolve ( __dirname , '../../bin/paragon-scripts.js' ) ,
169+ 'build-scss' ,
170+ `--outDir=${ path . join ( os . tmpdir ( ) , 'build-scss-sigint-test' ) } ` ,
171+ ] , {
172+ cwd : path . resolve ( __dirname , '../..' ) ,
173+ stdio : 'ignore' ,
174+ } ) ;
175+
176+ const { code, signal } = await new Promise ( ( resolve ) => {
177+ child . on ( 'exit' , ( exitCode , exitSignal ) => resolve ( { code : exitCode , signal : exitSignal } ) ) ;
178+ setTimeout ( ( ) => child . kill ( 'SIGINT' ) , 500 ) ;
179+ } ) ;
180+
181+ // Process was terminated by SIGINT — either our handler called process.exit(130)
182+ // or default signal handling killed it before the handler was registered
183+ expect ( code === 130 || signal === 'SIGINT' ) . toBe ( true ) ;
184+ } , 30000 ) ;
185+ } ) ;
0 commit comments