08ea5fbe98
添加用户管理视图、API和状态管理文件
145 lines
3.4 KiB
TypeScript
145 lines
3.4 KiB
TypeScript
/**
|
|
* 统一测试配置管理
|
|
* 支持多环境配置:local、dev、test、prod
|
|
*/
|
|
|
|
export interface EnvironmentConfig {
|
|
name: string;
|
|
baseURL: string;
|
|
apiBaseURL: string;
|
|
uniappBaseURL: string;
|
|
timeout: {
|
|
default: number;
|
|
navigation: number;
|
|
action: number;
|
|
};
|
|
mock: {
|
|
enabled: boolean;
|
|
mode: 'full' | 'partial' | 'none';
|
|
delay: number;
|
|
};
|
|
retry: {
|
|
count: number;
|
|
delay: number;
|
|
};
|
|
}
|
|
|
|
const environments: Record<string, EnvironmentConfig> = {
|
|
local: {
|
|
name: 'local',
|
|
baseURL: process.env.ADMIN_BASE_URL || 'http://localhost:5174',
|
|
apiBaseURL: process.env.API_BASE_URL || 'http://localhost:8080',
|
|
uniappBaseURL: process.env.UNIAPP_BASE_URL || 'http://localhost:8081',
|
|
timeout: {
|
|
default: 30000,
|
|
navigation: 30000,
|
|
action: 10000,
|
|
},
|
|
mock: {
|
|
enabled: process.env.E2E_MOCK_ENABLED === 'true',
|
|
mode: (process.env.E2E_MOCK_MODE as 'full' | 'partial' | 'none') || 'none',
|
|
delay: 0,
|
|
},
|
|
retry: {
|
|
count: process.env.CI ? 2 : 0,
|
|
delay: 1000,
|
|
},
|
|
},
|
|
dev: {
|
|
name: 'dev',
|
|
baseURL: process.env.ADMIN_BASE_URL || 'http://dev-admin.example.com',
|
|
apiBaseURL: process.env.API_BASE_URL || 'http://dev-api.example.com',
|
|
uniappBaseURL: process.env.UNIAPP_BASE_URL || 'http://dev-uniapp.example.com',
|
|
timeout: {
|
|
default: 30000,
|
|
navigation: 30000,
|
|
action: 10000,
|
|
},
|
|
mock: {
|
|
enabled: false,
|
|
mode: 'none',
|
|
delay: 0,
|
|
},
|
|
retry: {
|
|
count: 2,
|
|
delay: 1000,
|
|
},
|
|
},
|
|
test: {
|
|
name: 'test',
|
|
baseURL: process.env.ADMIN_BASE_URL || 'http://test-admin.example.com',
|
|
apiBaseURL: process.env.API_BASE_URL || 'http://test-api.example.com',
|
|
uniappBaseURL: process.env.UNIAPP_BASE_URL || 'http://test-uniapp.example.com',
|
|
timeout: {
|
|
default: 30000,
|
|
navigation: 30000,
|
|
action: 10000,
|
|
},
|
|
mock: {
|
|
enabled: false,
|
|
mode: 'none',
|
|
delay: 0,
|
|
},
|
|
retry: {
|
|
count: 2,
|
|
delay: 1000,
|
|
},
|
|
},
|
|
ci: {
|
|
name: 'ci',
|
|
baseURL: process.env.ADMIN_BASE_URL || 'http://localhost:5174',
|
|
apiBaseURL: process.env.API_BASE_URL || 'http://localhost:8080',
|
|
uniappBaseURL: process.env.UNIAPP_BASE_URL || 'http://localhost:8081',
|
|
timeout: {
|
|
default: 60000,
|
|
navigation: 60000,
|
|
action: 15000,
|
|
},
|
|
mock: {
|
|
enabled: true,
|
|
mode: 'full',
|
|
delay: 100,
|
|
},
|
|
retry: {
|
|
count: 2,
|
|
delay: 1000,
|
|
},
|
|
},
|
|
};
|
|
|
|
class TestConfigManager {
|
|
private currentEnv: string = 'local';
|
|
|
|
setEnvironment(env: string): void {
|
|
if (!environments[env]) {
|
|
throw new Error(`Unknown environment: ${env}. Available: ${Object.keys(environments).join(', ')}`);
|
|
}
|
|
this.currentEnv = env;
|
|
}
|
|
|
|
getConfig(): EnvironmentConfig {
|
|
return environments[this.currentEnv];
|
|
}
|
|
|
|
getEnvironmentName(): string {
|
|
return this.currentEnv;
|
|
}
|
|
|
|
isMockEnabled(): boolean {
|
|
return this.getConfig().mock.enabled;
|
|
}
|
|
|
|
getTimeout(type: keyof EnvironmentConfig['timeout'] = 'default'): number {
|
|
return this.getConfig().timeout[type];
|
|
}
|
|
}
|
|
|
|
export const testConfig = new TestConfigManager();
|
|
|
|
// 自动根据环境变量设置环境
|
|
if (process.env.CI) {
|
|
testConfig.setEnvironment('ci');
|
|
} else if (process.env.E2E_ENV && environments[process.env.E2E_ENV]) {
|
|
testConfig.setEnvironment(process.env.E2E_ENV);
|
|
}
|