Skip to content

Commit 2ca14a5

Browse files
authored
test(portal): make vitest config resolve aliases and use jsdom (#3458)
The portal vitest config (added in #3454 / CS-760) had two gaps that would break any test beyond the current pure-logic one: - No resolve.alias for the tsconfig `@/*` path, so any test importing via `@/...` fails at module resolution. Mirror `@` -> ./src, matching apps/app and apps/framework-editor. - environment was 'node' while the include glob targets .jsx/.tsx component tests, which need DOM APIs. Switch to jsdom (both sibling configs use it); node-only tests still run fine under it. Follow no-plugin approach (hand-mapped alias) like framework-editor to avoid the vite plugin type clash with Next's build-time typecheck on Vercel. Add jsdom + vitest as portal devDependencies so resolution no longer relies on workspace hoisting.
1 parent cd31daf commit 2ca14a5

3 files changed

Lines changed: 21 additions & 2 deletions

File tree

‎apps/portal/package.json‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,11 @@
4444
"@types/node": "^24.0.3",
4545
"eslint": "^9.18.0",
4646
"eslint-config-next": "15.5.2",
47+
"jsdom": "^26.1.0",
4748
"postcss": "^8.5.4",
4849
"tailwindcss": "^4.1.8",
49-
"typescript": "^5.8.3"
50+
"typescript": "^5.8.3",
51+
"vitest": "^3.2.7"
5052
},
5153
"peerDependencies": {
5254
"react": "^19.1.1",

‎apps/portal/vitest.config.ts‎

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,24 @@
1+
import { resolve } from 'path';
12
import { defineConfig } from 'vitest/config';
23

4+
// No vite plugins on purpose: esbuild already transforms TSX with the automatic
5+
// JSX runtime, and plugin types (e.g. @vitejs/plugin-react, vite-tsconfig-paths)
6+
// can clash with vitest's bundled vite during Next's build-time typecheck on
7+
// Vercel. Aliases are mirrored by hand from tsconfig instead — see
8+
// apps/framework-editor/vitest.config.ts for the same approach.
39
export default defineConfig({
410
test: {
5-
environment: 'node',
11+
// jsdom, not node: the include glob covers component tests (.jsx/.tsx) that
12+
// need DOM APIs (e.g. testing-library's render). Matches apps/app and
13+
// apps/framework-editor. Node-only tests run fine under jsdom too.
14+
environment: 'jsdom',
615
include: ['src/**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'],
716
exclude: ['node_modules', 'dist', '.next'],
817
},
18+
resolve: {
19+
// Mirror the tsconfig `@/*` path alias so tests can import via `@/...`.
20+
alias: {
21+
'@': resolve(__dirname, './src'),
22+
},
23+
},
924
});

‎bun.lock‎

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)