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:
kl
2026-03-04 15:06:15 +08:00
committed by GitHub
parent bb457924cd
commit 68d4d23a4b
5 changed files with 194 additions and 1 deletions

View File

@@ -11,6 +11,7 @@ This folder contains a first MVP of end-to-end automated tests.
- Security regression checks for blocked internal-network hosts (`10.*`) on:
- `/onlinePreview`
- `/getCorsFile`
- Basic performance smoke checks (configurable threshold): txt/docx/xlsx preview response time
## Local run
@@ -52,3 +53,13 @@ KK_TRUST_HOST='*' KK_NOT_TRUST_HOST='10.*,172.16.*,192.168.*' java -jar "$JAR_PA
cd tests/e2e
KK_BASE_URL=http://127.0.0.1:8012 FIXTURE_BASE_URL=http://127.0.0.1:18080 npm test
```
Optional:
```bash
# smoke only (self-contained: will auto-generate fixtures)
npm run test:smoke
# perf smoke (self-contained; default threshold 15000ms)
E2E_MAX_PREVIEW_MS=15000 npm run test:perf
```

View File

@@ -9,7 +9,11 @@
"gen:all": "npm run gen:fixtures && npm run gen:office",
"pretest": "npm run gen:all",
"test": "playwright test",
"test:headed": "playwright test --headed"
"test:headed": "playwright test --headed",
"pretest:smoke": "npm run gen:all",
"test:smoke": "playwright test specs/preview-smoke.spec.ts",
"pretest:perf": "npm run gen:all",
"test:perf": "playwright test specs/perf-smoke.spec.ts"
},
"devDependencies": {
"@playwright/test": "^1.55.0"

View File

@@ -4,8 +4,10 @@ export default defineConfig({
testDir: './specs',
timeout: 30_000,
expect: { timeout: 10_000 },
retries: process.env.CI ? 1 : 0,
reporter: [['list'], ['html', { outputFolder: 'playwright-report', open: 'never' }]],
use: {
baseURL: process.env.KK_BASE_URL || 'http://127.0.0.1:8012',
trace: 'on-first-retry',
},
});

View 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);
});