first commit
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
import { test, expect, request as playwrightRequest } from '@playwright/test';
|
||||
import type { APIRequestContext } from '@playwright/test';
|
||||
|
||||
const fixtureBase = process.env.FIXTURE_BASE_URL || 'http://127.0.0.1:18080';
|
||||
const DEFAULT_MAX_MS = 15000;
|
||||
const envMaxMs = Number(process.env.E2E_MAX_PREVIEW_MS);
|
||||
const maxMs = Number.isFinite(envMaxMs) && envMaxMs >= 1 ? Math.floor(envMaxMs) : DEFAULT_MAX_MS;
|
||||
|
||||
function b64(v: string): string {
|
||||
return Buffer.from(v).toString('base64');
|
||||
}
|
||||
|
||||
async function timedPreview(request: APIRequestContext, fileUrl: string) {
|
||||
const started = Date.now();
|
||||
const resp = await request.get(`/onlinePreview?url=${encodeURIComponent(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