Skip to content

Conversation

@macarie
Copy link
Member

@macarie macarie commented Nov 30, 2025

Description

Fixes #8959

Please don't delete this checklist! Before submitting the PR, please make sure you do the following:

  • It's really useful if your PR references an issue where it is discussed ahead of time. If the feature is substantial or introduces breaking changes without a discussion, PR might be closed.
  • Ideally, include a test that fails without this PR but passes with it.
  • Please, don't make changes to pnpm-lock.yaml unless you introduce a new test example.
  • Please check Allow edits by maintainers to make review process faster. Note that this option is not available for repositories that are owned by Github organizations.

Tests

  • Run the tests with pnpm test:ci.

Documentation

  • If you introduce new functionality, document it. You can run documentation with pnpm run docs command.

Changesets

  • Changes in changelog are generated from PR name. Please, make sure that it explains your changes in an understandable manner. Please, prefix changeset messages with feat:, fix:, perf:, docs:, or chore:.

@macarie macarie requested a review from sheremet-va November 30, 2025 22:16
Comment on lines 92 to 97
if (chai.util.flag(assertion, '_poll.assert_once')) {
clearTimeout(intervalId)
clearTimeout(timeoutId)

rejectWithCause(err)
}
Copy link
Member Author

Choose a reason for hiding this comment

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

Not entirely convinced by this solution, it adds yet-another exit point to a function that already has many...

@netlify
Copy link

netlify bot commented Nov 30, 2025

Deploy Preview for vitest-dev ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit 22eff98
🔍 Latest deploy log https://app.netlify.com/projects/vitest-dev/deploys/692cc25c817d0b000802528c
😎 Deploy Preview https://deploy-preview-9132--vitest-dev.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

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

@macarie
Copy link
Member Author

macarie commented Nov 30, 2025

Pushed a refactor of the poll assertion logic from the nested timer callbacks to a linear async/await loop.

The control flow was quite hard to follow, there were multiple timeouts to track and exit points across different scopes. This also fixes a potential race condition where check could run concurrently when the timeout fired while the previous call was mid-await.

The behavior is essentially unchanged, the only difference is the last attempt now waits interval before running and the assertion succeeds if it is successful (could keep this behavior, but there were edge cases in which lastError could still be undefined, thus throwing when attempting to set cause).

Happy to revert if there are concerns.

@macarie macarie force-pushed the fix/tomatchscreenshot-once-with-element branch from 9d8a543 to 39d89be Compare December 1, 2025 00:22
@macarie macarie marked this pull request as ready for review December 1, 2025 10:15
const elapsed = performance.now() - start

// Allow some buffer for screenshot capture + diffing
expect(elapsed).toBeLessThan(renderDelay + 500)
Copy link
Member Author

Choose a reason for hiding this comment

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

Locally, 500ms are enough for all browsers to finish. Might be worth monitoring on CI to see if it's flaky.

Copy link
Member Author

Choose a reason for hiding this comment

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

Looks like it's failing in CI. Maybe I can just check < 30_000 since that's poll's default timeout.

errorMessage = error.message
}

expect(typeof errorMessage === 'string')
Copy link
Member

@sheremet-va sheremet-va Dec 1, 2025

Choose a reason for hiding this comment

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

This doesn't do anything, did you mean expect.assert? We should maybe throw an error if the methods are not called 😄

Copy link
Member Author

Choose a reason for hiding this comment

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

Editing fail on my part, it was an if before but forgot to change === with ).toBe( 😅

Good catch, thanks!

@sheremet-va sheremet-va merged commit 0d2e7e3 into vitest-dev:main Dec 2, 2025
15 of 16 checks passed
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.

Infinite loop of screenshot creation on toMatchScreenshot failure

2 participants