-
Notifications
You must be signed in to change notification settings - Fork 18
Convert test suite from Karma/Chai/Mocha to Vitest with Playwright #48
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
- Removed karma, chai, mocha, chromium dependencies - Installed vitest@^3.2.4, @vitest/browser, and playwright - Created vitest.config.js with browser mode using chromium headless - Updated test file to use vitest imports and assertions - Renamed test.js to test.spec.js for vitest discovery - Removed karma.config.js and pretest build script - Updated package.json test script to use vitest - Updated .eslintrc.json to remove mocha environment and globals - Updated GitHub workflows to use Node 24 by default with Node 22 matrix - Added playwright install chromium step to CI workflows Co-authored-by: dgreif <[email protected]>
- Converted all test callbacks from done() to promises for Vitest compatibility - Updated .eslintrc.json to disable filename convention for test files - Removed executablePath from vitest config as per requirements - All tests pass with vitest and lint is clean Co-authored-by: dgreif <[email protected]>
- Use simpler browser config format as recommended - Remove instances array wrapper - Config now uses browser.name directly with chromium Co-authored-by: dgreif <[email protected]>
dgreif
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot please add test/__screenshots__ to the gitignore
- Add test/__screenshots__ to .gitignore - Remove Node version matrix, use only Node 24 - Use wildcard test/*.js in lint script Co-authored-by: dgreif <[email protected]>
Added test/screenshots to .gitignore in commit 6b4e2cf. |
There was a problem hiding this 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 modernizes the test infrastructure by migrating from the legacy Karma/Chai/Mocha testing stack to Vitest with browser mode and Playwright. The change simplifies the testing setup, eliminates build dependencies for tests, and aligns with modern JavaScript testing practices.
Key changes:
- Replaced Karma/Chai/Mocha with Vitest and Playwright for browser testing
- Updated test files to use Vitest's API and import from TypeScript source files directly
- Modified CI workflows to use Node 24 and install Playwright browsers
Reviewed Changes
Copilot reviewed 7 out of 9 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| vitest.config.js | New Vitest configuration replacing karma.config.js with browser mode and middleware |
| test/test.spec.js | New test file with Vitest API and promise-based assertions |
| test/test.js | Removed original Karma/Mocha test file |
| package.json | Updated dependencies and scripts for Vitest |
| .github/workflows/publish.yml | Updated to Node 24 with Playwright installation |
| .github/workflows/nodejs.yml | Updated to Node 24 with Playwright installation |
| .eslintrc.json | Removed Mocha-specific configuration and globals |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
bteng22
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice!
pat
Overview
This PR modernizes the test infrastructure by replacing Karma, Chai, and Mocha with Vitest in browser mode using Playwright. This change simplifies the testing setup, eliminates the need for a separate build step before testing (since Vitest can run TypeScript directly), and aligns with modern JavaScript testing practices.
Changes
Test Infrastructure
karma,karma-chai,karma-chrome-launcher,karma-mocha,karma-mocha-reporter,mocha,chai,chromiumvitest@^3.2.4,@vitest/browser,playwrightassertAPI to Vitest'sexpectAPIConfiguration
Created
vitest.config.jsto replacetest/karma.config.js:Test Files
test/test.js→test/test.spec.js(follows vitest naming conventions)describe,it,beforeEach,afterEach,expect../src/index.ts) instead of built dist filesassert.ok()→expect().toBe(true)/expect().toBeTruthy()assert.equal()→expect().toBe()assert.deepEqual()→expect().toEqual()assert.instanceOf()→expect().toBeInstanceOf()assert.isNull()→expect().toBeNull()assert.isFalse()→expect().toBe(false)assert.match()→expect().toMatch()done()callbacks to promises (required by Vitest)Build Scripts
Updated
package.json:pretestscript - no longer needed since Vitest runs TypeScript directlytestscript fromkarma start test/karma.config.jstovitest runlintscript to use wildcardtest/*.jsfor better flexibilityLinting
Updated
.eslintrc.json:mocha: trueenvironment settingassertandremoteFormglobals (no longer needed)CI/CD Workflows
Updated GitHub Actions workflows:
npx playwright install chromiumstepnpx playwright install chromiumstepactions/checkout@v4andactions/setup-node@v4Git Configuration
test/__screenshots__to.gitignoreto exclude Vitest browser mode screenshot artifactsTesting
All 9 tests pass successfully:
Linting and builds also pass without errors.
Running Tests Locally
To run tests locally, Playwright browsers must be installed first:
npx playwright install chromium npm testThe CI workflows automatically install the necessary browsers before running tests.
Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.