Files
novalon-manage-system/tests/performance/frontend-performance-test.js
T
张翔 be5d5ede90 feat: 添加异常日志功能并优化UI样式
refactor: 重构后端查询逻辑和API响应处理

fix: 修复用户角色更新和文件上传问题

test: 添加前端性能测试脚本和E2E测试用例

chore: 更新依赖版本和配置文件

docs: 添加环境检查脚本和测试文档

style: 统一表格标签样式和路由命名

perf: 优化前端页面加载速度和响应时间
2026-03-24 13:32:20 +08:00

54 lines
1.1 KiB
JavaScript

import http from 'k6/http';
import { check, sleep } from 'k6';
export let options = {
stages: [
{ duration: '30s', target: 5 },
{ duration: '1m', target: 10 },
{ duration: '30s', target: 0 },
],
thresholds: {
http_req_duration: ['p(95)<2000'],
http_req_failed: ['rate<0.02'],
},
};
const BASE_URL = __ENV.BASE_URL || 'http://localhost:3001';
export function setup() {
console.log('Starting frontend performance test...');
console.log(`Base URL: ${BASE_URL}`);
}
export default function () {
const pages = [
'/',
'/login',
'/dashboard',
'/system/config',
'/system/dict',
'/system/notice',
'/oplog',
'/loginlog',
'/files',
];
const page = pages[Math.floor(Math.random() * pages.length)];
const url = `${BASE_URL}${page}`;
const response = http.get(url, {
tags: { name: page },
});
check(response, {
'status is 200': (r) => r.status === 200,
'response time < 2s': (r) => r.timings.duration < 2000,
'page loads successfully': (r) => r.body.length > 0,
});
sleep(2);
}
export function teardown(data) {
console.log('Frontend performance test completed');
}