Skip to content

POC: run tests in real-browser vitest mode - #2638

Merged
matyasf merged 1 commit into
masterfrom
vitest_browser
Jul 28, 2026
Merged

POC: run tests in real-browser vitest mode#2638
matyasf merged 1 commit into
masterfrom
vitest_browser

Conversation

@matyasf

@matyasf matyasf commented Jul 14, 2026

Copy link
Copy Markdown
Collaborator

Add real-browser Vitest (Playwright/chromium) test POC, that replaces both Cypress component tests AND Vitest unit tests.

Summary

  • Port Alert (ui-alerts) and Dialog (ui-dialog) and some other suites to vitest/browser
  • add test:browser scripts and new vitest configs.

Test Plan

  • pnpm run test:browser runs the browser tests in the console
  • pnpm run test:browser-ui runs the browser tests in a browser
  • Check the code diff, it should do the same thing. Also check how you like the new syntax, any pros or cons
  • Read about it on https://vitest.dev/guide/browser/ or watch a short Youtube video

Future additions:

  • Vitest can automatically screenshot test failures, we could add it to the CI somehow
  • Vitest browser has a Visual regression test add-on, we could use it.

Fixes INSTUI-5098

🤖 Generated with Claude Code

@matyasf matyasf self-assigned this Jul 14, 2026
@matyasf matyasf changed the title test(ui-alerts,ui-dialog): run Alert and Dialog tests in real-browser vitest mode POC: run Alert and Dialog tests in real-browser vitest mode Jul 14, 2026
@github-actions

github-actions Bot commented Jul 14, 2026

Copy link
Copy Markdown
Contributor
PR Preview Action v1.8.1
Preview removed because the pull request was closed.
2026-07-28 10:09 UTC

})
DialogExample.displayName = 'DialogExample'

const NestedDialogExample = (props: DialogProps) => {

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

This was not used by the test at all

@github-actions

github-actions Bot commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

Visual regression report

⚠️ Changes detected.

Status Count
Unchanged 0
Changed 1
New 96
Removed 32

📊 View full report

Diff images (33)

alert.png — baseline no longer produced

avatar.png — baseline no longer produced

badge.png — baseline no longer produced

billboard.png — baseline no longer produced

breadcrumb.png — baseline no longer produced

button-and-derivatives.png — baseline no longer produced

byline.png — baseline no longer produced

calendar.png — baseline no longer produced

checkbox.png — baseline no longer produced

checkboxgroup.png — baseline no longer produced

colorpicker.png — baseline no longer produced

contextview.png — baseline no longer produced

custom-and-lucide-icons.png — baseline no longer produced

dateinput-dateinput2.png — baseline no longer produced

datetimeinput.png — baseline no longer produced

diff-demo.png — 6324 pixels differ

drilldown.png — baseline no longer produced

filedrop.png — baseline no longer produced

form-errors.png — baseline no longer produced

heading.png — baseline no longer produced

img.png — baseline no longer produced

link.png — baseline no longer produced

menu.png — baseline no longer produced

metric-pill-tag-timeselect-text.png — baseline no longer produced

options.png — baseline no longer produced

pagination.png — baseline no longer produced

progressbar.png — baseline no longer produced

select-simpleselect.png — baseline no longer produced

table.png — baseline no longer produced

tabs.png — baseline no longer produced

tooltip.png — baseline no longer produced

treebrowser.png — baseline no longer produced

view.png — baseline no longer produced

Baselines come from the visual-baselines branch. They refresh on every merge to master.

github-actions Bot pushed a commit that referenced this pull request Jul 14, 2026
Comment thread vitest.config.mts
enabled: true,
provider: playwright(),
headless: true,
instances: [{ browser: 'chromium' }],

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

we can add here other browsers easily to run our test suite on e.g. Firefox (but CI support might be tricky)

@joyenjoyer joyenjoyer Jul 16, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Good idea; I would add Safari if it is possible, it has many tricky cases when it comes to a11y

Comment thread vitest.config.mts
/// <reference types="vitest" />

import { defineConfig } from 'vitest/config'
import { defineConfig, configDefaults } from 'vitest/config'

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I havent checked this config thoroughly, we should do it, if this is the way forward

- name: Install dependencies
run: pnpm install --frozen-lockfile
- name: Install Playwright browser
run: pnpm exec playwright install --with-deps chromium

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

why isnt it installed from dev deps?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I also had to run this locally, pnpm install is not enough

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

there's no way to express it as a dependency.
playwright ships the JS driver only; the actual Chromium build (~150 MB) lives in ~/.cache/ms-playwright, outside node_modules, and is fetched by playwright install. I've added this to the package.json scripts.
The with-deps flag installs system deps too, these are present on PCs with GUIs and would just slow down test runs

Comment thread vitest.config.mts Outdated
find: `${pkgName}/src`,
replacement: path.join(pkgPath, 'src')
})
// Fallback bare-name -> package dir (for packages without an exports map)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

