@@ -14,8 +14,8 @@ import type {
1414import type { ParentBrowserProject } from './projectParent'
1515import { existsSync } from 'node:fs'
1616import { readFile } from 'node:fs/promises'
17- import { fileURLToPath } from 'node:url'
1817import { resolve } from 'pathe'
18+ import { distRoot } from './constants'
1919import { BrowserServerState } from './state'
2020import { getBrowserProvider } from './utils'
2121
@@ -25,41 +25,35 @@ export class ProjectBrowser implements IProjectBrowser {
2525
2626 public provider ! : BrowserProvider
2727 public vitest : Vitest
28+ public vite : ViteDevServer
2829 public config : ResolvedConfig
29- public children : Set < ProjectBrowser > = new Set < ProjectBrowser > ( )
30-
31- public parent ! : ParentBrowserProject
3230
3331 public state : BrowserServerState = new BrowserServerState ( )
3432
3533 constructor (
34+ public parent : ParentBrowserProject ,
3635 public project : TestProject ,
3736 public base : string ,
3837 ) {
3938 this . vitest = project . vitest
4039 this . config = project . config
40+ this . vite = parent . vite
4141
42- const pkgRoot = resolve ( fileURLToPath ( import . meta. url ) , '../..' )
43- const distRoot = resolve ( pkgRoot , 'dist' )
44-
42+ // instances can override testerHtmlPath
4543 const testerHtmlPath = project . config . browser . testerHtmlPath
4644 ? resolve ( project . config . root , project . config . browser . testerHtmlPath )
4745 : resolve ( distRoot , 'client/tester/tester.html' )
46+ // TODO: when config resolution is rewritten, project and parentProject should be created before the vite server is started
4847 if ( ! existsSync ( testerHtmlPath ) ) {
4948 throw new Error ( `Tester HTML file "${ testerHtmlPath } " doesn't exist.` )
5049 }
5150 this . testerFilepath = testerHtmlPath
52-
5351 this . testerHtml = readFile (
54- testerHtmlPath ,
52+ this . testerFilepath ,
5553 'utf8' ,
5654 ) . then ( html => ( this . testerHtml = html ) )
5755 }
5856
59- get vite ( ) : ViteDevServer {
60- return this . parent . vite
61- }
62-
6357 private commands = { } as Record < string , BrowserCommand < any , any > >
6458
6559 public registerCommand < K extends keyof BrowserCommands > (
@@ -130,7 +124,7 @@ export class ProjectBrowser implements IProjectBrowser {
130124 }
131125
132126 async close ( ) : Promise < void > {
133- await this . parent . vite . close ( )
127+ await this . vite . close ( )
134128 }
135129}
136130
0 commit comments