Files
EasyFlow/easyflow-ui-admin/app/vite-base-path-redirect.test.ts
陈子默 a75f7baf1b fix: 统一管理端开发与部署路由契约
- 开发与生产统一使用 /flow/ 基路径和 Hash 路由

- 自动规范化本地根路径入口并补充契约测试
2026-07-24 19:00:47 +08:00

57 lines
1.5 KiB
TypeScript

import { runInNewContext } from 'node:vm';
import { describe, expect, it } from 'vitest';
import {
buildBasePathRedirectScript,
resolveBasePathRedirect,
} from './vite-base-path-redirect';
describe('vite base path redirect', () => {
it.each([
['/', '/flow/'],
['/flow', '/flow/'],
['/flow?from=bookmark', '/flow/?from=bookmark'],
])('redirects %s to %s', (requestUrl, expected) => {
expect(resolveBasePathRedirect(requestUrl, '/flow/')).toBe(expected);
});
it.each(['/flow/', '/flow/api/v1/user/info', '/other'])(
'keeps %s unchanged',
(requestUrl) => {
expect(resolveBasePathRedirect(requestUrl, '/flow/')).toBeNull();
},
);
it('does not redirect when the application is deployed at root', () => {
expect(resolveBasePathRedirect('/', '/')).toBeNull();
});
it.each([
['/', '', '', '/flow/'],
[
'/flow',
'?from=bookmark',
'#/dashboard',
'/flow/?from=bookmark#/dashboard',
],
['/flow/', '', '#/dashboard', null],
])(
'normalizes browser entry %s before the router starts',
(pathname, search, hash, expected) => {
const replacements: string[] = [];
runInNewContext(buildBasePathRedirectScript('/flow/'), {
window: {
location: {
hash,
pathname,
replace: (target: string) => replacements.push(target),
search,
},
},
});
expect(replacements[0] ?? null).toBe(expected);
},
);
});