is this an existing scenario or just AI being cautious?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

AI being too cautinous, I've removed it

Comment thread vitest.config.mts
@@ -49,6 +126,14 @@ export default defineConfig({
// Allows using APIs like Jest without importing them
globals: true,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

not part of the changeset, but maybe we should consider changing this to false?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

yep, but in a different PR

Comment thread vitest.setup.browser.ts

// @instructure/console only outputs logs if process.env.NODE_ENV !== 'production'
// these messages are sometimes used in test assertions
if (typeof globalThis.process === 'undefined') {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

this file is a bit hard to parse. is it only needed because of the console package?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I dont know yet, it could be that other errors surface when we dont mock it

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

as I see yes. We're using the NODE_ENV in 3 types of places:

  1. to add console warnings/errors in non-prod builds.
  2. to have different displayName for stuff that is wrapped in decorators withStyle or WithDeterministicId.
  3. to generate a less readable, but shorter uid in prod.

As I see some tests are checking for console errors, this is why this mock is needed.
IMO in the future we should remove all NODE_ENV checks.

@matyasf
matyasf requested a review from HouseOfHawks July 20, 2026 14:09
@joyenjoyer

joyenjoyer commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

I like the browser-based runtime. There isn't a huge difference in the code syntax, which is also a great thing. I can't see any major drawbacks yet. I'd replace the component tests and Vitest tests with this if the test run is significantly faster.

github-actions Bot pushed a commit that referenced this pull request Jul 27, 2026
@matyasf
matyasf requested a review from balzss July 27, 2026 13:45
@matyasf matyasf changed the title POC: run Alert and Dialog tests in real-browser vitest mode POC: run tests in real-browser vitest mode Jul 27, 2026
github-actions Bot pushed a commit that referenced this pull request Jul 27, 2026

@balzss balzss left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

this is good as is for preparing the complete migration. please squash the commit before rebasing to master

Add a `browser` Vitest project that runs real-browser component tests via Playwright,
alongside the existing jsdom `web` and `node` projects.

- migrate the emotion, ui-a11y-content, ui-a11y-utils, ui-alerts, ui-avatar, ui-badge and
  ui-dialog test suites to browser mode, and delete the Cypress specs they replace
- alias `@instructure/*` workspace packages to TypeScript source so browser tests run
  without a prebuild, and alias bare `moment` to the all-locales build
- exclude the migrated packages from the `web` project so they do not run twice
- add `test:browser`, `test:browser-watch` and `test:browser-ui` scripts
- add a `Vitest browser tests` job to PR validation

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
github-actions Bot pushed a commit that referenced this pull request Jul 28, 2026
@matyasf
matyasf merged commit 30c7251 into master Jul 28, 2026
13 of 14 checks passed
@matyasf
matyasf deleted the vitest_browser branch July 28, 2026 10:09
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.

4 participants