Skip to content

Commit 227a992

Browse files
authored
fix(browser): run tests serially if provider doesn't provide a mocker (#8032)
1 parent 1716b61 commit 227a992

File tree

2 files changed

+59
-29
lines changed

2 files changed

+59
-29
lines changed

packages/browser/src/node/pool.ts

Lines changed: 49 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -69,28 +69,60 @@ export function createBrowserPool(vitest: Vitest): ProcessPool {
6969
isCancelled = true
7070
})
7171

72-
// TODO: this might now be a good idea... should we run these in chunks?
73-
await Promise.all(
74-
[...groupedFiles.entries()].map(async ([project, files]) => {
75-
await project._initBrowserProvider()
72+
const groupedSpecifications = [...groupedFiles.entries()]
73+
const initialisedPools = (await Promise.all(groupedSpecifications.map(async ([project, files]) => {
74+
await project._initBrowserProvider()
7675

77-
if (!project.browser) {
78-
throw new TypeError(`The browser server was not initialized${project.name ? ` for the "${project.name}" project` : ''}. This is a bug in Vitest. Please, open a new issue with reproduction.`)
79-
}
76+
if (!project.browser) {
77+
throw new TypeError(`The browser server was not initialized${project.name ? ` for the "${project.name}" project` : ''}. This is a bug in Vitest. Please, open a new issue with reproduction.`)
78+
}
79+
80+
if (isCancelled) {
81+
return
82+
}
8083

81-
if (isCancelled) {
82-
return
83-
}
84+
debug?.('provider is ready for %s project', project.name)
8485

85-
debug?.('provider is ready for %s project', project.name)
86+
const pool = ensurePool(project)
87+
vitest.state.clearFiles(project, files)
88+
providers.add(project.browser!.provider)
8689

87-
const pool = ensurePool(project)
88-
vitest.state.clearFiles(project, files)
89-
providers.add(project.browser!.provider)
90+
return {
91+
pool,
92+
provider: project.browser!.provider,
93+
runTests: () => pool.runTests(method, files),
94+
}
95+
})))
9096

91-
await pool.runTests(method, files)
92-
}),
93-
)
97+
if (isCancelled) {
98+
return
99+
}
100+
101+
const parallelPools: (() => Promise<void>)[] = []
102+
const nonParallelPools: (() => Promise<void>)[] = []
103+
104+
for (const result of initialisedPools) {
105+
if (!result) {
106+
return
107+
}
108+
109+
if (result.provider.mocker && result.provider.supportsParallelism) {
110+
parallelPools.push(result.runTests)
111+
}
112+
else {
113+
nonParallelPools.push(result.runTests)
114+
}
115+
}
116+
117+
await Promise.all(parallelPools.map(runTests => runTests()))
118+
119+
for (const runTests of nonParallelPools) {
120+
if (isCancelled) {
121+
return
122+
}
123+
124+
await runTests()
125+
}
94126
}
95127

96128
function getThreadsCount(project: TestProject) {

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

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,16 @@ export class DefaultReporter extends BaseReporter {
3030
}
3131

3232
onTestRunStart(specifications: ReadonlyArray<TestSpecification>): void {
33+
if (this.isTTY) {
34+
if (this.renderSucceed === undefined) {
35+
this.renderSucceed = !!this.renderSucceed
36+
}
37+
38+
if (this.renderSucceed !== true) {
39+
this.renderSucceed = specifications.length <= 1
40+
}
41+
}
42+
3343
this.summary?.onTestRunStart(specifications)
3444
}
3545

@@ -68,18 +78,6 @@ export class DefaultReporter extends BaseReporter {
6878
this.summary?.onInit(ctx, { verbose: this.verbose })
6979
}
7080

71-
onPathsCollected(paths: string[] = []): void {
72-
if (this.isTTY) {
73-
if (this.renderSucceed === undefined) {
74-
this.renderSucceed = !!this.renderSucceed
75-
}
76-
77-
if (this.renderSucceed !== true) {
78-
this.renderSucceed = paths.length <= 1
79-
}
80-
}
81-
}
82-
8381
onTestRunEnd(): void {
8482
this.summary?.onTestRunEnd()
8583
}

0 commit comments

Comments
 (0)