chore: migrate from Jest to Vitest and upgrade TypeScript to 5.9#236
chore: migrate from Jest to Vitest and upgrade TypeScript to 5.9#236
Conversation
Replace Jest 27 + ts-jest with Vitest 4 for native ESM support and modern test tooling. Upgrade TypeScript from 4.4 to 5.9. Additional fixes: - Replace `tempy` with Node.js built-ins in source code to fix ESM runtime error when consuming `@trapezedev/project` via `require()` - Fix XML fragment parsing for `@xmldom/xmldom` 0.9.9 strict mode by wrapping fragments and propagating namespace declarations - Change `const enum` to `enum` for esbuild compatibility - Add `types` array to tsconfigs to exclude hoisted `@types/mdx` - Replace `via.placeholder.com` with `picsum.photos` in tests
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
There was a problem hiding this comment.
Pull request overview
Migrates the monorepo’s unit test runner from Jest/ts-jest to Vitest and upgrades TypeScript to 5.9, while also addressing ESM/runtime compatibility issues and XML parsing strictness changes.
Changes:
- Replace Jest config/scripts with Vitest configs and update affected tests.
- Upgrade TypeScript to 5.9 and adjust tsconfig
typesto avoid unwanted hoisted typings. - Improve XML fragment injection/parsing (multi-root fragments + namespace propagation) and remove
tempyusage from Gradle temp-file creation.
Reviewed changes
Copilot reviewed 14 out of 15 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/project/vitest.config.ts | Adds Vitest configuration for the @trapezedev/project package. |
| packages/project/tsconfig.json | Adds explicit types list to control global typings resolution. |
| packages/project/test/xml-file.test.ts | Minor test adjustment to use replace with regex for whitespace normalization. |
| packages/project/test/project.ios.test.ts | Updates external image URL used in copy-from-URL test. |
| packages/project/test/project.android.test.ts | Updates external image URLs used in copy-from-URL tests. |
| packages/project/src/xml.ts | Updates XML fragment injection to support multi-root fragments + namespace propagation. |
| packages/project/src/util/xml.ts | Introduces parseXmlFragment helper for fragment parsing via wrapper root. |
| packages/project/src/definitions.ts | Replaces const enum with enum for esbuild compatibility. |
| packages/project/src/android/gradle-file.ts | Replaces tempy temp file path generation with Node temp-dir primitives. |
| packages/project/package.json | Switches test script to vitest run and updates dev dependencies (TS/Vitest). |
| packages/configure/vitest.config.ts | Adds Vitest configuration for the @trapezedev/configure package. |
| packages/configure/tsconfig.json | Adds explicit types list to control global typings resolution. |
| packages/configure/test/ctx.test.ts | Updates a Jest API usage to the Vitest equivalent (vi.resetModules). |
| packages/configure/package.json | Switches test script to vitest run and updates dev dependencies (TS/Vitest). |
| package-lock.json | Locks new Vitest/Vite/TypeScript dependency graph after migration/upgrades. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
|
||
| nodes.forEach(n => | ||
| Array.prototype.forEach.call(docNodes, d => n.appendChild(d)), | ||
| docNodes.forEach(d => n.appendChild(d)), |
There was a problem hiding this comment.
injectFragment appends the same Node instances into every matched target. Because appendChild moves a node, only the last matched node will end up containing the injected fragment (despite the docstring saying each node should get it). Clone/import the fragment nodes per target (e.g., deep-clone each node for each n) or re-parse the fragment for each target.
| docNodes.forEach(d => n.appendChild(d)), | |
| docNodes.forEach(d => n.appendChild(d.cloneNode(true))), |
| for (const attr in rootNode.attributes) { | ||
| const attribute = rootNode.attributes[attr]; | ||
| if (attribute.name?.startsWith('xmlns')) { | ||
| attrs.push(`${attribute.name}="${attribute.value}"`); | ||
| } |
There was a problem hiding this comment.
rootNode.attributes is a NamedNodeMap; iterating it with for...in can pick up non-attribute enumerable properties and is brittle across DOM implementations. Prefer iterating by index (for (let i = 0; i < rootNode.attributes.length; i++) and item(i)) when collecting xmlns* attributes.
| if (!this.tempFile) { | ||
| // If the temp file doesn't exist yet, create it and write the current file source to it | ||
| const gradleContents = await this.getGradleSource(); | ||
| this.tempFile = temporaryFile({ extension: 'gradle' }); | ||
| this.tempFile = join(mkdtempSync(join(os.tmpdir(), 'trapeze-')), 'temp.gradle'); | ||
| await writeFile(this.tempFile, gradleContents); |
There was a problem hiding this comment.
This now creates a real temporary directory via mkdtempSync(...) but nothing cleans it up, so repeated runs can leave many trapeze-* dirs under the OS temp folder. Consider tracking the created temp directory and removing it when the GradleFile/VFS is finished (or register a process-exit cleanup), or use a temp helper that supports automatic cleanup.
Replace Jest 27 + ts-jest with Vitest 4 for native ESM support and modern test tooling. Upgrade TypeScript from 4.4 to 5.9.
Additional fixes:
tempywith Node.js built-ins in source code to fix ESM runtime error when consuming@trapezedev/projectviarequire()@xmldom/xmldom0.9.9 strict mode by wrapping fragments and propagating namespace declarationsconst enumtoenumfor esbuild compatibilitytypesarray to tsconfigs to exclude hoisted@types/mdxvia.placeholder.comwithpicsum.photosin tests