Skip to content

Commit 1e9cdcf

Browse files
committed
What was actually happening: prepublish.sh (cp -r dist/src/* .) copies compiled TypeScript — including *.test.js files — into the root-level preprocessor/, parser/, and ast/
directories. Vitest found and ran these compiled test files alongside the TypeScript ones. The compiled preprocessor/preprocessor.test.js imported GlslSyntaxError from ../error.js (root-level compiled), but buildPreprocessorParser dynamically imported preprocessor/index.js which was resolved by Vite's TypeScript-aware resolver to src/preprocessor/index.ts → src/error.ts. Two different class instances → instanceof failed. Two fixes applied: 1. vite.config.ts: Added include: ['src/**/*.test.ts'] so Vitest only runs the canonical TypeScript test files in src/, ignoring compiled JS copies elsewhere. 2. prepublish.sh: Added cleanup to delete *.test.js and *.test.d.ts from published directories — test files don't belong in the npm package and cause this discovery problem.
1 parent c92f0f3 commit 1e9cdcf

2 files changed

Lines changed: 6 additions & 0 deletions

File tree

prepublish.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,8 @@ cp -r dist/src/* .
1111
# dist/parser/ and dist/preprocessor/, separate from the compiled TypeScript in dist/src/)
1212
cp dist/parser/parser.js parser/
1313
cp dist/preprocessor/preprocessor-parser.js preprocessor/
14+
15+
# Remove test files from the published directories - they're not part of the package
16+
# and if present they confuse Vitest into running compiled JS tests with broken module paths
17+
find . -name "*.test.js" -not -path "./src/*" -not -path "./dist/*" -not -path "./node_modules/*" -delete
18+
find . -name "*.test.d.ts" -not -path "./src/*" -not -path "./dist/*" -not -path "./node_modules/*" -delete

vite.config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,6 @@ export default defineConfig({
88
},
99
test: {
1010
globalSetup: './vitest.global-setup.ts',
11+
include: ['src/**/*.test.ts'],
1112
},
1213
});

0 commit comments

Comments
 (0)