Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Oct 7, 2025

This PR migrates the test suite from mocha/chai to Vitest with Playwright browser mode, modernizes the CI/CD pipeline to use Node 22 and 24, and updates dependencies.

Motivation

The project was using mocha and chai for browser-based testing, which required additional build steps and dependencies. Vitest provides a modern, fast testing framework with built-in TypeScript support and browser testing capabilities through Playwright.

Changes

Test Framework Migration

Migrated all 22 tests from mocha/chai to Vitest:

  • Replaced import {describe, it, beforeEach} from 'mocha' with import {describe, it, beforeEach, expect} from 'vitest'
  • Converted Chai assertions to Vitest's built-in assertions:
    • expect(calls).to.eql([...])expect(calls).toEqual([...])
    • expect(calls).to.have.lengthOf(1)expect(calls).toHaveLength(1)
  • Updated test script in package.json from mocha -r ts-node/register --extension ts to vitest run

Browser Testing Configuration

Created vitest.config.ts with Playwright provider to run tests in a real browser environment:

browser: {
  enabled: true,
  instances: [{
    browser: 'chromium'
  }],
  provider: 'playwright',
  headless: true
}

Playwright browsers are installed in CI via npx playwright install chromium step added before running tests.

Dependencies

Added:

  • vitest@^3.2.4 - Modern test framework with built-in TypeScript support
  • @vitest/browser - Browser testing support for Vitest
  • playwright - Browser automation for running tests
  • @types/node & @types/debug - Type definitions for Node.js and debug modules

Removed:

  • mocha, @types/mocha - Replaced by Vitest
  • chai, @types/chai - Vitest has built-in assertions
  • ts-node - No longer needed as Vitest handles TypeScript directly

Updated:

  • typescript from v4.1.5 to v5.9.3 - Required for Vitest type compatibility

CI/CD Updates

Updated GitHub Actions workflows to use modern Node.js versions and install Playwright browsers:

  • node.js.yml: Updated matrix to test on Node 22.x and 24.x (previously 20.x and 22.x), added npx playwright install chromium step
  • publish.yml: Updated to use Node 24 as the default (previously 22), added npx playwright install chromium step
  • Both workflows already using latest actions/checkout@v4 and actions/setup-node@v4

TypeScript Configuration

Updated tsconfig.json:

  • Added skipLibCheck: true to handle third-party library type definitions
  • Maintained all existing strict type checking options
  • No changes required to build configuration or output formats

Gitignore

Added test/__screenshots__ to .gitignore to exclude Vitest browser mode screenshot artifacts from version control.

Testing

All 22 tests pass successfully:

✓ chromium test/index.ts (22 tests) 7.4s
  ✓ throttle (8 tests)
  ✓ throttle {start:false} (1 test)
  ✓ throttle {middle:false} (2 tests)
  ✓ debounce (4 tests)
  ✓ marbles (5 tests)
  ✓ decorators (2 tests)

Test Files  1 passed (1)
Tests  22 passed (22)

Build and lint both pass without errors or warnings.

Breaking Changes

None. This is purely an internal testing infrastructure change with no impact on the public API or package consumers.

Original prompt

This package currently uses chai and mocha to run tests within a browser. Convert it to use Vitest in browser mode with Playwright. Install vitest version ^3.2.4. Update test files to import describe/it/etc from vitest and use assertion helpers from vitest. Remove the pretest build script since vitest can run TypeScript directly. Run the tests with npm test and verify they pass. Remove all references to karma/chai/mocha.

Also update all github workflows to run with Node 24 by default, and include Node 22 in matrix runs (only if matrix is already configured, don't add it). Drop older versions. Update actions to use the latest version of actions/setup-node and actions/checkout. Do not run npm playwright install in CI, it should work without this additional step.

Ensure lint and tests both pass. Remove any references to karma/mocha/chai from the lint config.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI changed the title [WIP] Update testing framework to use Vitest with Playwright Convert tests from mocha/chai to Vitest with Playwright browser mode Oct 7, 2025
Copilot AI requested a review from dgreif October 7, 2025 16:02
Copilot finished work on behalf of dgreif October 7, 2025 16:02
Copy link
Contributor

@dgreif dgreif left a comment

Choose a reason for hiding this comment

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

@copilot add test/__screenshots__ to the gitignore

vitest.config.ts Outdated
Comment on lines 12 to 14
launch: {
executablePath: '/usr/bin/chromium'
}
Copy link
Contributor

Choose a reason for hiding this comment

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

@copilot remove this and instead run npx playwright install chromium before the tests in CI

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed the executablePath configuration and added npx playwright install chromium step to both CI workflows (node.js.yml and publish.yml) in commit 2fb8a93

Copy link
Contributor Author

Copilot AI commented Oct 8, 2025

@copilot add test/__screenshots__ to the gitignore

Added test/__screenshots__ to .gitignore in commit 2fb8a93

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • esm.ubuntu.com
    • Triggering command: /usr/lib/apt/methods/https (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

@dgreif dgreif marked this pull request as ready for review October 8, 2025 02:43
@dgreif dgreif requested a review from a team as a code owner October 8, 2025 02:43
@dgreif dgreif requested review from Copilot and dgreif October 8, 2025 02:43
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 migrates the test framework from Mocha/Chai to Vitest with Playwright browser mode, updating to modern testing infrastructure and Node.js versions.

  • Converts all test files from Mocha/Chai syntax to Vitest equivalents
  • Configures Vitest to run tests in real Chromium browser via Playwright
  • Updates CI workflows to Node 22.x/24.x and installs Playwright browsers

Reviewed Changes

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

Show a summary per file
File Description
vitest.config.ts New Vitest configuration enabling browser mode with Playwright
test/index.ts Migrated test imports and assertions from Mocha/Chai to Vitest
package.json Updated dependencies and test script for Vitest
.github/workflows/publish.yml Updated to Node 24 and added Playwright install step
.github/workflows/node.js.yml Updated matrix to Node 22.x/24.x and added Playwright install step

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Copilot finished work on behalf of dgreif October 8, 2025 02:44
Copy link

@bteng22 bteng22 left a comment

Choose a reason for hiding this comment

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

🚀

@dgreif dgreif merged commit 18af7ba into main Oct 9, 2025
7 checks passed
@dgreif dgreif deleted the copilot/convert-tests-to-vitest-playwright branch October 9, 2025 14:31
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.

3 participants