{"record":{"id":"6e17a2d9052cdf11","repo":"vitest-dev/vitest","slug":"stopchunktrace-cannot-be-called-outside-of-the-tes","errorCode":null,"errorMessage":"stopChunkTrace cannot be called outside of the test file.","messagePattern":"stopChunkTrace cannot be called outside of the test file\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/browser-playwright/src/commands/trace.ts","lineNumber":36,"sourceCode":"    await context.tracing.start({\n      screenshots: options.screenshots ?? true,\n      snapshots: options.snapshots ?? true,\n      sources: options.sources ?? true,\n    }).catch(() => {\n      provider.tracingContexts.delete(sessionId)\n    })\n    return\n  }\n  throw new TypeError(`The ${provider.name} provider does not support tracing.`)\n}\n\nexport const startChunkTrace: BrowserCommand<[{ name: string; title: string }]> = async (\n  command,\n  { name, title },\n) => {\n  const { provider, sessionId, testPath, context } = command\n  if (!testPath) {\n    throw new Error(`stopChunkTrace cannot be called outside of the test file.`)\n  }\n  if (isPlaywrightProvider(provider)) {\n    if (!provider.tracingContexts.has(sessionId)) {\n      await startTracing(command)\n    }\n    const path = resolveTracesPath(command, name)\n    provider.pendingTraces.set(path, sessionId)\n    await context.tracing.startChunk({ name, title })\n    return\n  }\n  throw new TypeError(`The ${provider.name} provider does not support tracing.`)\n}\n\nexport const stopChunkTrace: BrowserCommand<[{ name: string }]> = async (\n  context,\n  { name },\n) => {\n  if (isPlaywrightProvider(context.provider)) {","sourceCodeStart":18,"sourceCodeEnd":54,"githubUrl":"https://github.com/vitest-dev/vitest/blob/1fa9837ec26533512fdcad8baebf249771bd340a/packages/browser-playwright/src/commands/trace.ts#L18-L54","documentation":"startChunkTrace needs the running test file path to resolve where the chunk trace `.zip` will be written (via resolveTracesPath). When the command is invoked without an active test (testPath undefined) it refuses. Note: the error string says 'stopChunkTrace' but the throwing function is startChunkTrace — this is a copy-paste bug in the message, but the cause is calling startChunkTrace outside a test scope.","triggerScenarios":"Runner/framework code invoking startChunkTrace during a phase that has no bound testPath (global setup/teardown, between tests, or when a test file is collected but not executing). Internal calls from the browser runner before a test context is established.","commonSituations":"Tracing enabled with a misconfigured runner that triggers chunk tracing outside test execution; custom test orchestration that calls startChunkTrace manually; partial support in a non-browser pool.","solutions":["Ensure tracing chunk commands are only triggered while a test is actively running (the runner normally handles this — if you see it manually, you are calling an internal API out of context).","Confirm the file is matched by the browser project's `include` and runs under `pool: 'browser'` so testPath is bound.","If this surfaces from framework internals, file a Vitest issue with the runner state; do not call startChunkTrace yourself."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// do not call startChunkTrace manually; ensure the runner is the only caller.\n// if you must guard custom code:\nif (!command.testPath) {\n  throw new Error('startChunkTrace must be called from within a running test')\n}","typeGuard":"function hasTestPath<T extends { testPath?: string }>(c: T): c is T & { testPath: string } {\n  return !!c.testPath\n}","tryCatchPattern":null,"preventionTips":["Never call internal trace chunk APIs directly; rely on the runner.","Ensure files run under pool: 'browser' with a valid include glob.","Report occurrences via Vitest issues — these commands are runner-internal."],"tags":["browser","tracing","lifecycle","internal"],"backgroundTag":null,"analyzedSha":"1fa9837ec26533512fdcad8baebf249771bd340a","analyzedAt":"2026-08-11T16:11:39.638Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}