Skip to content

Commit 895581e

Browse files
authored
fix(test): patch vitest resolver (#356)
<!-- CURSOR_SUMMARY --> > [!NOTE] > Patches Vitest resolver and test build to resolve package aliases directly, aligns browser context/provider exports, and fixes type/module augmentations. > > - **Test build (`packages/test/build.ts`)**: > - Patch `VitestCoreResolver` to resolve `@voidzero-dev/vite-plus/test` and `@voidzero-dev/vite-plus-test` directly to `dist/index.js`, with subpath routing to `vitest/*`. > - Add patches for module augmentations (`global.d.*.d.ts` -> relative paths), Chai type reference in `@vitest/expect/index.d.ts`, and mocker `hoistedModule` to accept package aliases. > - Expand optimizeDeps exclude list and inject vendor-aliases handling for vitest/browser and aliases. > - Create browser entry files and context/type wiring; copy/update browser client files and vendor stubs. > - **Exports and shims**: > - Route `./context` and `./browser/context` to `./dist/@vitest/browser/context.js` (preserve single module identity). > - Add `./browser/providers/{playwright,webdriverio,preview}` subpath exports in both `packages/test` and `packages/cli`. > - CLI `build.ts`: `.d.ts` shims now include side-effect import before `export *` to keep module augmentations. > - **Dependencies**: > - Add `@types/chai` to test package; add `playwright` as a root devDependency. > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit caf4aca. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY -->
1 parent b9acebf commit 895581e

7 files changed

Lines changed: 334 additions & 31 deletions

File tree

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
"lint-staged": "catalog:",
2727
"oxfmt": "catalog:",
2828
"oxlint": "catalog:",
29+
"playwright": "catalog:",
2930
"typescript": "catalog:",
3031
"vite": "catalog:",
3132
"vitest": "catalog:"

packages/cli/build.ts

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,11 @@ async function createShimForExport(
156156
// Check if it's a type-only export
157157
if (exportValue.endsWith('.d.ts')) {
158158
const dtsPath = join(shimDirForFile, `${baseFileName}.d.ts`);
159-
await writeFile(dtsPath, `export * from '${testImportSpecifier}';\n`);
159+
// Include side-effect import to preserve module augmentations (e.g., toMatchSnapshot on Assertion)
160+
await writeFile(
161+
dtsPath,
162+
`import '${testImportSpecifier}';\nexport * from '${testImportSpecifier}';\n`,
163+
);
160164
return { types: `./dist/test/${shimBaseName}.d.ts` };
161165
}
162166

@@ -184,7 +188,11 @@ async function createShimForExport(
184188

185189
if (value.types && typeof value.types === 'string') {
186190
const dtsPath = join(shimDirForFile, `${baseFileName}.d.ts`);
187-
await writeFile(dtsPath, `export * from '${testImportSpecifier}';\n`);
191+
// Include side-effect import to preserve module augmentations (e.g., toMatchSnapshot on Assertion)
192+
await writeFile(
193+
dtsPath,
194+
`import '${testImportSpecifier}';\nexport * from '${testImportSpecifier}';\n`,
195+
);
188196
(result as Record<string, string>).types = `./dist/test/${shimBaseName}.d.ts`;
189197
}
190198

@@ -220,7 +228,11 @@ async function createConditionalShim(
220228
// Handle top-level types (flat structure like { types, require, default })
221229
if (value.types && typeof value.types === 'string' && !value.import) {
222230
const dtsPath = join(shimDir, `${baseFileName}.d.ts`);
223-
await writeFile(dtsPath, `export * from '${testImportSpecifier}';\n`);
231+
// Include side-effect import to preserve module augmentations (e.g., toMatchSnapshot on Assertion)
232+
await writeFile(
233+
dtsPath,
234+
`import '${testImportSpecifier}';\nexport * from '${testImportSpecifier}';\n`,
235+
);
224236
(result as Record<string, string>).types = `./dist/test/${shimBaseName}.d.ts`;
225237
}
226238

@@ -244,7 +256,11 @@ async function createConditionalShim(
244256

245257
if (importValue.types && typeof importValue.types === 'string') {
246258
const dtsPath = join(shimDir, `${baseFileName}.d.ts`);
247-
await writeFile(dtsPath, `export * from '${testImportSpecifier}';\n`);
259+
// Include side-effect import to preserve module augmentations (e.g., toMatchSnapshot on Assertion)
260+
await writeFile(
261+
dtsPath,
262+
`import '${testImportSpecifier}';\nexport * from '${testImportSpecifier}';\n`,
263+
);
248264
importResult.types = `./dist/test/${shimBaseName}.d.ts`;
249265
}
250266

@@ -276,7 +292,11 @@ async function createConditionalShim(
276292

277293
if (requireValue.types && typeof requireValue.types === 'string') {
278294
const dctsPath = join(shimDir, `${baseFileName}.d.cts`);
279-
await writeFile(dctsPath, `export * from '${testImportSpecifier}';\n`);
295+
// Include side-effect import to preserve module augmentations (e.g., toMatchSnapshot on Assertion)
296+
await writeFile(
297+
dctsPath,
298+
`import '${testImportSpecifier}';\nexport * from '${testImportSpecifier}';\n`,
299+
);
280300
requireResult.types = `./dist/test/${shimBaseName}.d.cts`;
281301
}
282302

packages/cli/package.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,10 @@
155155
"types": "./dist/test/context.d.ts",
156156
"default": "./dist/test/context.js"
157157
},
158+
"./test/browser/context": {
159+
"types": "./dist/test/browser/context.d.ts",
160+
"default": "./dist/test/browser/context.js"
161+
},
158162
"./test/locators": {
159163
"default": "./dist/test/locators.js"
160164
},
@@ -176,6 +180,18 @@
176180
"types": "./dist/test/browser-preview.d.ts",
177181
"default": "./dist/test/browser-preview.js"
178182
},
183+
"./test/browser/providers/playwright": {
184+
"types": "./dist/test/browser/providers/playwright.d.ts",
185+
"default": "./dist/test/browser/providers/playwright.js"
186+
},
187+
"./test/browser/providers/webdriverio": {
188+
"types": "./dist/test/browser/providers/webdriverio.d.ts",
189+
"default": "./dist/test/browser/providers/webdriverio.js"
190+
},
191+
"./test/browser/providers/preview": {
192+
"types": "./dist/test/browser/providers/preview.d.ts",
193+
"default": "./dist/test/browser/providers/preview.js"
194+
},
179195
"./test/plugins/runner": {
180196
"default": "./dist/test/plugins/runner.js"
181197
},

0 commit comments

Comments
 (0)