-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvitest.config.ts
More file actions
120 lines (117 loc) · 4.26 KB
/
Copy pathvitest.config.ts
File metadata and controls
120 lines (117 loc) · 4.26 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
/**
* Vitest configuration for @bitcode/ui runtime tests.
*
* Runtime tests (`*.runtime.test.tsx`) mount compiled Mitosis React output
* in jsdom and fire real events via @testing-library/react. Source-level
* tests (`*.test.ts`) remain on Node's built-in test runner semantics but
* are executed under vitest for a single `npm test` entry point.
*
* Key aliases mirror `demo-app/vite.config.ts` so runtime tests hit the
* same compiled `output/react/src` the demo app consumes — catching
* Mitosis generator regressions that source-level tests cannot see.
*/
import { defineConfig, type Plugin } from 'vitest/config';
import { resolve, normalize, dirname } from 'path';
import { existsSync } from 'fs';
const ROOT = resolve(__dirname);
const REACT_OUT = resolve(ROOT, 'output/react/src');
const UI_SRC_CORE = resolve(ROOT, 'src/core');
/**
* Redirect .lite imports from output/react/src/core/ to compiled .tsx output.
* Mirrors the redirectRelativeCoreImports plugin in demo-app/vite.config.ts.
*/
function redirectLiteImports(): Plugin {
return {
name: 'redirect-lite-imports',
enforce: 'pre',
resolveId(source, importer) {
if (!importer || !source.includes('.lite')) return null;
const resolved = normalize(resolve(dirname(importer), source));
// For ANY .lite import that resolves inside output/react/src/,
// prefer the compiled .tsx (without .lite) when it exists.
if (resolved.startsWith(REACT_OUT)) {
const liteMatch = resolved.slice(REACT_OUT.length).match(/^(.*)\.lite$/);
if (liteMatch) {
const compiledPath = resolve(REACT_OUT, liteMatch[1].replace(/^[\\/]+/, '') + '.tsx');
if (existsSync(compiledPath)) return compiledPath;
}
}
return null;
},
};
}
export default defineConfig({
plugins: [redirectLiteImports()],
esbuild: {
jsx: 'automatic',
jsxImportSource: 'react',
},
resolve: {
// Adapt components (BcLightbox, BcMap, BcWebcam, BcShare, BcGridView,
// BcNative*) use the `.web.tsx` extension per ADR-006 §3. Vite's default
// extensions list does NOT include `.web.*`, so `import './BcLightbox'`
// from an Adapt entry `index.ts` fails to resolve under vitest even though
// the demo-app (which sets these explicitly) works. Mirror the demo-app
// vite.config.ts extensions so the runtime test suite can resolve Adapt
// components compiled into output/react/src.
extensions: [
'.web.tsx',
'.web.ts',
'.web.jsx',
'.web.js',
'.tsx',
'.ts',
'.jsx',
'.js',
'.mjs',
'.json',
],
alias: {
'@/core': UI_SRC_CORE,
'@': resolve(ROOT, 'src'),
'@bitcode/ui': REACT_OUT,
'@builder.io/mitosis/jsx-runtime': 'react/jsx-runtime',
'@builder.io/mitosis/jsx-dev-runtime': 'react/jsx-dev-runtime',
'react-native': resolve(ROOT, 'test/react-native-web-stub.tsx'),
},
},
test: {
environment: 'jsdom',
globals: true,
setupFiles: ['./test-setup.ts'],
include: ['src/**/*.rtl.test.ts', 'src/**/*.rtl.test.tsx'],
exclude: [
'**/node_modules/**',
'**/output/**',
'**/dist/**',
],
coverage: {
provider: 'v8',
reporter: ['text', 'html', 'json-summary'],
reportsDirectory: resolve(ROOT, 'coverage'),
include: ['output/react/src/components/**/*.{ts,tsx}'],
exclude: [
'output/react/src/components/**/*.contract.ts',
'output/react/src/components/**/*.test.*',
'output/react/src/components/**/*.utils.ts',
],
thresholds: {
// Phase A1 baseline — raised per-component as runtime tests land.
// Target for Core Integration Surface is 80% (C4 in roadmap).
statements: 0,
branches: 0,
functions: 0,
lines: 0,
},
},
// Runtime tests do dynamic import('@bitcode/ui') → output/react/src.
// When fork workers run in parallel, each worker gets its own module
// cache and the cached Mitosis output can diverge between workers
// (race on first import), producing ~30 false-positive failures.
// singleFork runs all test files in one worker sequentially, which is
// slower (~2x) but eliminates the cache-pollution isolation issue.
poolOptions: {
forks: { singleFork: true },
},
},
});