@@ -20,7 +20,7 @@ class TestStart extends (Start as any) {
2020 return '/fake/framework' ;
2121 }
2222 async getServerBin ( ) {
23- return ' /fake/scripts/start-cluster.cjs';
23+ return ` /fake/scripts/start-cluster.${ this . isESM ? 'mjs' : ' cjs'} ` ;
2424 }
2525}
2626
@@ -69,6 +69,34 @@ describe('test/start-unit.test.ts', () => {
6969 expect ( options . env . NODE_ENV ) . toBe ( 'production' ) ;
7070 } ) ;
7171
72+ it ( 'preloads source-map-support with a file URL for ESM apps' , async ( ) => {
73+ const esmBaseDir = path . join ( homeDir , 'esm-typescript-app' ) ;
74+ await fs . mkdir ( esmBaseDir ) ;
75+ await fs . writeFile (
76+ path . join ( esmBaseDir , 'package.json' ) ,
77+ JSON . stringify ( { name : 'esm-typescript-app' , type : 'module' , egg : { typescript : true } } ) ,
78+ ) ;
79+ spawnMock . mockImplementation ( ( ) => ( {
80+ once : vi . fn ( ) . mockReturnThis ( ) ,
81+ on : vi . fn ( ) . mockReturnThis ( ) ,
82+ unref : vi . fn ( ) ,
83+ disconnect : vi . fn ( ) ,
84+ kill : vi . fn ( ) ,
85+ pid : 1112 ,
86+ } ) ) ;
87+
88+ await TestStart . run ( [ '--workers=1' , esmBaseDir ] ) ;
89+
90+ expect ( spawnMock ) . toHaveBeenCalledTimes ( 1 ) ;
91+ const [ , args ] = spawnMock . mock . calls [ 0 ] as [ string , string [ ] ] ;
92+ expect ( args ) . toContain ( '/fake/scripts/start-cluster.mjs' ) ;
93+ const importIndex = args . indexOf ( '--import' ) ;
94+ expect ( importIndex ) . toBeGreaterThan ( - 1 ) ;
95+ // A Windows drive path such as D:\app\register.js is parsed as the
96+ // unsupported `d:` URL scheme by Node's ESM loader unless it is a file URL.
97+ expect ( args [ importIndex + 1 ] ) . toMatch ( / ^ f i l e : / ) ;
98+ } ) ;
99+
72100 it ( 'daemon mode backgrounds once the child reports egg-ready over IPC' , async ( ) => {
73101 const unref = vi . fn ( ) ;
74102 const disconnect = vi . fn ( ) ;
0 commit comments