Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/browser/src/node/serverOrchestrator.ts
Copy link
Copy Markdown
Collaborator Author

@hi-ogawa hi-ogawa May 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Opening /__vitest_test__/ without ?sessionId is allowed for preview, but for otelCarrier, it's legitimate to require proper sessionId -> session mapping on server side.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be honest, I have no idea how sessionId-less orchestrator is meant to work. Probably we should revisit the proper invariant around these fallback.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it just picks up the first available one

Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export async function resolveOrchestrator(
__VITEST_TYPE__: '"orchestrator"',
__VITEST_SESSION_ID__: JSON.stringify(sessionId),
__VITEST_TESTER_ID__: '"none"',
__VITEST_OTEL_CARRIER__: url.searchParams.get('otelCarrier') ?? 'null',
__VITEST_OTEL_CARRIER__: JSON.stringify(session?.otelCarrier ?? null),
__VITEST_PROVIDED_CONTEXT__: JSON.stringify(stringify(browserProject.project.getProvidedContext())),
Comment thread
hi-ogawa marked this conversation as resolved.
Comment thread
hi-ogawa marked this conversation as resolved.
__VITEST_API_TOKEN__: JSON.stringify(globalServer.vitest.config.api.token),
})
Expand Down
9 changes: 8 additions & 1 deletion packages/vitest/src/node/browser/sessions.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { OTELCarrier } from '../../utils/traces'
import type { TestProject } from '../project'
import type { BrowserServerStateSession } from '../types/browser'
import { createDefer } from '@vitest/utils/helpers'
Expand All @@ -15,7 +16,12 @@ export class BrowserSessions {
this.sessions.delete(sessionId)
}

createSession(sessionId: string, project: TestProject, pool: { reject: (error: Error) => void }): Promise<void> {
createSession(
sessionId: string,
project: TestProject,
pool: { reject: (error: Error) => void },
options?: { otelCarrier?: OTELCarrier },
): Promise<void> {
// this promise only waits for the WS connection with the orchestrator to be established
const defer = createDefer<void>()

Expand All @@ -25,6 +31,7 @@ export class BrowserSessions {

this.sessions.set(sessionId, {
project,
otelCarrier: options?.otelCarrier,
connected: () => {
Comment thread
hi-ogawa marked this conversation as resolved.
defer.resolve()
clearTimeout(timeout)
Expand Down
4 changes: 1 addition & 3 deletions packages/vitest/src/node/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -631,14 +631,12 @@ export class TestProject {
const url = new URL('/__vitest_test__/', origin)
url.searchParams.set('sessionId', sessionId)
const otelCarrier = this.vitest._traces.getContextCarrier()
if (otelCarrier) {
url.searchParams.set('otelCarrier', JSON.stringify(otelCarrier))
}
this.vitest._browserSessions.sessionIds.add(sessionId)
const sessionPromise = this.vitest._browserSessions.createSession(
sessionId,
this,
pool,
{ otelCarrier },
)
const pagePromise = this.browser.provider.openPage(
sessionId,
Expand Down
2 changes: 2 additions & 0 deletions packages/vitest/src/node/types/browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import type { Plugin, ViteDevServer } from 'vite'
import type { BrowserCommands, CDPSession } from 'vitest/browser'
import type { BrowserTraceViewMode } from '../../runtime/config'
import type { BrowserTesterOptions } from '../../types/browser'
import type { OTELCarrier } from '../../utils/traces'
import type { TestProject } from '../project'
import type { ApiConfig, ProjectConfig } from './config'

Expand Down Expand Up @@ -354,6 +355,7 @@ export interface BrowserCommandContext {

export interface BrowserServerStateSession {
project: TestProject
otelCarrier?: OTELCarrier
connected: () => void
fail: (v: Error) => void
}
Expand Down
Loading