Skip to content

Commit 6d34d49

Browse files
committed
Hotfix for version check in bundle tests
1 parent a122b1a commit 6d34d49

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

tests/setup-version.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/**
2+
* Inject the package.json version onto globalThis as __VERSION_PLACEHOLDER__.
3+
*
4+
* The built bundle (dist/esm/) has this baked in by esbuild's `define` (see
5+
* build.ts). For source-import test runs (no build step), src/index.ts falls
6+
* back to globalThis.__VERSION_PLACEHOLDER__ — this setup file populates it.
7+
*
8+
* Wired into each source-importing project as `setupFiles` in vitest.config.ts.
9+
* The bundle smoke test (tests/bundles/node.test.ts) separately asserts the
10+
* built artifact reports the real semver, not the 'dev' fallback.
11+
*/
12+
import { readFileSync } from 'node:fs';
13+
import { fileURLToPath } from 'node:url';
14+
import { dirname, resolve } from 'node:path';
15+
16+
const here = dirname(fileURLToPath(import.meta.url));
17+
const pkg = JSON.parse(readFileSync(resolve(here, '..', 'package.json'), 'utf8'));
18+
19+
(globalThis as { __VERSION_PLACEHOLDER__?: string }).__VERSION_PLACEHOLDER__ = pkg.version;

vitest.config.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ export default defineConfig({
3939
include: ['tests/unit/**'],
4040
exclude: ['**/node_modules/**'],
4141
environment: 'node',
42+
// Inject __VERSION_PLACEHOLDER__ for source-imported __version__.
43+
setupFiles: ['tests/setup-version.ts'],
4244
},
4345
}),
4446
// Validation tests (requires Python + NumPy)
@@ -48,6 +50,7 @@ export default defineConfig({
4850
include: ['tests/validation/**'],
4951
exclude: ['**/node_modules/**', '**/*.md', '**/numpy-oracle.ts', '**/_helpers.ts', '**/_dtype-matrix.ts', '**/_*.ts'],
5052
environment: 'node',
53+
setupFiles: ['tests/setup-version.ts'],
5154
},
5255
}),
5356
// Runtime file IO tests (runs under Node, Bun, and Deno)
@@ -57,6 +60,7 @@ export default defineConfig({
5760
include: ['tests/runtime/**/*.test.ts'],
5861
exclude: ['**/node_modules/**'],
5962
environment: 'node',
63+
setupFiles: ['tests/setup-version.ts'],
6064
},
6165
}),
6266
// ESM bundle smoke test (tests dist/esm/ with file IO)
@@ -99,6 +103,7 @@ export default defineConfig({
99103
name: 'browser-unit',
100104
include: ['tests/unit/**'],
101105
exclude: ['**/node_modules/**', '**/__screenshots__/**'],
106+
setupFiles: ['tests/setup-version.ts'],
102107
browser: {
103108
enabled: true,
104109
headless: true,
@@ -124,6 +129,7 @@ export default defineConfig({
124129
exclude: ['**/node_modules/**'],
125130
environment: 'node',
126131
testTimeout: 60000,
132+
setupFiles: ['tests/setup-version.ts'],
127133
},
128134
}),
129135
// WASM memory leak tests (validates operations don't leak WASM heap)
@@ -134,6 +140,7 @@ export default defineConfig({
134140
exclude: ['**/node_modules/**'],
135141
environment: 'node',
136142
testTimeout: 300000, // 5 minutes — runs many specs
143+
setupFiles: ['tests/setup-version.ts'],
137144
},
138145
}),
139146
// Tree-shaking tests (tests with multiple bundlers)

0 commit comments

Comments
 (0)