play.wenpai.net/tests/frontend.spec.js
elementary-qa 504315bcf2 修复 Playwright 测试套件适配 Playground 环境
- baseURL 改为 127.0.0.1 解决 CORS 脚本加载问题
- 统一使用 domcontentloaded 替代 load(Playground 特性)
- admin 页面测试串行化避免并发压力
- 过滤 Playground CORS 控制台错误
- Markdown Feed 改用 request API 避免下载触发
- 认证测试兼容 Playground 自动登录
全部 25 测试通过。

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-02-20 13:31:27 +08:00

63 lines
2.1 KiB
JavaScript

// WPMind GEO 模块前端功能测试
// @ts-check
const { test, expect } = require('@playwright/test');
const GOTO_OPTS = { waitUntil: 'domcontentloaded' };
test.describe('GEO 模块前端', () => {
test('Markdown Feed 可访问', async ({ request }) => {
// feed 返回下载流,用 request API 而非 page.goto
const response = await request.get('/?feed=markdown');
expect(response.status()).not.toBe(500);
});
test('llms.txt 可访问', async ({ page }) => {
const response = await page.goto('/llms.txt', GOTO_OPTS);
if (response.status() === 200) {
const content = await page.content();
expect(content.length).toBeGreaterThan(0);
}
expect([200, 404]).toContain(response.status());
});
test('AI Sitemap 可访问', async ({ page }) => {
const response = await page.goto('/ai-sitemap.xml', GOTO_OPTS);
if (response.status() === 200) {
const content = await page.content();
expect(content).toMatch(/xml|sitemap/i);
}
expect([200, 404]).toContain(response.status());
});
test('robots.txt 存在', async ({ page }) => {
const response = await page.goto('/robots.txt', GOTO_OPTS);
expect(response.status()).toBe(200);
});
});
test.describe('前端页面健康', () => {
test('首页无 PHP 错误', async ({ page }) => {
await page.goto('/', GOTO_OPTS);
const content = await page.content();
expect(content).not.toMatch(/Fatal error|Warning:|Parse error|Notice:/);
expect(content).not.toMatch(/Call to undefined/);
});
test('首页无 JS 控制台错误', async ({ page }) => {
const errors = [];
page.on('console', msg => {
if (msg.type() === 'error') errors.push(msg.text());
});
await page.goto('/', GOTO_OPTS);
await page.waitForTimeout(3000);
// 过滤 Playground 环境的已知无害错误
const realErrors = errors.filter(e =>
!e.includes('favicon') &&
!e.includes('net::ERR') &&
!e.includes('404') &&
!e.includes('CORS') &&
!e.includes('Access-Control-Allow-Origin')
);
expect(realErrors).toHaveLength(0);
});
});