-
Notifications
You must be signed in to change notification settings - Fork 108
TypeScript definitions are lost when running Vitest via @nuxt/test-utils #801
Copy link
Copy link
Closed
Labels
bugSomething isn't workingSomething isn't working
Description
Describe the bug
When running tests with Vitest (using @nuxt/test-utils), the database schema type definitions in node_modules/@nuxthub/db/schema.d.mts are replaced with a stub (export * from './schema.mjs') instead of preserving the full type definitions.
This causes TypeScript errors in the editor after test execution, breaking the development experience.
Steps to reproduce
- Set up a Nuxt project with
@nuxthub/[email protected]and@nuxt/test-utils - Create database schema in
server/db/schema.ts - Run
pnpm dev- schema types are correctly generated - Run
pnpm test- tests pass but schema types are destroyed - Check
node_modules/@nuxthub/db/schema.d.mts- it becomes 28 bytes - Editor shows TypeScript errors for
@nuxthub/db/schemaimports
Expected behavior
After running tests, node_modules/@nuxthub/db/schema.d.mts should maintain the full type definitions, not be replaced with a stub.
Environment
@nuxthub/core: 0.10.5@nuxt/test-utils: 3.23.0vitest: 4.0.17nuxt: 4.3.0
Root Cause Analysis
During Vitest execution with @nuxt/test-utils, the buildDir changes from .nuxt to node_modules/.cache/nuxt/.nuxt.
The issue maybe occurs in generateDatabaseSchema():
buildDatabaseSchema()generates schema files to<buildDir>/hub/db/(=.nuxt/hub/db/)@nuxt/test-utilschangesbuildDirtonode_modules/.cache/nuxt/.nuxtduring tests- The code tries to read generated schema from
<buildDir>/hub/db/schema.d.mts(=node_modules/.cache/nuxt/.nuxt/hub/db/schema.d.mts) - Since the file doesn't exist at that location, it falls into the catch block
- The catch block writes a stub:
export * from './schema.mjs'
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working