Commit 98241c12 by Sweet Zhang

fix(test): 降级 jsdom 至 26 修复 worker 启动崩溃,并清理 env.d.ts 冲突标记

parent 3770118b
...@@ -15,6 +15,10 @@ VITE_OIDC_SCOPE=openid profile phone ...@@ -15,6 +15,10 @@ VITE_OIDC_SCOPE=openid profile phone
# 置为 true 才启用接口 mock(当前仅影响首页待办的假延迟),默认关闭。 # 置为 true 才启用接口 mock(当前仅影响首页待办的假延迟),默认关闭。
# VITE_USE_MOCK=false # VITE_USE_MOCK=false
# mock-only 本地核对模式:整条 OIDC 链路停用,用 localStorage 里的转介人身份直连后端。
# 只在本地 .env.development.local 里临时打开,切勿写进测试/生产构建。
# VITE_MOCK_ONLY=true
# 说明: # 说明:
# redirect_uri / post_logout_redirect_uri 由代码按当前域名自动拼出,无需配置。 # redirect_uri / post_logout_redirect_uri 由代码按当前域名自动拼出,无需配置。
# 上线 https://center.zuihuibi.cn 前,需在 IdP 应用里登记: # 上线 https://center.zuihuibi.cn 前,需在 IdP 应用里登记:
......
...@@ -3,14 +3,20 @@ ...@@ -3,14 +3,20 @@
"version": "0.1.0", "version": "0.1.0",
"private": true, "private": true,
"type": "module", "type": "module",
"engines": {
"node": ">=20.19.0"
},
"scripts": { "scripts": {
"dev": "vite", "dev": "vite",
"prebuild": "node scripts/check-node.mjs",
"build": "vue-tsc --noEmit && vite build", "build": "vue-tsc --noEmit && vite build",
"preview": "vite preview", "preview": "vite preview",
"type-check": "vue-tsc --noEmit", "type-check": "vue-tsc --noEmit",
"pretest": "node scripts/check-node.mjs",
"test": "vitest run --config vitest.config.ts", "test": "vitest run --config vitest.config.ts",
"test:watch": "vitest --config vitest.config.ts", "test:watch": "vitest --config vitest.config.ts",
"test:cov": "vitest run --coverage --config vitest.config.ts" "test:cov": "vitest run --coverage --config vitest.config.ts",
"check:node": "node scripts/check-node.mjs"
}, },
"dependencies": { "dependencies": {
"@headlessui/vue": "^1.7.23", "@headlessui/vue": "^1.7.23",
...@@ -27,7 +33,7 @@ ...@@ -27,7 +33,7 @@
"@vitest/coverage-v8": "^5.0.5", "@vitest/coverage-v8": "^5.0.5",
"@vue/test-utils": "^2.5.1", "@vue/test-utils": "^2.5.1",
"autoprefixer": "^10.4.20", "autoprefixer": "^10.4.20",
"jsdom": "^30.1.3", "jsdom": "^26.1.0",
"postcss": "^8.4.49", "postcss": "^8.4.49",
"tailwindcss": "^3.4.17", "tailwindcss": "^3.4.17",
"typescript": "~5.6.3", "typescript": "~5.6.3",
......
/**
* Node 版本预检(npm test / npm run build 前自动执行)。
*
* vite 6 / vitest 5 / jsdom 都有 Node 下限。版本过低时 vitest 不会给出可读提示,
* 而是在启动 worker 时抛出 `TypeError: Cannot read properties of undefined (reading 'bind')`
* (jsdom 30 依赖的 undici 8 用到了 Node 22.15+ 才有的 zlib.createZstdDecompress),
* 极难定位。这里提前拦截,直接告诉使用者该切哪个版本。
*/
const REQUIRED_MAJOR = 20
const REQUIRED_MINOR = 19
const [major, minor] = process.versions.node.split('.').map(Number)
const tooOld = major < REQUIRED_MAJOR || (major === REQUIRED_MAJOR && minor < REQUIRED_MINOR)
if (tooOld) {
console.error(
[
'',
`✖ Node 版本过低:当前 v${process.versions.node},本项目要求 >= ${REQUIRED_MAJOR}.${REQUIRED_MINOR}.0`,
'',
' 切换方式(任选其一):',
' fnm install 22 && fnm use 22',
' nvm install 22 && nvm use 22',
' 或从 https://nodejs.org 安装 LTS 后重开终端。',
'',
' 确认当前生效版本:node -v(注意 IDE 内置终端可能用的是另一份 Node)',
''
].join('\n')
)
process.exit(1)
}
/// <reference types="vite/client" /> /// <reference types="vite/client" />
<<<<<<< HEAD
/** /**
* 构建期注入的环境变量(Vite 只暴露 VITE_ 前缀)。 * 构建期注入的环境变量(Vite 只暴露 VITE_ 前缀)。
* 集中声明后 `import.meta.env.XXX` 有补全与拼写校验,避免变量名打错后静默取到 undefined。 * 集中声明后 `import.meta.env.XXX` 有补全与拼写校验,避免变量名打错后静默取到 undefined。
...@@ -16,9 +15,6 @@ interface ImportMetaEnv { ...@@ -16,9 +15,6 @@ interface ImportMetaEnv {
readonly VITE_USE_MOCK?: string readonly VITE_USE_MOCK?: string
/** 本地开发代理后端地址,未设置时指向本机 9202 */ /** 本地开发代理后端地址,未设置时指向本机 9202 */
readonly VITE_API_TARGET?: string readonly VITE_API_TARGET?: string
}
=======
interface ImportMetaEnv {
/** mock-only 模式(本地生产数据核对):禁用 OIDC 跳转与 Bearer 附加 */ /** mock-only 模式(本地生产数据核对):禁用 OIDC 跳转与 Bearer 附加 */
readonly VITE_MOCK_ONLY?: string readonly VITE_MOCK_ONLY?: string
} }
...@@ -26,4 +22,3 @@ interface ImportMetaEnv { ...@@ -26,4 +22,3 @@ interface ImportMetaEnv {
interface ImportMeta { interface ImportMeta {
readonly env: ImportMetaEnv readonly env: ImportMetaEnv
} }
>>>>>>> 0cac32e9c611857dfc32d14724490175aac1f693
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment