Skip to content

Commit 2b4b058

Browse files
authored
fix(runner): don't bundle runner with utils (#8496)
1 parent 259a298 commit 2b4b058

File tree

4 files changed

+8
-7
lines changed

4 files changed

+8
-7
lines changed

packages/browser/src/client/orchestrator.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { GlobalChannelIncomingEvent, IframeChannelIncomingEvent, IframeChannelOutgoingEvent, IframeViewportDoneEvent, IframeViewportFailEvent } from '@vitest/browser/client'
22
import type { BrowserTesterOptions, SerializedConfig } from 'vitest'
33
import { channel, client, globalChannel } from '@vitest/browser/client'
4-
import { generateHash } from '@vitest/runner/utils'
4+
import { generateFileHash } from '@vitest/runner/utils'
55
import { relative } from 'pathe'
66
import { getUiAPI } from './ui'
77
import { getBrowserState, getConfig } from './utils'
@@ -291,9 +291,8 @@ async function sendEventToIframe(event: IframeChannelOutgoingEvent) {
291291

292292
function generateFileId(file: string) {
293293
const config = getConfig()
294-
const project = config.name || ''
295294
const path = relative(config.root, file)
296-
return generateHash(`${path}${project}`)
295+
return generateFileHash(path, config.name)
297296
}
298297

299298
async function setIframeViewport(

packages/browser/src/client/ui.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type { BrowserUI } from 'vitest'
22

3+
/* @__NO_SIDE_EFFECTS__ */
34
export function getUiAPI(): BrowserUI | undefined {
45
// @ts-expect-error not typed global
56
return window.__vitest_ui_api__

packages/runner/src/collect.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import type { FileSpecification, VitestRunner } from './types/runner'
22
import type { File, SuiteHooks } from './types/tasks'
33
import { toArray } from '@vitest/utils'
44
import { processError } from '@vitest/utils/error'
5-
import { collectorContext } from './context'
5+
import { collectorContext, setFileContext } from './context'
66
import { getHooks, setHooks } from './map'
77
import { runSetupFiles } from './setup'
88
import {
@@ -32,6 +32,7 @@ export async function collectTests(
3232
const testLocations = typeof spec === 'string' ? undefined : spec.testLocations
3333

3434
const file = createFileTask(filepath, config.root, config.name, runner.pool)
35+
setFileContext(file, Object.create(null))
3536
file.shuffle = config.sequence.shuffle
3637

3738
runner.onCollectStart?.(file)

packages/runner/src/utils/collect.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import type { File, Suite, TaskBase } from '../types/tasks'
33
import { processError } from '@vitest/utils/error'
44
import { parseSingleStack } from '@vitest/utils/source-map'
55
import { relative } from 'pathe'
6-
import { setFileContext } from '../context'
76

87
/**
98
* If any tasks been marked as `only`, mark all other tasks as `skip`.
@@ -155,6 +154,7 @@ function checkAllowOnly(task: TaskBase, allowOnly?: boolean) {
155154
}
156155
}
157156

157+
/* @__NO_SIDE_EFFECTS__ */
158158
export function generateHash(str: string): string {
159159
let hash = 0
160160
if (str.length === 0) {
@@ -197,7 +197,6 @@ export function createFileTask(
197197
pool,
198198
}
199199
file.file = file
200-
setFileContext(file, Object.create(null))
201200
return file
202201
}
203202

@@ -206,11 +205,12 @@ export function createFileTask(
206205
* @param file File relative to the root of the project to keep ID the same between different machines
207206
* @param projectName The name of the test project
208207
*/
208+
/* @__NO_SIDE_EFFECTS__ */
209209
export function generateFileHash(
210210
file: string,
211211
projectName: string | undefined,
212212
): string {
213-
return generateHash(`${file}${projectName || ''}`)
213+
return /* @__PURE__ */ generateHash(`${file}${projectName || ''}`)
214214
}
215215

216216
export function findTestFileStackTrace(testFilePath: string, error: string): ParsedStack | undefined {

0 commit comments

Comments
 (0)