FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

fix(browser): correctly inherit CLI options by sheremet-va · Pull Request #7858 · vitest-dev/vitest · GitHub

Repository navigation

fix(browser): correctly inherit CLI options - #7858

Merged
sheremet-va merged 12 commits into
vitest-dev:mainfrom
sheremet-va:fix/inherit-browser-cli-options
Apr 29, 2025
Merged

sheremet-va merged 12 commits into
vitest-dev:mainfrom
sheremet-va:fix/inherit-browser-cli-options

Conversation

sheremet-va commented Apr 18, 2025 •
edited
Loading

Copy link
Copy Markdown
Member

Description

Fixes #7521

Let's complicate config resolution even further!

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

netlify Bot commented Apr 18, 2025 •
edited
Loading

Copy link
Copy Markdown

✅ Deploy Preview for vitest-dev ready!

Name Link
🔨 Latest commit dd92a95
🔍 Latest deploy log https://app.netlify.com/sites/vitest-dev/deploys/6810ece4f7f15900089d37a8
😎 Deploy Preview https://deploy-preview-7858--vitest-dev.netlify.app
📱 Preview on mobile Toggle QR Code...



Use your smartphone camera to open QR code link.

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

AriPerkkio left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Looks good so far, great work 💯

I wrote couple of manual test cases earlier that fail with these changes:

This config correctly opens Vitest UI when run with vitest --browser.headless=false ✅

import { defineConfig } from "vitest/config";

export default defineConfig({
  test: {
    browser: {
      provider: "playwright",
      enabled: true,
      headless: true,
      instances: [{ browser: "chromium" }],
    },
  },
});

This config opens browser without Vitest UI when run with vitest --browser.headless=false ❌

import { defineConfig } from "vitest/config";

export default defineConfig({
  test: {
    workspace: [
      {
        test: {
          name: "browser",
          browser: {
            provider: "playwright",
            enabled: true,
            headless: true,
            instances: [{ browser: "chromium" }],
          },
        },
      },
    ],
  },
});

This config does not run test cases in Browser Mode when run with vitest --browser.enabled ❌

import { defineConfig } from "vitest/config";

export default defineConfig({
  test: {
    workspace: [
      {
        test: {
          name: "browser",
          browser: {
            provider: "playwright",
            enabled: false,
            headless: true,
            instances: [{ browser: "chromium" }],
          },
        },
      },
    ],
  },
});

Comment on lines +342 to +343
// throw an error to avoid running tests
throw new Error('stop')

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

This utility looks great - I've thought about building something like this before. Sometimes it's not enough to check resolved options just via resolveConfig as plugins and other parts can change them before tests run. Bailing out like this before pools are running saves time.

sheremet-va commented Apr 25, 2025 •
edited
Loading

Copy link
Copy Markdown
Member Author

I wrote couple of manual test cases earlier that fail with these changes:

I cannot confirm this. All configs you provided open the UI (automatic tests also check that UI is set, tests fail without changes in this PR)


if (browser.enabled) {
// if browser was enabled via CLI and it's configured by the user, then validate the input
if (browser.enabled && viteConfig.test?.browser) {

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

The main change is that we ignore all browser CLI flags if workspace doesn't have the browser configured

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Note: we throw an error if --browser is provided, but there are no configurations for it

Copy link
Copy Markdown
Member

I cannot confirm this. All configs you provided open the UI (automatic tests also check that UI is set, tests fail without changes in this PR)

You are right, it seems to work properly now! 💯

sheremet-va merged commit 03660f9 into vitest-dev:main Apr 29, 2025

Copy link
Copy Markdown
Contributor

Thanks a million, this will reduce the amount of people acidentally comitting changing headless: true to false because it will be possible to turn it off from the CLI as needed 😌

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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.

CLI --browser.headless=false doesn't load Vitest UI when using workspaces

3 participants


Back | FazBrowse Home | New Git URL