Skip to content

refactor(browser): centralize browser config validation in @rstest/browser#951

Merged
fi3ework merged 1 commit intomainfrom
max/2026-02-08--01-48AM
Feb 8, 2026
Merged

refactor(browser): centralize browser config validation in @rstest/browser#951
fi3ework merged 1 commit intomainfrom
max/2026-02-08--01-48AM

Conversation

@fi3ework
Copy link
Copy Markdown
Member

@fi3ework fi3ework commented Feb 8, 2026

Summary

Moves browser-specific config validation (provider, viewport) from @rstest/core to @rstest/browser, called after dynamic import. This keeps @rstest/core focused on config normalization while @rstest/browser owns runtime validation logic. Type definitions remain in core to preserve defineConfig autocomplete.

Behavior diff:

Scenario Before After
Invalid browser.provider Throws during withDefaultConfig() in core Throws after loading @rstest/browser, slightly later
Invalid browser.viewport Throws during withDefaultConfig() in core Validated by validateBrowserConfig() in browser package

Changes:

  • Add validateBrowserConfig() exported from @rstest/browser
    • Validates provider, viewport preset, and viewport dimensions
  • Move BROWSER_VIEWPORT_PRESET_IDS and resolveBrowserViewportPreset() to browser package
  • Convert DevicePreset from derived const to explicit literal union in core types
  • Remove browser validation from withDefaultConfig() in core
  • Add e2e test for invalid browser provider early-exit
  • Add sync comments to prevent drift between core types and browser runtime

Related Links

Checklist

  • Tests updated (or not required).
  • Documentation updated (or not required).

Copilot AI review requested due to automatic review settings February 8, 2026 06:31
@fi3ework fi3ework enabled auto-merge (squash) February 8, 2026 06:31
Copy link
Copy Markdown
Contributor

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 moves browser-specific config validation (provider + viewport) out of @rstest/core and into @rstest/browser, running validation after the browser package is dynamically loaded. This keeps core focused on normalization while delegating runtime validation to the browser runtime package.

Changes:

  • Added validateBrowserConfig() to @rstest/browser and invoked it from core before running/listing browser tests.
  • Moved viewport preset IDs + preset resolution into @rstest/browser, and updated core types to keep defineConfig autocomplete.
  • Updated core config tests to reflect “normalize only” behavior and added an e2e fixture/test for invalid provider early exit.

Reviewed changes

Copilot reviewed 13 out of 14 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
packages/core/tests/config.test.ts Updates expectations: core no longer throws on invalid/missing browser fields during normalization.
packages/core/src/utils/constants.ts Removes viewport preset IDs from core constants.
packages/core/src/types/config.ts Converts DevicePreset typing to an explicit union and documents sync requirement with browser runtime presets.
packages/core/src/env.d.ts Adds validateBrowserConfig to the ambient @rstest/browser module declaration.
packages/core/src/core/runTests.ts Calls validateBrowserConfig() after loading @rstest/browser and before running browser tests.
packages/core/src/core/listTests.ts Calls validateBrowserConfig() after loading @rstest/browser and before listing browser tests.
packages/core/src/core/browserLoader.ts Extends BrowserModule type to include validateBrowserConfig.
packages/core/src/config.ts Removes browser provider/viewport validation from withDefaultConfig() (normalization only).
packages/browser/src/viewportPresets.ts Introduces runtime source-of-truth for viewport preset IDs and dimensions + resolver.
packages/browser/src/index.ts Exports validateBrowserConfig and viewport preset utilities from the browser package entrypoint.
packages/browser/src/configValidation.ts Implements provider + viewport validation used by core before starting browser mode.
e2e/browser-mode/fixtures/invalid-provider/tests/smoke.test.ts Adds a minimal test file for the invalid-provider e2e fixture.
e2e/browser-mode/fixtures/invalid-provider/rstest.config.ts Adds an e2e config fixture with an intentionally invalid browser provider.
e2e/browser-mode/config.test.ts Adds an e2e test asserting invalid provider fails before browser mode starts.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 196 to 199
validateBrowserConfig(context as any);
// Cast to any because listBrowserTests expects Rstest but we have RstestContext
// In practice, context is always a Rstest instance
return listBrowserTests(context as any, { shardedEntries });
Copy link

Copilot AI Feb 8, 2026

Choose a reason for hiding this comment

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

The as any casts aren’t needed here: BrowserModule.validateBrowserConfig/listBrowserTests are typed to accept unknown in core, so context can be passed directly. Keeping the casts (and the nearby comment about type mismatch) makes the code harder to reason about and can hide real typing issues.

Suggested change
validateBrowserConfig(context as any);
// Cast to any because listBrowserTests expects Rstest but we have RstestContext
// In practice, context is always a Rstest instance
return listBrowserTests(context as any, { shardedEntries });
validateBrowserConfig(context);
return listBrowserTests(context, { shardedEntries });

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 2c5602a422

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

const { validateBrowserConfig, runBrowserTests } = await loadBrowserModule({
projectRoots,
});
validateBrowserConfig(context);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Handle validation failures before parallel browser launch

runBrowserModeTests now calls validateBrowserConfig(context) and can reject immediately on invalid browser config, but in mixed node+browser runs runTests starts this promise and only awaits it much later after node work. In Node 22 this creates an unhandled rejection window (default --unhandled-rejections=throw), so an invalid browser provider/viewport can crash the process before reporters/cleanup run instead of producing a controlled test failure; this regression is introduced by the new synchronous throw point here.

Useful? React with 👍 / 👎.

@fi3ework fi3ework force-pushed the max/2026-02-08--01-48AM branch from 2c5602a to 8b22d6b Compare February 8, 2026 06:48
@fi3ework fi3ework merged commit 6d412f4 into main Feb 8, 2026
9 checks passed
@fi3ework fi3ework deleted the max/2026-02-08--01-48AM branch February 8, 2026 07:05
@9aoy 9aoy mentioned this pull request Feb 10, 2026
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.

2 participants