Skip to content

fix(ui): fix html reporter crash when --bail cancels files - #11693

Merged
sheremet-va merged 3 commits into
vitest-dev:mainfrom
hi-ogawa:fix/issue-11689
Oct 23, 2026
Merged

sheremet-va merged 3 commits into
vitest-dev:mainfrom
hi-ogawa:fix/issue-11689

Conversation

@hi-ogawa

@hi-ogawa hi-ogawa commented Oct 22, 2026 •

Copy link
Copy Markdown
Collaborator

When building the module graph, the HTML reporter assumed TestModule.viteEnvironment is always set. But that assumption is wrong for test files that never reached a worker, for example files that --bail cancels before they start. This PR fixes it by skipping those files, so they show up in the report with an empty module graph.

Other places already handle this case, and only the HTML reporter missed it:

  • const viteEnvironment = testModule.viteEnvironment
    // if there is no viteEnvironment, it means the file did not run yet
    if (!viteEnvironment) {
    return { modules: [], untrackedModules: [] }
    }
  • // the reporter keys graphs by the environment the file ran in, which is the file's
    // `viteEnvironment`. It's unset only for files that never ran, which have no graph.
    const graph = viteEnvironment
    ? metadata.moduleGraph[projectName]?.[viteEnvironment]
    : undefined

hi-ogawa and others added 2 commits October 22, 2026 10:25
Closes vitest-dev#11689

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@netlify

netlify Bot commented Oct 22, 2026

Copy link
Copy Markdown

✅ Deploy Preview for vitest-dev ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit 83b4f66
🔍 Latest deploy log https://app.netlify.com/projects/vitest-dev/deploys/6ad967d0cfc1eb7ceff18ca4
😎 Deploy Preview https://deploy-preview-11693--vitest-dev.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

reporters: ['default', 'html'],
},
)
expect(result.stderr).toMatchInlineSnapshot(`

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.

Previously this failed by:

⎯⎯⎯⎯⎯⎯ Unhandled Error ⎯⎯⎯⎯⎯⎯⎯
Error: Cannot find environment for <repo>/test/e2e/vitest-test-ffef203f-…/b-pass.test.ts
 ❯ getModuleGraphEnvironment ../../../packages/ui/dist/reporter.js:82:9
     80|  }
     81|  if (!environment) {
     82|   throw new Error(`Cannot find environment for ${testFilePath}`);
       |         ^
     83|  }
     84|  return environment;
 ❯ getSharedModuleGraphByEnvironment ../../../packages/ui/dist/reporter.js:68:23
 ❯ getSharedModuleGraphByProject ../../../packages/ui/dist/reporter.js:61:26
 ❯ serializeReportMetadata ../../../packages/ui/dist/reporter.js:232:16
 ❯ HTMLReporter.onTestRunEnd ../../../packages/ui/dist/reporter.js:160:24
 ❯ ../../../packages/vitest/dist/chunks/cli-api.BFK2VqI2.js:13664:56
 ❯ Vitest.report ../../../packages/vitest/dist/chunks/cli-api.BFK2VqI2.js:13664:36
 ❯ TestRun.end ../../../packages/vitest/dist/chunks/cli-api.BFK2VqI2.js:12142:21
 ❯ ../../../packages/vitest/dist/chunks/cli-api.BFK2VqI2.js:13242:26

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@hi-ogawa hi-ogawa changed the title fix(ui): skip never-run files in html report module graph fix(ui): fix html reporter crash when --bail cancels files Oct 22, 2026
@hi-ogawa
hi-ogawa marked this pull request as ready for review October 22, 2026 02:05
@sheremet-va
sheremet-va merged commit 36a5fa1 into vitest-dev:main Oct 23, 2026
29 checks passed
@hi-ogawa
hi-ogawa deleted the fix/issue-11689 branch October 23, 2026 02:25
@github-actions github-actions Bot locked and limited conversation to collaborators Nov 7, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

HTML reporter crashes with "Cannot find environment" when --bail cancels test files

2 participants