Skip to content

test: setup Vitest with vscode mocks for unit testing - #1

Open
taj54 wants to merge 1 commit into
Irandoust:mainfrom
taj54:main
Open

test: setup Vitest with vscode mocks for unit testing#1
taj54 wants to merge 1 commit into
Irandoust:mainfrom
taj54:main

Conversation

@taj54

@taj54 taj54 commented Jul 19, 2025

Copy link
Copy Markdown

No description provided.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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 the test npm script to vitest, and bumps @types/node from 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.json to explicitly include src/**/* and exclude tests and dist.

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.

Comment thread vitest.config.ts

export default defineConfig({
test: {
include: ['tests/*.test.ts'],
Comment on lines +63 to +64
hostsManager = new HostsManager(mockShellExecutor);
vi.clearAllMocks();
Comment thread tests/utils.test.ts
Comment on lines +77 to +80
it('should return null for comment lines', () => {
expect(Utils.parseHostsLine('# 127.0.0.1 localhost')).toBeNull();
});

Comment thread package.json
"package": "vsce package"
},
"devDependencies": {
"@types/node": "^20.0.0",
Comment thread package.json
"pretest": "npm run compile && npm run lint",
"lint": "eslint src --ext ts",
"test": "node ./out/test/runTest.js",
"test": "vitest",
@Irandoust

Copy link
Copy Markdown
Owner

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.

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