77 * file that was distributed with this source code.
88 */
99
10+ import getRandomPort from 'get-port'
1011import { join } from 'node:path/posix'
1112import { cliui } from '@poppinss/cliui'
1213import type Hooks from '@poppinss/hooks'
@@ -65,6 +66,12 @@ export class TestRunner {
6566 */
6667 #stickyPort! : string
6768
69+ /**
70+ * The stickyHmrPort is set by the start and the startAndWatch methods
71+ * and we will continue to use that port during restart
72+ */
73+ #stickyHmrPort! : string
74+
6875 /**
6976 * Reference to chokidar watcher
7077 */
@@ -113,7 +120,7 @@ export class TestRunner {
113120 this . #testsProcess. removeAllListeners ( )
114121 this . #testsProcess. kill ( 'SIGKILL' )
115122 }
116- await this . #runTests( this . #stickyPort, filters )
123+ await this . #runTests( this . #stickyPort, this . #stickyHmrPort , filters )
117124 } , 'reRunTests' )
118125
119126 /**
@@ -242,7 +249,7 @@ export class TestRunner {
242249 * @param port - The port number to set in the environment
243250 * @param filters - Optional test filters to apply for this run
244251 */
245- async #runTests( port : string , filters ?: TestRunnerOptions [ 'filters' ] ) {
252+ async #runTests( port : string , hmrPort : string , filters ?: TestRunnerOptions [ 'filters' ] ) {
246253 /**
247254 * Execute the registered before creating the child process. This will allow
248255 * hooks to modify the options before they are used.
@@ -265,7 +272,7 @@ export class TestRunner {
265272 this . #testsProcess = runNode ( this . cwd , {
266273 script : this . scriptFile ,
267274 reject : true ,
268- env : { PORT : port , ...this . options . env } ,
275+ env : { PORT : port , VITE_HMR_PORT : hmrPort , ...this . options . env } ,
269276 nodeArgs : this . options . nodeArgs ,
270277 scriptArgs,
271278 } )
@@ -400,6 +407,7 @@ export class TestRunner {
400407 */
401408 async run ( ) {
402409 this . #stickyPort = String ( await getPort ( this . cwd ) )
410+ this . #stickyHmrPort = String ( getRandomPort ( { port : 24678 } ) )
403411 this . #indexGenerator = new IndexGenerator ( this . cwdPath , this . ui . logger )
404412
405413 this . #clearScreen( )
@@ -418,7 +426,7 @@ export class TestRunner {
418426 await this . #indexGenerator. generate ( )
419427
420428 this . ui . logger . info ( 'booting application to run tests...' )
421- await this . #runTests( this . #stickyPort)
429+ await this . #runTests( this . #stickyPort, this . #stickyHmrPort )
422430 }
423431
424432 /**
@@ -440,6 +448,7 @@ export class TestRunner {
440448 }
441449
442450 this . #stickyPort = String ( await getPort ( this . cwd ) )
451+ this . #stickyHmrPort = String ( getRandomPort ( { port : 24678 } ) )
443452 this . #indexGenerator = new IndexGenerator ( this . cwdPath , this . ui . logger )
444453
445454 this . #fileSystem = new FileSystem ( this . cwdPath , tsConfig , {
@@ -476,7 +485,7 @@ export class TestRunner {
476485 await this . #indexGenerator. generate ( )
477486
478487 this . ui . logger . info ( 'booting application to run tests...' )
479- await this . #runTests( this . #stickyPort)
488+ await this . #runTests( this . #stickyPort, this . #stickyHmrPort )
480489
481490 /**
482491 * Create watcher
0 commit comments