Skip to content

Commit

Permalink
apply sequencer to browser tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tim-smart committed Nov 5, 2023
1 parent 91dcf57 commit 97267ef
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
13 changes: 11 additions & 2 deletions packages/vitest/src/node/pools/browser.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { createDefer } from '@vitest/utils'
import { relative } from 'pathe'
import type { Vitest } from '../core'
import type { ProcessPool } from '../pool'
import type { ProcessPool, WorkspaceSpec } from '../pool'
import type { WorkspaceProject } from '../workspace'
import type { BrowserProvider } from '../../types/browser'

Expand All @@ -27,6 +27,9 @@ export function createBrowserPool(ctx: Vitest): ProcessPool {
}
}

const Sequencer = ctx.config.sequence.sequencer
const sequencer = new Sequencer(ctx)

const runTests = async (project: WorkspaceProject, files: string[]) => {
ctx.state.clearFiles(project, files)

Expand All @@ -39,7 +42,13 @@ export function createBrowserPool(ctx: Vitest): ProcessPool {
providers.add(provider)

const origin = `http://${ctx.config.browser.api?.host || 'localhost'}:${project.browser!.config.server.port}`
const paths = files.map(file => relative(project.config.root, file))

let specs: Array<WorkspaceSpec> = files.map(file => [project, file])
if (ctx.config.shard)
specs = await sequencer.shard(specs)
specs = await sequencer.sort(specs)

const paths = specs.map(([,file]) => relative(project.config.root, file))

if (project.config.browser.isolate) {
for (const path of paths) {
Expand Down
2 changes: 1 addition & 1 deletion test/browser/specs/shard.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ const browserResult = await readFile('./browser-shard.json', 'utf-8')
const browserResultJson = JSON.parse(browserResult)

await test('shard option runs portion of tests', async () => {
assert.strictEqual(browserResultJson.numTotalTests, 12)
assert.strictEqual(browserResultJson.testResults.length, 4)
})

0 comments on commit 97267ef

Please sign in to comment.