test: setup Vitest with vscode mocks for unit testing - #1
Conversation
There was a problem hiding this comment.
Pull request overview
Introduces Vitest as the unit-testing framework for the extension, replacing the previous @vscode/test-electron runner script. Adds initial unit tests for Utils, ShellExecutor, and HostsManager with mocked vscode, fs, and util.promisify, and adjusts the TypeScript configuration so tests live outside the compiled extension build.
Changes:
- Adds
vitest.config.ts, switches thetestnpm script tovitest, and bumps@types/nodefrom 16.x to ^20. - Adds three new test files (
utils.test.ts,shellExecutor.test.ts,hostsManager.test.ts) covering parsing, validation, sudo flow, shell info, file IO, and host-entry manipulation. - Updates
tsconfig.jsonto explicitlyincludesrc/**/*andexcludetestsanddist.
Reviewed changes
Copilot reviewed 5 out of 7 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| vitest.config.ts | New Vitest config restricting test discovery to top-level tests/*.test.ts. |
| tsconfig.json | Narrows compilation scope to src/**/* and excludes tests/dist. |
| package.json | Switches test script to vitest, adds vitest devDependency, bumps @types/node to ^20. |
| package-lock.json | Lockfile updates for the new Vitest/esbuild/rollup dependency tree and Node 20 typings. |
| tests/utils.test.ts | Unit tests for Utils static helpers with mocked fs and vscode. |
| tests/shellExecutor.test.ts | Tests for ShellExecutor using mocked util.promisify and vscode. |
| tests/hostsManager.test.ts | Tests for HostsManager parsing/read/write with mocked fs, vscode, and a stubbed ShellExecutor. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
|
||
| export default defineConfig({ | ||
| test: { | ||
| include: ['tests/*.test.ts'], |
| hostsManager = new HostsManager(mockShellExecutor); | ||
| vi.clearAllMocks(); |
| it('should return null for comment lines', () => { | ||
| expect(Utils.parseHostsLine('# 127.0.0.1 localhost')).toBeNull(); | ||
| }); | ||
|
|
| "package": "vsce package" | ||
| }, | ||
| "devDependencies": { | ||
| "@types/node": "^20.0.0", |
| "pretest": "npm run compile && npm run lint", | ||
| "lint": "eslint src --ext ts", | ||
| "test": "node ./out/test/runTest.js", | ||
| "test": "vitest", |
|
Thank you so much for your collaboration. Unfortunately, I didn't have much time to maintain the codebase and review the PR. Please resolve Copilot comments and update the description so we can merge it. I'm gonna add some PR instructions for the repo to it will be clearer for further collaboration. |
No description provided.