forked from RishabhK103/claude-code
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathvitest.config.ts
More file actions
52 lines (47 loc) · 1.72 KB
/
vitest.config.ts
File metadata and controls
52 lines (47 loc) · 1.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import { defineConfig } from 'vitest/config'
import { fileURLToPath } from 'url'
import { resolve, dirname } from 'path'
import { existsSync } from 'fs'
const __dirname = fileURLToPath(new URL('.', import.meta.url))
/**
* Vite plugin that resolves relative `.js` imports to their `.ts`/`.tsx`
* equivalents at the filesystem level.
*
* The source uses TypeScript's `allowImportingTsExtensions: true` convention
* (`.js` suffixes on imports for Node ESM compatibility), but Vitest's runtime
* must locate the real TypeScript source files. This plugin intercepts all
* relative `.js` imports and checks whether a matching `.ts` or `.tsx` file
* exists, returning its absolute path if found.
*/
const resolveJsToTs = {
name: 'resolve-js-to-ts',
enforce: 'pre' as const,
resolveId(id: string, importer: string | undefined): string | null {
if (!importer || !id.startsWith('.') || !id.endsWith('.js')) return null
const dir = dirname(importer)
const base = id.slice(0, -3)
for (const ext of ['.ts', '.tsx']) {
const candidate = resolve(dir, base + ext)
if (existsSync(candidate)) return candidate
}
return null
},
}
export default defineConfig({
plugins: [resolveJsToTs],
test: {
globals: true,
environment: 'node',
include: ['tests/**/*.test.ts'],
setupFiles: ['tests/setup.ts'],
testTimeout: 30000,
},
resolve: {
alias: [
// The source uses baseUrl:"." in tsconfig so bare "src/..." imports resolve from root
{ find: /^src\//, replacement: resolve(__dirname, 'src') + '/' },
// bun:bundle is a Bun bundler virtual module; redirect to the dev shim
{ find: 'bun:bundle', replacement: resolve(__dirname, 'src/shims/bun-bundle.ts') },
],
},
})