Files
hermes-ui/vitest.config.ts
toor a1fff482bf make the test suite and openapi generator platform-independent
Windows checkouts turned LF into CRLF (core.autocrlf=true), and several
tests plus the openapi generator hardcoded LF or POSIX path separators.
The result was a suite that was green on Linux CI but red on Windows, and
an openapi.json whose /api/hermes/* routes silently disappeared when
generated on Windows.

Pin the repository to LF via .gitattributes, strip shebangs before
Vite's SSR transform, and key route files by their posix path. Add a
manually triggered macOS verification workflow so the same checks run
on a self-hosted macOS runner.
2026-10-20 11:17:34 +08:00

46 lines
1.6 KiB
TypeScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { defineConfig, type Plugin } from 'vitest/config'
import vue from '@vitejs/plugin-vue'
import { resolve } from 'path'
/**
* Vite 的 SSR 变换用 `/^#!.*\n/` 识别 shebang,并把 import 声明提升到它前面。
* 这个正则只在 LF 工作区成立:`.` 不匹配 `\r`,所以 CRLF checkout(Windows 默认
* core.autocrlf=true)下 shebang 识别失败,import 被提升到 `#!/usr/bin/env node`
* 之前,shebang 落到文件中部,运行期直接抛 "Invalid or unexpected token"。
*
* 统一在 SSR 变换之前剥掉 shebang:它只对「直接执行」有意义,测试里不需要。
*/
function stripShebang(): Plugin {
return {
name: 'hermes:strip-shebang',
enforce: 'pre',
transform(code, id) {
if (!code.startsWith('#!')) return null
const newline = code.indexOf('\n')
return { code: newline === -1 ? '' : code.slice(newline + 1), map: null }
},
}
}
export default defineConfig({
plugins: [stripShebang(), vue()],
resolve: {
alias: {
'@': resolve(__dirname, 'packages/client/src'),
'/logo.png': resolve(__dirname, 'packages/client/public/logo.png'),
},
},
test: {
include: ['tests/**/*.test.ts'],
setupFiles: ['tests/setup.ts'],
coverage: {
// Without an explicit include, v8 coverage walks the whole project root.
// While the read-only reference_code/ checkout was present that pulled in
// ~570 of its files and diluted every percentage below.
provider: 'v8',
include: ['packages/*/src/**'],
exclude: ['**/vendor/**', '**/*.d.ts'],
},
},
})