test(e2e): fix preflight fixture scope and path handling

This commit is contained in:
kl
2026-03-04 12:54:42 +08:00
parent 7f6ad472c4
commit 3b0f7af382
3 changed files with 9 additions and 5 deletions

View File

@@ -26,7 +26,7 @@ mvn -q -pl server -DskipTests package
cd tests/e2e
npm install
npx playwright install --with-deps chromium
pip3 install -r tests/e2e/requirements.txt
pip3 install -r requirements.txt
```
3. Generate fixtures and start fixture server:

View File

@@ -1,8 +1,10 @@
import fs from 'node:fs';
import path from 'node:path';
import { execFileSync } from 'node:child_process';
import { fileURLToPath } from 'node:url';
const fixturesDir = path.resolve(process.cwd(), 'tests/e2e/fixtures');
const __dirname = path.dirname(fileURLToPath(import.meta.url));
const fixturesDir = path.resolve(__dirname, '..', 'fixtures');
fs.mkdirSync(fixturesDir, { recursive: true });
const write = (name, content) => fs.writeFileSync(path.join(fixturesDir, name), content);

View File

@@ -1,4 +1,4 @@
import { test, expect } from '@playwright/test';
import { test, expect, request as playwrightRequest } from '@playwright/test';
const fixtureBase = process.env.FIXTURE_BASE_URL || 'http://127.0.0.1:18080';
@@ -11,12 +11,14 @@ async function openPreview(request: any, fileUrl: string) {
return request.get(`/onlinePreview?url=${encoded}`);
}
test.beforeAll(async ({ request }) => {
test.beforeAll(async () => {
const api = await playwrightRequest.newContext();
const required = ['sample.txt', 'sample.docx', 'sample.xlsx', 'sample.pptx', 'sample.zip'];
for (const name of required) {
const resp = await request.get(`${fixtureBase}/${name}`);
const resp = await api.get(`${fixtureBase}/${name}`);
expect(resp.ok(), `fixture missing or unavailable: ${name}`).toBeTruthy();
}
await api.dispose();
});
test('01 home/index reachable', async ({ request }) => {