Skip to content

fix: avoid leaking the context expect - #11845

Merged
sheremet-va merged 1 commit into
mainfrom
fix/context-expect-retention
Nov 4, 2026
Merged

sheremet-va merged 1 commit into
mainfrom
fix/context-expect-retention

Conversation

@sheremet-va

Copy link
Copy Markdown
Member

Fixes #11839

With isolate: false, a test that reads expect from its context kept its whole file and fixture values alive. createExpect added the built-in matchers again to each local expect, and chai.use() keeps every plugin closure.

  • add customMatchers and benchMatchers only to the global expect
  • call the expect.extend plugin directly instead of with chai.use(); this also releases the matchers that setup files add for each test file

@netlify

netlify Bot commented Nov 3, 2026

Copy link
Copy Markdown

✅ Deploy Preview for vitest-dev ready!

Name Link
🔨 Latest commit a0adc01
🔍 Latest deploy log https://app.netlify.com/projects/vitest-dev/deploys/6ae9c61c49b94a59f507da05
😎 Deploy Preview https://deploy-preview-11845--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.

@flakiness-io

flakiness-io Bot commented Nov 3, 2026 •

Copy link
Copy Markdown

Test Results Summary

This comment shows the latest test results for this pull request.

Commit Status Test Results CI Runs
a0adc01 ❌ Failed 1 regressed · 31397 passed · 234 flaky · 1185 skipped 27 runs

1 regressed

🔥 win 10.0.26100 · snapshots test/e2e/snapshots/domain-aria-inline.test.ts › domain multiple inline at same location - fail

⚠️ 234 flaky

⚠️ win 10.0.26100 · threads test/unit/test/retry.test.ts:55 › describe object add(1, 1) › returned value not be greater than 2
⚠️ Ubuntu 24.04 · vmThreads test/unit/test/retry.test.ts:55 › describe object add(1, 1) › returned value not be greater than 2
⚠️ Ubuntu 24.04 · threads test/unit/test/retry.test.ts:55 › describe object add(1, 1) › returned value not be greater than 2
⚠️ Ubuntu 24.04 · threads test/unit/test/retry.test.ts:55 › describe object add(1, 1) › returned value not be greater than 2
⚠️ Ubuntu 24.04 · vmThreads test/unit/test/retry.test.ts:55 › describe object add(1, 1) › returned value not be greater than 2
⚠️ Ubuntu 24.04 · forks test/unit/test/retry.test.ts:55 › describe object add(1, 1) › returned value not be greater than 2
⚠️ Ubuntu 24.04 · forks test/unit/test/retry.test.ts:55 › describe object add(1, 1) › returned value not be greater than 2
⚠️ win 10.0.26100 · vmThreads test/unit/test/retry.test.ts:55 › describe object add(1, 1) › returned value not be greater than 2
⚠️ win 10.0.26100 · forks test/unit/test/retry.test.ts:55 › describe object add(1, 1) › returned value not be greater than 2
⚠️ win 10.0.26100 · threads test/unit/test/retry.test.ts:61 › describe object add(1, 1) › returned value not be less than 2
…and 224 more

View full report

ℹ️ About Flakiness.io in GitHub

Your team has set up Flakiness.io pull request comments. This comment is updated when

  • The first test results arrive for this pull request
  • A later run reports more results for the same commit
  • A new commit is pushed and tested

Flakiness.io rewrites the comment in place, so it always reflects the most recently tested commit.

@hi-ogawa hi-ogawa left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Nice fix! I was concerned about how this can keep local expect's asymmetric matchers working, then I realized my old comment saying they are already shared through a global singleton lol

// keep track of asymmetric matchers on global so that it can be copied over to local context's `expect`.
// note that the negated variant is automatically shared since it's assigned on the single `expect.not` object.

@sheremet-va
sheremet-va merged commit 3c967a7 into main Nov 4, 2026
29 of 32 checks passed
@sheremet-va
sheremet-va deleted the fix/context-expect-retention branch November 4, 2026 07:38
@elierotenberg

Copy link
Copy Markdown

Fixes #11839

With isolate: false, a test that reads expect from its context kept its whole file and fixture values alive. createExpect added the built-in matchers again to each local expect, and chai.use() keeps every plugin closure.

* add `customMatchers` and `benchMatchers` only to the global `expect`

* call the `expect.extend` plugin directly instead of with `chai.use()`; this also releases the matchers that setup files add for each test file

Thank you!!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

The expect of a test context prevents the garbage collection of its test file and fixture values

3 participants