···11---
22name: vitest-test-writer
33-description: "Use this agent when the user needs to write comprehensive tests for Vitest features. This includes unit tests for individual functions, integration tests for CLI functionality, and browser mode tests. The agent should be invoked when implementing new features that require test coverage, fixing bugs that need regression tests, or expanding test coverage for existing functionality.\\n\\nExamples:\\n\\n<example>\\nContext: User has just implemented a new utility function in the codebase.\\nuser: \"I just added a new parseConfig function to the config package\"\\nassistant: \"I see you've added a new function. Let me use the vitest-test-writer agent to create comprehensive tests for it.\"\\n<commentary>\\nSince a new function was added, use the Task tool to launch the vitest-test-writer agent to write unit tests in test/core.\\n</commentary>\\n</example>\\n\\n<example>\\nContext: User is working on a CLI feature.\\nuser: \"Please add a --json flag to the list command\"\\nassistant: \"I'll implement the --json flag for the list command.\"\\n<function call to implement the feature>\\nassistant: \"Now let me use the vitest-test-writer agent to write integration tests for this new CLI flag.\"\\n<commentary>\\nSince a CLI feature was implemented, use the Task tool to launch the vitest-test-writer agent to write integration tests in test/cli using runInlineTests.\\n</commentary>\\n</example>\\n\\n<example>\\nContext: User wants to ensure a feature works in both normal and browser modes.\\nuser: \"Can you write tests for the new snapshot feature?\"\\nassistant: \"I'll use the vitest-test-writer agent to write comprehensive tests for the snapshot feature, covering both normal and browser modes.\"\\n<commentary>\\nSince the feature needs testing in multiple modes, use the Task tool to launch the vitest-test-writer agent to write tests in test/cli (for features supporting both modes).\\n</commentary>\\n</example>"
33+description: "Use this agent when the user needs to write comprehensive tests for Vitest features. This includes unit tests for individual functions, integration tests for CLI functionality, and browser mode tests. The agent should be invoked when implementing new features that require test coverage, fixing bugs that need regression tests, or expanding test coverage for existing functionality.\\n\\nExamples:\\n\\n<example>\\nContext: User has just implemented a new utility function in the codebase.\\nuser: \"I just added a new parseConfig function to the config package\"\\nassistant: \"I see you've added a new function. Let me use the vitest-test-writer agent to create comprehensive tests for it.\"\\n<commentary>\\nSince a new function was added, use the Task tool to launch the vitest-test-writer agent to write unit tests in test/unit.\\n</commentary>\\n</example>\\n\\n<example>\\nContext: User is working on a CLI feature.\\nuser: \"Please add a --json flag to the list command\"\\nassistant: \"I'll implement the --json flag for the list command.\"\\n<function call to implement the feature>\\nassistant: \"Now let me use the vitest-test-writer agent to write integration tests for this new CLI flag.\"\\n<commentary>\\nSince a CLI feature was implemented, use the Task tool to launch the vitest-test-writer agent to write integration tests in test/e2e using runInlineTests.\\n</commentary>\\n</example>\\n\\n<example>\\nContext: User wants to ensure a feature works in both normal and browser modes.\\nuser: \"Can you write tests for the new snapshot feature?\"\\nassistant: \"I'll use the vitest-test-writer agent to write comprehensive tests for the snapshot feature, covering both normal and browser modes.\"\\n<commentary>\\nSince the feature needs testing in multiple modes, use the Task tool to launch the vitest-test-writer agent to write tests in test/e2e (for features supporting both modes).\\n</commentary>\\n</example>"
44model: opus
55color: green
66---
···13131414## Test Location Rules
15151616-- **Unit tests**: Place in `test/core/`. These test individual functions by importing them directly, regardless of which package defines them.
1717-- **Integration tests**: Place in `test/cli/`. These test CLI functionality and features that require running Vitest as a process.
1818-- **Browser mode tests**: Place in `test/browser/`. However, if a feature supports both normal tests AND browser tests, place the tests in `test/cli/`.
1616+- **Unit tests**: Place in `test/unit/`. These test individual functions by importing them directly, regardless of which package defines them.
1717+- **Integration tests**: Place in `test/e2e/`. These test CLI functionality and features that require running Vitest as a process.
1818+- **Browser mode tests**: Place in `test/browser/`. However, if a feature supports both normal tests AND browser tests, place the tests in `test/e2e/`.
19192020## Testing Patterns You Must Follow
2121···51515252## Writing Unit Tests
53535454-For unit tests in `test/core/`:
5454+For unit tests in `test/unit/`:
55551. Import the function directly from its source package
56562. Test pure functionality without process spawning
57573. Cover edge cases, error conditions, and typical usage
···59596060## Writing Integration Tests
61616262-For integration tests in `test/cli/`:
6262+For integration tests in `test/e2e/`:
63631. Use `runInlineTests` to define test scenarios
64642. Create realistic test file content
65653. Validate both stderr and the test results structure
···50505151 const { setTimeout, clearTimeout } = getSafeTimers()
52525353- // this function name is used to filter error in test/cli/test/fails.test.ts
5353+ // this function name is used to filter error in test/e2e/test/fails.test.ts
5454 return (function runWithTimeout(...args: T extends (...args: infer A) => any ? A : never) {
5555 const startTime = now()
5656 const runner = getRunner()
+1-1
packages/ui/explorer.md
···7272It is using a new approach to handle the tree list, now we have a separated vue shallow ref for entries in the ui ([uiEntries in composables/explorer/state.ts](client/composables/explorer/state.ts)), and the WebSocket state using vue shallow ref for both, `idsMap` and `filesMap`, while keeping the state itself with Vue reactive.
7373Now we are able to update the tree list only when the entries are updated and not when the WebSocket state is updated, which is a huge performance improvement.
74747575-Some numbers running `test/core` with Vitest UI (162 files with 3 workspaces: 5100+ tests) in a `i7-12700H` laptop:
7575+Some numbers running `test/unit` with Vitest UI (162 files with 3 workspaces: 5100+ tests) in a `i7-12700H` laptop:
7676- tree list: after server finishing running the tests, Vitest UI took ~1 minute to finish rendering the full tree (~150MB of memory usage)
7777- explorer: Vitest UI finishing rendering the full tree before the server reporter shows the tests summary (~10MB of memory usage)
7878
···1313## cli
14141515If you are testing a complex interaction, place your tests here.
1616-Type-focused fixtures live under `test/cli/dts/`.
1616+Type-focused fixtures live under `test/e2e/dts/`.
17171818## browser
1919
···106106107107 ##### \`flaky/math.spec.ts\` (5 flaky tests)
108108109109- - [\`should multiply numbers correctly\`](https://github.com/owner/repo/blob/aaa/test/cli/fixtures/reporters/github-actions/flaky/math.spec.ts) (**passed on retry 5 out of 5**)
110110- - [\`should handle edge cases\`](https://github.com/owner/repo/blob/aaa/test/cli/fixtures/reporters/github-actions/flaky/math.spec.ts) (**passed on retry 4 out of 5**)
111111- - [\`should validate input properly\`](https://github.com/owner/repo/blob/aaa/test/cli/fixtures/reporters/github-actions/flaky/math.spec.ts) (**passed on retry 4 out of 5**)
112112- - [\`should divide numbers correctly\`](https://github.com/owner/repo/blob/aaa/test/cli/fixtures/reporters/github-actions/flaky/math.spec.ts) (passed on retry 2 out of 5)
113113- - [\`should subtract numbers correctly\`](https://github.com/owner/repo/blob/aaa/test/cli/fixtures/reporters/github-actions/flaky/math.spec.ts) (passed on retry 1 out of 5)
109109+ - [\`should multiply numbers correctly\`](https://github.com/owner/repo/blob/aaa/test/e2e/fixtures/reporters/github-actions/flaky/math.spec.ts) (**passed on retry 5 out of 5**)
110110+ - [\`should handle edge cases\`](https://github.com/owner/repo/blob/aaa/test/e2e/fixtures/reporters/github-actions/flaky/math.spec.ts) (**passed on retry 4 out of 5**)
111111+ - [\`should validate input properly\`](https://github.com/owner/repo/blob/aaa/test/e2e/fixtures/reporters/github-actions/flaky/math.spec.ts) (**passed on retry 4 out of 5**)
112112+ - [\`should divide numbers correctly\`](https://github.com/owner/repo/blob/aaa/test/e2e/fixtures/reporters/github-actions/flaky/math.spec.ts) (passed on retry 2 out of 5)
113113+ - [\`should subtract numbers correctly\`](https://github.com/owner/repo/blob/aaa/test/e2e/fixtures/reporters/github-actions/flaky/math.spec.ts) (passed on retry 1 out of 5)
114114115115 ##### \`flaky/network.spec.ts\` (3 flaky tests)
116116117117- - [\`network > should handle network timeouts gracefully\`](https://github.com/owner/repo/blob/aaa/test/cli/fixtures/reporters/github-actions/flaky/network.spec.ts) (**passed on retry 4 out of 4**)
118118- - [\`network > should fetch user data from API\`](https://github.com/owner/repo/blob/aaa/test/cli/fixtures/reporters/github-actions/flaky/network.spec.ts) (passed on retry 2 out of 3)
119119- - [\`network > should retry failed requests\`](https://github.com/owner/repo/blob/aaa/test/cli/fixtures/reporters/github-actions/flaky/network.spec.ts) (passed on retry 1 out of 3)
117117+ - [\`network > should handle network timeouts gracefully\`](https://github.com/owner/repo/blob/aaa/test/e2e/fixtures/reporters/github-actions/flaky/network.spec.ts) (**passed on retry 4 out of 4**)
118118+ - [\`network > should fetch user data from API\`](https://github.com/owner/repo/blob/aaa/test/e2e/fixtures/reporters/github-actions/flaky/network.spec.ts) (passed on retry 2 out of 3)
119119+ - [\`network > should retry failed requests\`](https://github.com/owner/repo/blob/aaa/test/e2e/fixtures/reporters/github-actions/flaky/network.spec.ts) (passed on retry 1 out of 3)
120120 "
121121 `)
122122 })
···88import { beforeEach, expect, test } from 'vitest'
99import { version } from 'vitest/package.json'
1010import { writeBlob } from 'vitest/src/node/reporters/blob.js'
1111-import { getModuleGraph } from '../../../../packages/vitest/src/utils/graph'
1111+import { getModuleGraph } from 'vitest/src/utils/graph.js'
12121313// always relative to CWD because it's used only from the CLI,
1414// so we need to correctly resolve it here
···11+/* eslint-disable no-console */
22+13import type { afterAll, beforeAll, ExpectStatic, expectTypeOf as ExpectTypeOfFn, SuiteAPI, TestAPI } from 'vitest'
24import type { ViteUserConfig } from 'vitest/config'
35import type { TestSpecification, TestUserConfig } from 'vitest/node'