Files
jackwener 92408e7ee9 fix: improve E2E testing infrastructure
- buildMcpArgs: use CI env var instead of token detection (preserves local behavior)
- browser.test.ts: align tests with CI-based mode detection
- api-health.test.ts: remove duplicate xueqiu entry
- browser-public.test.ts: unify BBC test with tryBrowserCommand
- vitest.config.ts: default to unit tests only (E2E via explicit path)
- ci.yml: remove unnecessary needs:build for unit-test, use composite action
- e2e-headed.yml: use composite action, increase timeout to 20min
- Add .github/actions/setup-chrome composite action for shared CI steps
2026-03-16 17:33:25 +08:00

73 lines
2.6 KiB
TypeScript

/**
* Smoke tests for external API health.
* Only run on schedule or manual dispatch — NOT on every push/PR.
* These verify that external APIs haven't changed their structure.
*/
import { describe, it, expect } from 'vitest';
import { runCli, parseJsonOutput } from '../e2e/helpers.js';
describe('API health smoke tests', () => {
// ── Public API commands (should always work) ──
it('hackernews API is responsive and returns expected structure', async () => {
const { stdout, code } = await runCli(['hackernews', 'top', '--limit', '5', '-f', 'json']);
expect(code).toBe(0);
const data = parseJsonOutput(stdout);
expect(data.length).toBe(5);
for (const item of data) {
expect(item).toHaveProperty('title');
expect(item).toHaveProperty('score');
expect(item).toHaveProperty('author');
expect(item).toHaveProperty('rank');
}
}, 30_000);
it('v2ex hot API is responsive', async () => {
const { stdout, code } = await runCli(['v2ex', 'hot', '--limit', '3', '-f', 'json']);
expect(code).toBe(0);
const data = parseJsonOutput(stdout);
expect(data.length).toBeGreaterThanOrEqual(1);
expect(data[0]).toHaveProperty('title');
}, 30_000);
it('v2ex latest API is responsive', async () => {
const { stdout, code } = await runCli(['v2ex', 'latest', '--limit', '3', '-f', 'json']);
expect(code).toBe(0);
const data = parseJsonOutput(stdout);
expect(data.length).toBeGreaterThanOrEqual(1);
}, 30_000);
it('v2ex topic API is responsive', async () => {
const { stdout, code } = await runCli(['v2ex', 'topic', '--id', '1000001', '-f', 'json']);
if (code === 0) {
const data = parseJsonOutput(stdout);
expect(data).toBeDefined();
}
}, 30_000);
// ── Validate all adapters ──
it('all adapter definitions are valid', async () => {
const { stdout, code } = await runCli(['validate']);
expect(code).toBe(0);
expect(stdout).toContain('PASS');
});
// ── Command registry integrity ──
it('all expected sites are registered', async () => {
const { stdout, code } = await runCli(['list', '-f', 'json']);
expect(code).toBe(0);
const data = parseJsonOutput(stdout);
const sites = new Set(data.map((d: any) => d.site));
// Verify all 17 sites are present
for (const expected of [
'hackernews', 'bbc', 'bilibili', 'v2ex', 'weibo', 'zhihu',
'twitter', 'reddit', 'xueqiu', 'reuters', 'youtube',
'smzdm', 'boss', 'ctrip', 'coupang', 'xiaohongshu',
'yahoo-finance',
]) {
expect(sites.has(expected)).toBe(true);
}
});
});