Convert from Karma/Chai/Mocha to Vitest with Playwright browser mode#41
Convert from Karma/Chai/Mocha to Vitest with Playwright browser mode#41
Conversation
Co-authored-by: dgreif <3026298+dgreif@users.noreply.github.com>
.github/workflows/nodejs.yml
Outdated
| strategy: | ||
| matrix: | ||
| node-version: [22, 24] |
There was a problem hiding this comment.
Removed the matrix. Now using Node 24 only. Fixed in 67e5336
test/.eslintrc.json
Outdated
| "globals": { | ||
| "assert": true | ||
| "describe": "readonly", | ||
| "it": "readonly", | ||
| "expect": "readonly" | ||
| }, |
There was a problem hiding this comment.
@copilot we shouldn't need these since we import from the vitest package
There was a problem hiding this comment.
Removed the globals since they're imported from vitest. Fixed in 67e5336
test/setup.js
Outdated
There was a problem hiding this comment.
@copilot this file duplicates a lot of what is in test-runner.js. Remove test-runner.js and update the tests to simply call a function which starts up the socket server in beforeAll and shuts it down in afterAll. Update the package.json to simply run vitest run instead of test-runner.js
There was a problem hiding this comment.
Removed test-runner.js and test/setup.js. Created a simpler shell script (scripts/test-with-server.sh) that starts the WebSocket server in the background and runs vitest. Updated package.json to run vitest run via this script. Fixed in 67e5336
There was a problem hiding this comment.
@copilot Ok, I now see that we need to run the websocket server in Node, not in the browser. I like the bash file you created, but please move the server JS portion of it into test/websocket-server.js
There was a problem hiding this comment.
Moved the WebSocket server code into test/websocket-server.js. The bash script now simply starts that file as a background process. Fixed in 22af8f3
vitest.config.ts
Outdated
| }, | ||
| ], | ||
| }, | ||
| include: ['test/**/test.js'], |
There was a problem hiding this comment.
Changed pattern to test/test*.js. Fixed in 67e5336
Co-authored-by: dgreif <3026298+dgreif@users.noreply.github.com>
Co-authored-by: dgreif <3026298+dgreif@users.noreply.github.com>
There was a problem hiding this comment.
Pull Request Overview
This PR converts the test setup from Karma/Chai/Mocha to Vitest with Playwright browser mode, streamlining the testing infrastructure while maintaining all existing test functionality.
Key changes:
- Migrated to Vitest ^3.2.4 with Playwright browser mode using Chromium headless
- Updated test assertions from Chai to Vitest's expect API
- Simplified test execution by removing the pretest build step and using direct TypeScript imports
- Updated CI workflows to use Node 24 and include Playwright installation
Reviewed Changes
Copilot reviewed 9 out of 11 changed files in this pull request and generated 9 comments.
Show a summary per file
| File | Description |
|---|---|
| vitest.config.ts | New Vitest configuration with Playwright browser mode and Chromium setup |
| test/websocket-server.js | Extracted WebSocket server code from karma config for standalone test server |
| test/test.js | Updated test file with Vitest imports and expect assertions replacing Chai |
| test/.eslintrc.json | Removed Mocha environment and globals, added module source type |
| scripts/test-with-server.sh | New script to manage WebSocket server lifecycle during testing |
| package.json | Removed Karma/Chai/Mocha dependencies, added Vitest and Playwright, updated test script |
| karma.config.cjs | Removed Karma configuration file |
| .github/workflows/publish.yml | Updated to Node 24 and added Playwright installation |
| .github/workflows/nodejs.yml | Updated to Node 24 and added Playwright installation |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
Plan: Convert from Karma/Chai/Mocha to Vitest with Playwright
All tasks completed successfully. Tests are passing with vitest in browser mode using Playwright chromium.
Original prompt
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.