Skip to content

Comments

fix(browser): correctly calculate timeout in hooks when actions are performed#7747

Merged
sheremet-va merged 1 commit intovitest-dev:mainfrom
sheremet-va:fix/timeout-calculation-browser-mode
Mar 28, 2025
Merged

fix(browser): correctly calculate timeout in hooks when actions are performed#7747
sheremet-va merged 1 commit intovitest-dev:mainfrom
sheremet-va:fix/timeout-calculation-browser-mode

Conversation

@sheremet-va
Copy link
Member

Description

Fixes #7694

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.

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:.

@sheremet-va sheremet-va requested a review from Copilot March 27, 2025 15:06
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes the calculation of timeouts in hooks when actions are performed in the browser context. It adjusts error message expectations and test snapshots for timeout errors, updates the runner to track the start time and timeout per task, and propagates these changes through the browser client and tester utilities.

  • Updated test expectations in browser tests by removing deprecated playwright-specific tests and changing the expected error line numbers.
  • Enhanced timeout tracking by adding private properties to the runner and clearing them appropriately after test execution.
  • Adjusted browser client state to include the runner and updated the processTimeoutOptions logic to use the new timeout properties.

Reviewed Changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated no comments.

Show a summary per file
File Description
test/browser/test/failing.test.ts Removed playwright-specific tests and updated error matching criteria
test/browser/specs/runner.test.ts Adjusted expected error snapshot line numbers and renamed a test case
test/browser/fixtures/timeout-hooks/vitest.config.ts Added a dedicated configuration for timeout hooks tests
test/browser/fixtures/timeout-hooks/hooks-timeout.test.ts Introduced new tests for verifying timeout hooks behavior
packages/runner/src/types/runner.ts Added private properties (_currentTaskStartTime, _currentTaskTimeout) to track timeout details
packages/runner/src/context.ts Updated the withTimeout function to set and clear the runner timeout properties
packages/browser/src/client/utils.ts Extended the BrowserRunnerState interface with a runner property
packages/browser/src/client/tester/utils.ts Modified processTimeoutOptions to compute timeout based on the runner properties
packages/browser/src/client/tester/tester.ts Set the runner in the browser state to facilitate updated timeout logic
Comments suppressed due to low confidence (3)

packages/runner/src/context.ts:49

  • Consider adding a null check for the object returned by getRunner() to avoid potential runtime errors if the runner is unexpectedly undefined.
const runner = getRunner()

packages/browser/src/client/tester/utils.ts:147

  • Ensure that getBrowserState().runner is properly initialized before processTimeoutOptions is called to prevent potential undefined behavior.
const runner = getBrowserState().runner

test/browser/specs/runner.test.ts:180

  • [nitpick] Verify that the updated error matching pattern with the new line number accurately reflects the current code locations after the refactor.
expect(stderr).toMatch(/test\/failing.test.ts:25:(2|8)/)

@netlify
Copy link

netlify bot commented Mar 27, 2025

Deploy Preview for vitest-dev ready!

Name Link
🔨 Latest commit 85440fe
🔍 Latest deploy log https://app.netlify.com/sites/vitest-dev/deploys/67e56991aba14200082228bf
😎 Deploy Preview https://deploy-preview-7747--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 site configuration.

@sheremet-va sheremet-va merged commit a550551 into vitest-dev:main Mar 28, 2025
12 of 13 checks passed
@sheremet-va sheremet-va deleted the fix/timeout-calculation-browser-mode branch March 28, 2025 12:48
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.

Timeout is calculated incorrectly in hooks

2 participants