Skip to content

Commit f5e6866

Browse files
authored
chore: simplify test/ structure (#9367)
1 parent fd45928 commit f5e6866

343 files changed

Lines changed: 2959 additions & 1994 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitattributes

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
* text=auto eol=lf
22

3-
test/reporters/fixtures/indicator-position.test.js eol=crlf
3+
test/cli/fixtures/reporters/indicator-position.test.js eol=crlf

packages/browser/src/node/project.ts

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ import type {
1414
import type { ParentBrowserProject } from './projectParent'
1515
import { existsSync } from 'node:fs'
1616
import { readFile } from 'node:fs/promises'
17-
import { fileURLToPath } from 'node:url'
1817
import { resolve } from 'pathe'
18+
import { distRoot } from './constants'
1919
import { BrowserServerState } from './state'
2020
import { 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

packages/browser/src/node/projectParent.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,10 +147,10 @@ export class ParentBrowserProject {
147147
throw new Error(`Cannot spawn child server without a parent dev server.`)
148148
}
149149
const clone = new ProjectBrowser(
150+
this,
150151
project,
151152
'/',
152153
)
153-
clone.parent = this
154154
this.children.add(clone)
155155
return clone
156156
}

packages/vitest/src/node/project.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,7 @@ export class TestProject {
505505
[
506506
this.vite?.close(),
507507
this.typechecker?.stop(),
508-
this.browser?.close(),
508+
(this.browser || this._parent?._parentBrowser?.vite)?.close(),
509509
this.clearTmpDir(),
510510
].filter(Boolean),
511511
).then(() => {

packages/vitest/src/node/reporters/junit.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ export interface JUnitOptions {
3535
* @default false
3636
*/
3737
addFileAttribute?: boolean
38+
/**
39+
* Hostname to use in the report. By default, it uses os.hostname()
40+
*/
41+
hostname?: string
3842
}
3943

4044
function flattenTasks(task: Task, baseName = ''): Task[] {
@@ -373,7 +377,7 @@ export class JUnitReporter implements Reporter {
373377
{
374378
name: filename,
375379
timestamp: new Date().toISOString(),
376-
hostname: hostname(),
380+
hostname: this.options.hostname || hostname(),
377381
tests: file.tasks.length,
378382
failures: file.stats.failures,
379383
errors: 0, // An errored test is one that had an unanticipated problem. We cannot detect those.

pnpm-lock.yaml

Lines changed: 36 additions & 84 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)