@@ -54,6 +54,7 @@ describe('CLI dev command', () => {
5454 let signalHandlers : Record < string , Array < ( ...args : unknown [ ] ) => void > >
5555
5656 beforeEach ( ( ) => {
57+ _spawnCalled = false
5758 tmpDir = mkdtempSync ( join ( os . tmpdir ( ) , 'nuxt-processor-cli-' ) )
5859 // minimal package.json
5960 writeFileSync ( join ( tmpDir , 'package.json' ) , JSON . stringify ( { name : 'app' , version : '0.0.0' , scripts : { } } , null , 2 ) )
@@ -147,10 +148,29 @@ describe('CLI dev command', () => {
147148 expect ( pkg2 . scripts && pkg2 . scripts [ 'processor:dev' ] ) . toBe ( 'nuxt-processor dev' )
148149 } )
149150
151+ it ( 'exits when entry exists but processor:dev script could not be ensured' , async ( ) => {
152+ const entryDir = join ( tmpDir , '.nuxt' , 'dev' , 'workers' )
153+ mkdirSync ( entryDir , { recursive : true } )
154+ writeFileSync ( join ( entryDir , 'index.mjs' ) , 'export {}\n' )
155+ promptAnswer = 'n'
156+ const { main } = await importCli ( )
157+ try {
158+ await main ( { rawArgs : [ 'dev' , tmpDir ] } )
159+ }
160+ catch ( e ) {
161+ expect ( String ( e ) ) . toContain ( 'process.exit(1)' )
162+ }
163+ expect ( _spawnCalled ) . toBe ( false )
164+ } )
165+
150166 it ( 'kills child process on SIGINT signal' , async ( ) => {
151167 const entryDir = join ( tmpDir , '.nuxt' , 'dev' , 'workers' )
152168 mkdirSync ( entryDir , { recursive : true } )
153169 writeFileSync ( join ( entryDir , 'index.mjs' ) , 'export {}\n' )
170+ const pkgPath = join ( tmpDir , 'package.json' )
171+ const pkg = JSON . parse ( readFileSync ( pkgPath , 'utf8' ) ) as { scripts ?: Record < string , string > }
172+ pkg . scripts = { ...( pkg . scripts || { } ) , 'processor:dev' : 'nuxt-processor dev' }
173+ writeFileSync ( pkgPath , JSON . stringify ( pkg , null , 2 ) )
154174
155175 promptAnswer = 'n'
156176 const { main } = await importCli ( )
@@ -175,6 +195,10 @@ describe('CLI dev command', () => {
175195 const entryDir = join ( tmpDir , '.nuxt' , 'dev' , 'workers' )
176196 mkdirSync ( entryDir , { recursive : true } )
177197 writeFileSync ( join ( entryDir , 'index.mjs' ) , 'export {}\n' )
198+ const pkgPath = join ( tmpDir , 'package.json' )
199+ const pkg = JSON . parse ( readFileSync ( pkgPath , 'utf8' ) ) as { scripts ?: Record < string , string > }
200+ pkg . scripts = { ...( pkg . scripts || { } ) , 'processor:dev' : 'nuxt-processor dev' }
201+ writeFileSync ( pkgPath , JSON . stringify ( pkg , null , 2 ) )
178202
179203 promptAnswer = 'n'
180204 const { main } = await importCli ( )
0 commit comments