feat: 配置多环境支持
- 创建环境配置文件environments.ts - 支持development/staging/production三个环境 - 更新playwright.config.ts使用环境配置 - 创建.env.example环境变量示例 - 创建ENVIRONMENT.md环境配置指南 - 支持CI/CD集成配置
This commit is contained in:
@@ -0,0 +1,82 @@
|
||||
export interface EnvironmentConfig {
|
||||
name: string;
|
||||
baseURL: string;
|
||||
apiURL: string;
|
||||
timeout: number;
|
||||
retries: number;
|
||||
headless: boolean;
|
||||
slowMo: number;
|
||||
screenshot: 'on' | 'off' | 'only-on-failure';
|
||||
video: 'on' | 'off' | 'retain-on-failure';
|
||||
trace: 'on' | 'off' | 'retain-on-failure';
|
||||
}
|
||||
|
||||
export const environments: Record<string, EnvironmentConfig> = {
|
||||
development: {
|
||||
name: 'development',
|
||||
baseURL: 'http://localhost:3001',
|
||||
apiURL: 'http://localhost:3001/api',
|
||||
timeout: 120000,
|
||||
retries: 0,
|
||||
headless: false,
|
||||
slowMo: 100,
|
||||
screenshot: 'only-on-failure',
|
||||
video: 'retain-on-failure',
|
||||
trace: 'retain-on-failure',
|
||||
},
|
||||
staging: {
|
||||
name: 'staging',
|
||||
baseURL: 'https://staging.novalon.com',
|
||||
apiURL: 'https://staging.novalon.com/api',
|
||||
timeout: 120000,
|
||||
retries: 1,
|
||||
headless: true,
|
||||
slowMo: 0,
|
||||
screenshot: 'only-on-failure',
|
||||
video: 'retain-on-failure',
|
||||
trace: 'retain-on-failure',
|
||||
},
|
||||
production: {
|
||||
name: 'production',
|
||||
baseURL: 'https://novalon.com',
|
||||
apiURL: 'https://novalon.com/api',
|
||||
timeout: 120000,
|
||||
retries: 2,
|
||||
headless: true,
|
||||
slowMo: 0,
|
||||
screenshot: 'only-on-failure',
|
||||
video: 'retain-on-failure',
|
||||
trace: 'retain-on-failure',
|
||||
},
|
||||
};
|
||||
|
||||
export function getEnvironment(): EnvironmentConfig {
|
||||
const envName = process.env.TEST_ENV || 'development';
|
||||
const env = environments[envName];
|
||||
|
||||
if (!env) {
|
||||
throw new Error(`Unknown environment: ${envName}. Valid environments: ${Object.keys(environments).join(', ')}`);
|
||||
}
|
||||
|
||||
return env;
|
||||
}
|
||||
|
||||
export function getBaseURL(): string {
|
||||
return getEnvironment().baseURL;
|
||||
}
|
||||
|
||||
export function getApiURL(): string {
|
||||
return getEnvironment().apiURL;
|
||||
}
|
||||
|
||||
export function isDevelopment(): boolean {
|
||||
return getEnvironment().name === 'development';
|
||||
}
|
||||
|
||||
export function isStaging(): boolean {
|
||||
return getEnvironment().name === 'staging';
|
||||
}
|
||||
|
||||
export function isProduction(): boolean {
|
||||
return getEnvironment().name === 'production';
|
||||
}
|
||||
Reference in New Issue
Block a user