mirror of
https://gitee.com/kekingcn/file-online-preview.git
synced 2026-03-13 20:53:47 +08:00
test(e2e): phase-3 add nightly full run and perf smoke checks (#717)
* test(e2e): phase-3 add nightly workflow and perf smoke suite * test(e2e): address copilot review for phase-3 fixture and readiness flow
This commit is contained in:
47
tests/e2e/specs/perf-smoke.spec.ts
Normal file
47
tests/e2e/specs/perf-smoke.spec.ts
Normal file
@@ -0,0 +1,47 @@
|
||||
import { test, expect, request as playwrightRequest } from '@playwright/test';
|
||||
|
||||
const fixtureBase = process.env.FIXTURE_BASE_URL || 'http://127.0.0.1:18080';
|
||||
const envMaxMs = Number(process.env.E2E_MAX_PREVIEW_MS);
|
||||
const maxMs = Number.isFinite(envMaxMs) ? envMaxMs : 15000;
|
||||
|
||||
function b64(v: string): string {
|
||||
return Buffer.from(v).toString('base64');
|
||||
}
|
||||
|
||||
async function timedPreview(request: any, fileUrl: string) {
|
||||
const started = Date.now();
|
||||
const resp = await request.get(`/onlinePreview?url=${b64(fileUrl)}`);
|
||||
const elapsed = Date.now() - started;
|
||||
return { resp, elapsed };
|
||||
}
|
||||
|
||||
test.beforeAll(async () => {
|
||||
const api = await playwrightRequest.newContext();
|
||||
const required = ['sample.txt', 'sample.docx', 'sample.xlsx'];
|
||||
try {
|
||||
for (const name of required) {
|
||||
const resp = await api.get(`${fixtureBase}/${name}`);
|
||||
expect(resp.ok(), `fixture missing or unavailable: ${name}`).toBeTruthy();
|
||||
}
|
||||
} finally {
|
||||
await api.dispose();
|
||||
}
|
||||
});
|
||||
|
||||
test('perf: txt preview response under threshold', async ({ request }) => {
|
||||
const { resp, elapsed } = await timedPreview(request, `${fixtureBase}/sample.txt`);
|
||||
expect(resp.status()).toBe(200);
|
||||
expect(elapsed).toBeLessThan(maxMs);
|
||||
});
|
||||
|
||||
test('perf: docx preview response under threshold', async ({ request }) => {
|
||||
const { resp, elapsed } = await timedPreview(request, `${fixtureBase}/sample.docx`);
|
||||
expect(resp.status()).toBe(200);
|
||||
expect(elapsed).toBeLessThan(maxMs);
|
||||
});
|
||||
|
||||
test('perf: xlsx preview response under threshold', async ({ request }) => {
|
||||
const { resp, elapsed } = await timedPreview(request, `${fixtureBase}/sample.xlsx`);
|
||||
expect(resp.status()).toBe(200);
|
||||
expect(elapsed).toBeLessThan(maxMs);
|
||||
});
|
||||
Reference in New Issue
Block a user