From 7f6ad472c4c09077840a051e02e74844eab1b710 Mon Sep 17 00:00:00 2001 From: kl Date: Wed, 4 Mar 2026 12:05:31 +0800 Subject: [PATCH] test(e2e): address copilot review for fixture stability and CI python setup --- .github/workflows/pr-e2e-mvp.yml | 9 +++++++-- tests/e2e/.gitignore | 3 +++ tests/e2e/README.md | 2 +- tests/e2e/package.json | 8 +++++--- tests/e2e/requirements.txt | 3 +++ tests/e2e/scripts/generate-fixtures.mjs | 21 ++++++++++++--------- tests/e2e/specs/preview-smoke.spec.ts | 8 ++++++++ 7 files changed, 39 insertions(+), 15 deletions(-) create mode 100644 tests/e2e/requirements.txt diff --git a/.github/workflows/pr-e2e-mvp.yml b/.github/workflows/pr-e2e-mvp.yml index e4c08ac8..31f47697 100644 --- a/.github/workflows/pr-e2e-mvp.yml +++ b/.github/workflows/pr-e2e-mvp.yml @@ -31,6 +31,11 @@ jobs: cache: 'npm' cache-dependency-path: tests/e2e/package-lock.json + - name: Setup Python 3.11 + uses: actions/setup-python@v5 + with: + python-version: '3.11' + - name: Install LibreOffice + zip run: | sudo apt-get update @@ -38,8 +43,8 @@ jobs: - name: Setup Python deps for office fixtures run: | - python3 -m pip install --upgrade pip - pip3 install python-docx openpyxl python-pptx + python -m pip install --upgrade pip + pip install -r tests/e2e/requirements.txt - name: Build kkFileView run: mvn -q -pl server -DskipTests package diff --git a/tests/e2e/.gitignore b/tests/e2e/.gitignore index 4a9ea05f..f3b87092 100644 --- a/tests/e2e/.gitignore +++ b/tests/e2e/.gitignore @@ -4,3 +4,6 @@ test-results/ __pycache__/ fixtures/zip-tmp/ +fixtures/sample.docx +fixtures/sample.xlsx +fixtures/sample.pptx diff --git a/tests/e2e/README.md b/tests/e2e/README.md index 3a3d5fc9..35eb6276 100644 --- a/tests/e2e/README.md +++ b/tests/e2e/README.md @@ -26,7 +26,7 @@ mvn -q -pl server -DskipTests package cd tests/e2e npm install npx playwright install --with-deps chromium -pip3 install python-docx openpyxl python-pptx +pip3 install -r tests/e2e/requirements.txt ``` 3. Generate fixtures and start fixture server: diff --git a/tests/e2e/package.json b/tests/e2e/package.json index 868716ee..6e08946d 100644 --- a/tests/e2e/package.json +++ b/tests/e2e/package.json @@ -4,10 +4,12 @@ "version": "0.1.0", "type": "module", "scripts": { - "test": "playwright test", - "test:headed": "playwright test --headed", "gen:fixtures": "node ./scripts/generate-fixtures.mjs", - "gen:office": "python3 ./scripts/generate-office-fixtures.py" + "gen:office": "python3 ./scripts/generate-office-fixtures.py", + "gen:all": "npm run gen:fixtures && npm run gen:office", + "pretest": "npm run gen:all", + "test": "playwright test", + "test:headed": "playwright test --headed" }, "devDependencies": { "@playwright/test": "^1.55.0" diff --git a/tests/e2e/requirements.txt b/tests/e2e/requirements.txt new file mode 100644 index 00000000..663606bb --- /dev/null +++ b/tests/e2e/requirements.txt @@ -0,0 +1,3 @@ +python-docx==1.1.2 +openpyxl==3.1.5 +python-pptx==1.0.2 diff --git a/tests/e2e/scripts/generate-fixtures.mjs b/tests/e2e/scripts/generate-fixtures.mjs index 6a96daab..c35db03f 100644 --- a/tests/e2e/scripts/generate-fixtures.mjs +++ b/tests/e2e/scripts/generate-fixtures.mjs @@ -1,6 +1,6 @@ import fs from 'node:fs'; import path from 'node:path'; -import { execSync } from 'node:child_process'; +import { execFileSync } from 'node:child_process'; const fixturesDir = path.resolve(process.cwd(), 'tests/e2e/fixtures'); fs.mkdirSync(fixturesDir, { recursive: true }); @@ -14,14 +14,17 @@ write('sample.xml', 'kkFileViewtrue'); write('sample.csv', 'name,value\nkkFileView,1\ne2e,1\n'); write('sample.html', '

kkFileView fixture

'); -// zip (contains txt) -const zipWork = path.join(fixturesDir, 'zip-tmp'); -fs.mkdirSync(zipWork, { recursive: true }); -fs.writeFileSync(path.join(zipWork, 'inner.txt'), 'kkFileView zip inner file'); -try { - execSync(`cd "${zipWork}" && zip -q -r "${path.join(fixturesDir, 'sample.zip')}" inner.txt`); -} catch { - // fallback: keep going if zip is not available locally +// zip (contains txt) - only generate if missing to avoid noisy local diffs +const zipPath = path.join(fixturesDir, 'sample.zip'); +if (!fs.existsSync(zipPath)) { + const zipWork = path.join(fixturesDir, 'zip-tmp'); + fs.mkdirSync(zipWork, { recursive: true }); + fs.writeFileSync(path.join(zipWork, 'inner.txt'), 'kkFileView zip inner file'); + try { + execFileSync('zip', ['-X', '-q', '-r', zipPath, 'inner.txt'], { cwd: zipWork }); + } catch { + // fallback: keep going if zip is not available locally + } } // 1x1 png diff --git a/tests/e2e/specs/preview-smoke.spec.ts b/tests/e2e/specs/preview-smoke.spec.ts index 34a37d61..8d307a94 100644 --- a/tests/e2e/specs/preview-smoke.spec.ts +++ b/tests/e2e/specs/preview-smoke.spec.ts @@ -11,6 +11,14 @@ async function openPreview(request: any, fileUrl: string) { return request.get(`/onlinePreview?url=${encoded}`); } +test.beforeAll(async ({ request }) => { + const required = ['sample.txt', 'sample.docx', 'sample.xlsx', 'sample.pptx', 'sample.zip']; + for (const name of required) { + const resp = await request.get(`${fixtureBase}/${name}`); + expect(resp.ok(), `fixture missing or unavailable: ${name}`).toBeTruthy(); + } +}); + test('01 home/index reachable', async ({ request }) => { const resp = await request.get('/'); expect(resp.status()).toBeLessThan(500);