@@ -352,6 +352,7 @@ fs.readFileSync = (file, ...rest) => {
352352 "#!/t3-test-missing-loader\n" ,
353353 '#!/bin/sh\necho "runtime loader failed" >&2\nexit 42\n' ,
354354 "#!/bin/sh\nkill -TERM $$\n" ,
355+ '#!/bin/sh\ntrap \'echo caught > "$T3CODE_TEST_TERM"; exit 42\' TERM\necho ready > "$T3CODE_TEST_READY"\nwhile :; do :; done\n' ,
355356 ] ) {
356357 const root = yield * fs . makeTempDirectoryScoped ( { prefix : "t3-npm-validation-test-" } ) ;
357358 const output = yield * buildNpmLauncher ( {
@@ -361,19 +362,40 @@ fs.readFileSync = (file, ...rest) => {
361362 const release = yield * serveFakeRelease ( root , executable ) ;
362363 const home = path . join ( root , "home" ) ;
363364 const dir = path . join ( home , "runtime/versions" , VERSION ) ;
365+ const probeTimeoutHook = path . join ( root , "probe-timeout.mjs" ) ;
366+ yield * fs . writeFileString (
367+ probeTimeoutHook ,
368+ `import childProcess from "node:child_process";
369+ import { syncBuiltinESMExports } from "node:module";
370+ const { spawnSync } = childProcess;
371+ childProcess.spawnSync = (command, args, options) => spawnSync(command, args,
372+ options?.timeout === undefined ? options : { ...options, timeout: 500 });
373+ syncBuiltinESMExports();
374+ ` ,
375+ ) ;
364376 const env = {
365377 PATH : process . env . PATH ,
366378 T3CODE_HOME : home ,
367379 T3CODE_RELEASE_BASE_URL : release . baseUrl ,
380+ T3CODE_TEST_READY : path . join ( root , "probe-ready" ) ,
381+ T3CODE_TEST_TERM : path . join ( root , "probe-term" ) ,
368382 } ;
369383 const launcher = path . join ( output . packageDir , "bin/t3.mjs" ) ;
370- const failed = yield * run ( process . execPath , [ launcher , "serve" ] , { cwd : root , env } ) ;
384+ const failed = yield * run (
385+ process . execPath ,
386+ [ "--import" , probeTimeoutHook , launcher , "serve" ] ,
387+ { cwd : root , env } ,
388+ ) ;
371389 assert . equal ( failed . exitCode , 1 , failed . stderr ) ;
372390 assert . deepStrictEqual ( yield * fs . readDirectory ( path . dirname ( dir ) ) , [ ] , failed . stderr ) ;
373391 assert . include ( failed . stderr , "could not run" ) ;
374- if ( executable . includes ( "exit 42 " ) ) {
392+ if ( executable . includes ( "runtime loader failed " ) ) {
375393 assert . include ( failed . stderr , "runtime loader failed" ) ;
376394 }
395+ if ( executable . includes ( "trap" ) ) {
396+ assert . isTrue ( yield * fs . exists ( env . T3CODE_TEST_READY ) ) ;
397+ assert . isFalse ( yield * fs . exists ( env . T3CODE_TEST_TERM ) ) ;
398+ }
377399 if ( ( yield * HostProcess . Platform ) === "linux" ) {
378400 assert . include ( failed . stderr , "glibc" ) ;
379401 assert . include ( failed . stderr , "musl" ) ;
0 commit comments