mirror of
https://github.com/jackwener/OpenCLI.git
synced 2026-09-14 18:25:42 +08:00
788b069c02
## Changes ### E2E Test Suite (~52 test cases) - public-commands.test.ts — Public API commands (hackernews, v2ex) - browser-public.test.ts — Browser commands for public data across all sites - browser-auth.test.ts — Graceful failure verification for login-required commands - management.test.ts — Full coverage of management commands - output-formats.test.ts — Output format validation (json/yaml/csv/md) - smoke/api-health.test.ts — Scheduled API health checks ### Auto-detect Browser Mode - buildMcpArgs uses CI env var to select mode: - Local (no CI) → --extension (connect to user's Chrome) - CI → standalone (launches its own browser) ### CI Pipeline - e2e-headed.yml — Real Chrome via setup-chrome + xvfb in headed mode - ci.yml — build + unit-test (2 shards) + smoke-test (scheduled/manual) - Composite action for shared Chrome + xvfb setup ### Documentation - New TESTING.md — Architecture, coverage, local setup, how to add tests Co-authored-by: AlexYue <yj976240184@qq.com>
49 lines
1.4 KiB
TypeScript
49 lines
1.4 KiB
TypeScript
/**
|
|
* E2E tests for output format rendering.
|
|
* Uses hackernews (public, fast) as a stable data source.
|
|
*/
|
|
|
|
import { describe, it, expect } from 'vitest';
|
|
import { runCli, parseJsonOutput } from './helpers.js';
|
|
|
|
const FORMATS = ['json', 'yaml', 'csv', 'md'] as const;
|
|
|
|
describe('output formats E2E', () => {
|
|
for (const fmt of FORMATS) {
|
|
it(`hackernews top -f ${fmt} produces valid output`, async () => {
|
|
const { stdout, code } = await runCli(['hackernews', 'top', '--limit', '2', '-f', fmt]);
|
|
expect(code).toBe(0);
|
|
expect(stdout.trim().length).toBeGreaterThan(0);
|
|
|
|
if (fmt === 'json') {
|
|
const data = parseJsonOutput(stdout);
|
|
expect(Array.isArray(data)).toBe(true);
|
|
expect(data.length).toBe(2);
|
|
}
|
|
|
|
if (fmt === 'yaml') {
|
|
expect(stdout).toContain('title:');
|
|
}
|
|
|
|
if (fmt === 'csv') {
|
|
// CSV should have a header row + data rows
|
|
const lines = stdout.trim().split('\n');
|
|
expect(lines.length).toBeGreaterThanOrEqual(2);
|
|
}
|
|
|
|
if (fmt === 'md') {
|
|
// Markdown table should have pipe characters
|
|
expect(stdout).toContain('|');
|
|
}
|
|
}, 30_000);
|
|
}
|
|
|
|
it('list -f csv produces valid csv', async () => {
|
|
const { stdout, code } = await runCli(['list', '-f', 'csv']);
|
|
expect(code).toBe(0);
|
|
const lines = stdout.trim().split('\n');
|
|
// Header + many data lines
|
|
expect(lines.length).toBeGreaterThan(50);
|
|
});
|
|
});
|