skillhub/web/base-path-config.test.ts
philsun 34f244e7a4 feat(web): support configurable base-path deployment
Signed-off-by: philsun <xinyi.sun@daocloud.io>
2026-08-05 12:50:26 +08:00

38 lines
961 B
TypeScript

import { describe, expect, it } from 'vitest'
import { validateBasePath } from './base-path-config'
describe('validateBasePath', () => {
it.each(['/skillhub/', '/foo.bar/', '/a_b~c/'])('accepts %s', (value) => {
expect(validateBasePath(value)).toBe(value)
})
it('accepts root deployment', () => {
expect(validateBasePath('/')).toBe('/')
})
it.each([
'//cdn.example/',
'/foo//bar/',
'/foo/../bar/',
'/foo/./bar/',
'/foo bar/',
'skillhub/',
'/skillhub',
])('rejects unsafe or malformed value %s', (value) => {
expect(() => validateBasePath(value)).toThrow(/VITE_BASE_PATH/)
})
it.each([
'/api/',
'/oauth2/',
'/login/',
'/assets/',
'/registry/',
'/nginx-health/',
'/.well-known/',
'/runtime-config.js/',
'/api/nested/',
])('rejects reserved first segment %s', (value) => {
expect(() => validateBasePath(value)).toThrow(/reserved by the SkillHub server/)
})
})