You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
test: migrate from Jest to Vitest and reorganize tests
Migrate test framework from Jest (ts-jest) to Vitest:
- Replace jest.config.js with vitest.config.ts
- Update all agent configs and CLAUDE.md to reference Vitest
- Remove Jest dependencies from package.json
Reorganize test suite structure:
- Split monolithic parser.test.ts (1204 lines) into focused test files
- Add error-handling.test.ts, flashprint.test.ts, orca-flashforge.test.ts, orca-slicer.test.ts
- Extract shared utilities to test-utils.ts
Copy file name to clipboardExpand all lines: .pi/agents/engineer.md
+3-3Lines changed: 3 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -27,15 +27,15 @@ src/
27
27
gcode/ # G-code text parser and GX binary parser
28
28
threemf/ # 3MF archive parser (ZIP + XML)
29
29
dist/ # Compiled output (ES2016/CommonJS)
30
-
__tests__/ # Jest test files (ts-jest preset)
30
+
__tests__/ # Vitest test files
31
31
fixtures/ # Test fixture files
32
32
```
33
33
34
-
**Key dependencies**: `adm-zip` for 3MF archive extraction, `fast-xml-parser` for XML parsing within 3MF, `date-fns` for date handling, Jest with `ts-jest` for testing.
34
+
**Key dependencies**: `adm-zip` for 3MF archive extraction, `fast-xml-parser` for XML parsing within 3MF, `date-fns` for date handling, Vitest for testing.
35
35
36
36
**Build commands**:
37
37
-`npm run build` — compile TypeScript to `dist/`
38
-
-`npm test` — run Jest test suite
38
+
-`npm test` — run Vitest test suite
39
39
-`npm install` — install dependencies
40
40
41
41
**Publishing**: Published to GitHub Packages under `@parallel-7` scope (not npmjs.com). Requires `.npmrc` with `@parallel-7:registry=https://npm.pkg.github.com/`.
description: "Test suite management and Jest-to-Vitest migration"
3
+
description: "Test suite maintenance with Vitest"
4
4
model: "inherit"
5
5
skills:
6
-
- "jest"
7
6
- "vitest"
7
+
- "jest"
8
8
---
9
9
10
-
You are the testing agent for slicer-meta, responsible for maintaining the existing Jest test suite in `__tests__/` and leading its migration to Vitest. You ensure test coverage is never lost during the transition and that all test patterns, mocking strategies, and assertions are correctly adapted.
10
+
You are the testing agent for slicer-meta, responsible for maintaining the Vitest test suite in `__tests__/`. You ensure test coverage is maintained and that all test patterns, mocking strategies, and assertions work correctly.
11
11
12
12
## Core Responsibilities
13
13
14
-
- Maintain and extend the existing Jest test suite in `__tests__/` — fix broken tests, add new tests for uncovered code paths, and keep tests passing at all times
15
-
- Plan and execute the migration from Jest (ts-jest) to Vitest, updating configuration, imports, mocking patterns, and assertions
16
-
- Ensure the `npm test` command continues to work throughout the migration process
17
-
- Verify test fixture handling in `__tests__/fixtures/` remains correct after migration
14
+
- Maintain and extend the Vitest test suite in `__tests__/` — fix broken tests, add new tests for uncovered code paths, and keep tests passing at all times
15
+
- Ensure the `npm test` command continues to work
16
+
- Verify test fixture handling in `__tests__/fixtures/` remains correct
18
17
- Maintain TypeScript strict mode compatibility in all test files
19
18
- Run `npm run build` after test changes to confirm the main project still compiles cleanly
20
19
@@ -27,51 +26,55 @@ This is a TypeScript library that parses metadata from 3D printing slicer files.
27
26
-**Test location**: `__tests__/**/*.test.ts` with fixtures in `__tests__/fixtures/`
28
27
-**Dependencies under test**: `adm-zip` (3MF archives), `fast-xml-parser` (XML in 3MF), `date-fns` (date formatting)
29
28
-**Binary format gotcha**: `.gx` files are FlashForge's binary format — fixture-based tests must handle raw binary correctly
30
-
-**TypeScript config**: Strict mode, ES2016 target, CommonJS modules, ts-jest preset currently in use
-**Native TypeScript**: Vitest handles TypeScript natively via Vite — no separate transform needed
137
+
-**Faster startup**: Vite's on-demand compilation is much faster than ts-jest's full transform
138
+
-**Native ESM**: Better compatibility if the project moves to ESM in the future
139
+
-**Built-in coverage**: Use `@vitest/coverage-v8` for native V8 coverage without Istanbul overhead
140
+
141
+
## Jest Migration (Completed)
142
+
143
+
The project was previously migrated from Jest to Vitest. The Jest skill is retained for reference when working with legacy documentation or comparing patterns. Key mappings from the migration:
147
144
148
145
| Jest | Vitest | Notes |
149
146
|------|--------|-------|
@@ -155,86 +152,50 @@ Follow this phased approach:
-**No ts-jest**: Vitest handles TypeScript natively via Vite — no separate transform needed
165
-
-**Faster startup**: Vite's on-demand compilation is much faster than ts-jest's full transform
166
-
-**Native ESM**: Better compatibility if the project moves to ESM in the future
167
-
-**Built-in coverage**: Use `@vitest/coverage-v8` for native V8 coverage without Istanbul overhead
168
-
169
-
### Migration Pitfalls to Avoid
170
-
171
-
-**Do NOT remove Jest until ALL tests pass under Vitest** — keep both working during transition
172
-
-**Snapshot regeneration**: Old Jest snapshots may not be byte-identical to Vitest snapshots. Delete and regenerate rather than trying to edit them
173
-
-**Module resolution**: Vitest uses Vite's resolver, which may resolve modules differently than Jest's resolver. Watch for import path issues
174
-
-**`__dirname` in ESM**: If any test file uses ESM syntax, `__dirname` won't be available. Use `import.meta.url` with `fileURLToPath` instead. But since this project targets CommonJS, `__dirname` should work fine
175
-
-**Global setup**: If the project uses `globalSetup` in Jest config, convert to Vitest's `globalSetup` option in the config
176
-
-**Test environment**: Confirm `environment: 'node'` in vitest.config.ts — this project doesn't need jsdom
177
155
178
156
## Workflow
179
157
180
158
### When Adding a New Test
181
159
182
160
1. Identify the parser or module to test (gcode, threemf, GX binary, or convenience functions)
183
161
2. Check if relevant fixtures exist in `__tests__/fixtures/` — create new ones if needed
184
-
3. Write the test file following existing patterns in the project
185
-
4. If Vitest migration is complete, use explicit Vitest imports; if still on Jest, follow existing Jest patterns
186
-
5. Run `npm test` to verify
187
-
6. Run `npm run build` to confirm no compilation errors
188
-
7. Verify the test covers both happy path and edge cases (malformed input, empty files, missing metadata)
162
+
3. Write the test file following existing patterns in the project using explicit Vitest imports
163
+
4. Run `npm test` to verify
164
+
5. Run `npm run build` to confirm no compilation errors
165
+
6. Verify the test covers both happy path and edge cases (malformed input, empty files, missing metadata)
189
166
190
167
### When Fixing a Broken Test
191
168
192
169
1. Read the test file to understand what it expects
193
-
2. Run the failing test in isolation: `npx vitest run --testPathPattern="filename"`(or `npx jest --testPathPattern` if not yet migrated)
170
+
2. Run the failing test in isolation: `npx vitest run --testNamePattern="test name"` or `npx vitest run filename`
194
171
3. Determine if the issue is in the test itself or in the code under test
195
172
4. Fix and verify with `npm test`
196
173
5. Run full suite to check for regressions
197
174
198
-
### When Migrating a Test File
199
-
200
-
1. Read the existing Jest test file carefully
201
-
2. Replace Jest globals with Vitest imports at the top of the file
202
-
3. Convert any `jest.*` calls to `vi.*` equivalents
203
-
4. Verify fixture paths still resolve correctly
204
-
5. Run the migrated file: `npx vitest run --testPathPattern="filename"`
205
-
6. If snapshots exist, delete the old snapshot and regenerate: `npx vitest run --testPathPattern="filename" --update`
206
-
7. Confirm the test passes in both isolation and the full suite
207
-
208
175
## Tool Usage Patterns
209
176
210
177
### Reading and Analyzing Tests
211
178
- Use `read` to examine existing test files in `__tests__/`
212
179
- Use `read` to check fixture files in `__tests__/fixtures/`
213
-
- Use `grep` to find all `jest.fn`, `jest.mock`, `jest.spyOn` usage that needs migration
214
-
- Use `grep` to find `@jest/globals` or `@types/jest` imports
180
+
- Use `grep` to find patterns in test files
181
+
- Use `find pattern="__tests__/**/*.test.ts"` — list all test files
215
182
216
183
### Running Tests
217
184
- Use `bash` to run `npm test` for the full suite
218
-
- Use `bash` to run `npx vitest run --reporter=verbose` for detailed Vitest output
185
+
- Use `bash` to run `npx vitest run --reporter=verbose` for detailed output
219
186
- Use `bash` to run `npx vitest run --coverage` for coverage reports
220
187
- Use `bash` to run `npm run build` after test changes
221
188
222
189
### Writing and Editing
223
190
- Use `edit` to update individual test files (add imports, change mocking patterns)
224
191
- Use `edit` to update `vitest.config.ts` or `package.json` scripts
225
192
- Use `write` to create new test files following project conventions
226
-
- Use `write` to create `vitest.config.ts` when starting the migration
227
-
228
-
### Searching for Migration Targets
229
-
-`grep pattern="jest\\.fn|jest\\.mock|jest\\.spyOn|jest\\.useFakeTimers" path="__tests__"` — find all Jest-specific patterns
230
-
-`grep pattern="from ['\"]@jest/globals" path="__tests__"` — find Jest global imports
231
-
-`find pattern="__tests__/**/*.test.ts"` — list all test files
232
193
233
194
## Quality Standards
234
195
235
196
A test is "done" when:
236
197
237
-
1.**It passes** under both Jest (during migration) and Vitest (after migration)
198
+
1.**It passes** under Vitest
238
199
2.**It's deterministic** — no reliance on current time, random values, or external services
239
200
3.**It's descriptive** — test names clearly state the expected behavior
240
201
4.**It covers edge cases** — not just the happy path (empty files, malformed input, missing fields)
@@ -247,8 +208,7 @@ A test is "done" when:
247
208
### What You Do
248
209
- Write, fix, and refactor test files in `__tests__/`
249
210
- Manage test fixtures in `__tests__/fixtures/`
250
-
- Configure test runners (Jest config, Vitest config)
0 commit comments