Skip to content

Conversation

@cte
Copy link
Collaborator

@cte cte commented Jun 11, 2025

Description

This ports ~700 tests from jest to vitest. There are still 1,300 remaining. I can do another pass of the prompt and not tell Roo Code to give up so easily.

Roo Code prompt:

Many of the tests under src/ use jest, but we'd like to use vitest instead. We currently already have the infrastructure we need, and if you name your test foo.spec.ts instead of foo.test.ts then it will use vitest instead of jest. Let's systematically go through each jest test file and convert it to vitest. We should run the tests to verify that we've ported correctly. If you struggle to get a test to pass then let's just skip it; this will be a first pass to get the low hanging fruit. Start by looking at the existing vitest examples.

You should read the files yourself to understand how to write vitest tests and then spawn subtasks for each jest test that we want to convert.


Important

Convert Jest tests to Vitest across multiple modules, updating mocks and configurations for compatibility.

  • Test Conversion:
    • Convert Jest tests to Vitest in openrouter.spec.ts, requesty.spec.ts, vertex.spec.ts, reasoning.spec.ts, vscode-lm-format.spec.ts, cache-strategy.spec.ts, diagnostics.spec.ts, line-counter.spec.ts, ShadowCheckpointService.spec.ts, excludes.spec.ts, openai-compatible.spec.ts, parser.spec.ts, scanner.spec.ts, qdrant-client.spec.ts, enhance-prompt.spec.ts, git.spec.ts, outputChannelLogger.spec.ts, xml.spec.ts, CompactLogger.spec.ts.
    • Replace jest with vitest for mocking and assertions.
    • Update mock implementations to use vitest.fn() and vitest.mock().
    • Adjust test configurations in vitest.config.ts to include setup files and disable watch mode.
  • Mocking:
    • Add vitest-vscode-mock.js to mock VSCode API for Vitest tests.
    • Update path alias in vitest.config.ts to use the new VSCode mock file.
  • Miscellaneous:
    • Ensure all tests are compatible with Vitest's API and behavior.
    • Maintain original test logic and coverage while adapting to Vitest.

This description was created by Ellipsis for 7ab2027. You can customize this summary. It will automatically update as commits are pushed.

@cte cte requested review from jr and mrubens as code owners June 11, 2025 19:56
@dosubot dosubot bot added the size:XL This PR changes 500-999 lines, ignoring generated files. label Jun 11, 2025
@hannesrudolph hannesrudolph added the Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. label Jun 11, 2025
cte and others added 2 commits June 11, 2025 13:04
Co-authored-by: ellipsis-dev[bot] <65095814+ellipsis-dev[bot]@users.noreply.github.com>
Co-authored-by: ellipsis-dev[bot] <65095814+ellipsis-dev[bot]@users.noreply.github.com>
@jr
Copy link
Collaborator

jr commented Jun 11, 2025

For the glama spec I see output like

roo-cline:test: stderr | api/providers/__tests__/glama.spec.ts > GlamaHandler > createMessage > should handle streaming responsese:test: 
roo-cline:test: Error fetching Glama completion details AxiosError: Request failed with status code 500
roo-cline:test:     at settle (file:///Users/john/repos/roo-code-experiments/Roo-Code/node_modules/.pnpm/[email protected]/node_modules/axios/lib/core/settle.js:19:12)
roo-cline:test:     at Unzip.handleStreamEnd (file:///Users/john/repos/roo-code-experiments/Roo-Code/node_modules/.pnpm/[email protected]/node_modules/axios/lib/adapters/http.js:599:11)
roo-cline:test:     at Unzip.emit (node:events:536:35)
roo-cline:test:     at endReadableNT (node:internal/streams/readable:1698:12)
roo-cline:test:     at processTicksAndRejections (node:internal/process/task_queues:82:21)
roo-cline:test:     at Axios.request (file:///Users/john/repos/roo-code-experiments/Roo-Code/node_modules/.pnpm/[email protected]/node_modules/axios/lib/core/Axios.js:45:41)
roo-cline:test:     at processTicksAndRejections (node:internal/process/task_queues:95:5)
roo-cline:test:     at GlamaHandler.createMessage (/Users/john/repos/roo-code-experiments/Roo-Code/src/api/providers/glama.ts:92:22)est: 
roo-cline:test:     at /Users/john/repos/roo-code-experiments/Roo-Code/src/api/providers/__tests__/glama.spec.ts:140:21
roo-cline:test:     at file:///Users/john/repos/roo-code-experiments/Roo-Code/node_modules/.pnpm/@[email protected]/node_modules/@vitest/runner/dist/index.js:596:20 {
roo-cline:test:   code: 'ERR_BAD_RESPONSE',
roo-cline:test:   config: {
roo-cline:test:     transitional: {
roo-cline:test:       silentJSONParsing: true,
roo-cline:test:       forcedJSONParsing: true,
roo-cline:test:       clarifyTimeoutError: false
roo-cline:test:     },
roo-cline:test:     adapter: [ 'xhr', 'http', 'fetch' ],
roo-cline:test:     transformRequest: [ [Function: transformRequest] ],
roo-cline:test:     transformResponse: [ [Function: transformResponse] ],
roo-cline:test:     timeout: 0,
roo-cline:test:     xsrfCookieName: 'XSRF-TOKEN',
roo-cline:test:     xsrfHeaderName: 'X-XSRF-TOKEN',

that makes it look like it might be making a real request. I don't see that output in the jest version, but I'm not sure if that means:

  1. Something about mocking is working differently and a real request slipped through
  2. jest just wasn't displaying those log messages

@cte
Copy link
Collaborator Author

cte commented Jun 11, 2025

that makes it look like it might be making a real request. I don't see that output in the jest version, but I'm not sure if that means:

  1. Something about mocking is working differently and a real request slipped through
  2. jest just wasn't displaying those log messages

Jest is suppressing this particular error, and we're not mocking it, but it is disallowed since we've configured nock for jest: https://github.com/RooCodeInc/Roo-Code/blob/main/src/__mocks__/jest.setup.ts#L3

We'll want to do the same for vitest; good catch.

@cte
Copy link
Collaborator Author

cte commented Jun 11, 2025

@jr - 7ab2027 (#4568)

@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Jun 11, 2025
@cte cte merged commit 395f55b into main Jun 11, 2025
13 checks passed
@cte cte deleted the cte/vitest-conversion branch June 11, 2025 21:48
@github-project-automation github-project-automation bot moved this from New to Done in Roo Code Roadmap Jun 11, 2025
@github-project-automation github-project-automation bot moved this from Triage to Done in Roo Code Roadmap Jun 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. lgtm This PR has been approved by a maintainer size:XL This PR changes 500-999 lines, ignoring generated files.

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

4 participants