mirror of
https://gitee.com/kekingcn/file-online-preview.git
synced 2026-03-14 05:03:49 +08:00
test(e2e): phase-2 add Office and zip smoke automation (#714)
* test(e2e): phase-2 add office and zip smoke coverage * test(e2e): address copilot review for fixture stability and CI python setup * test(e2e): fix preflight fixture scope and path handling * test(e2e): harden fixture preflight and remove duplicate generation * test(e2e): remove redundant zip install and cleanup temp zip dir * test(e2e): ensure zip dependency and unify python command in docs * docs(e2e): align README with npm gen scripts and python3 usage
This commit is contained in:
@@ -1,7 +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);
|
||||
@@ -13,6 +16,22 @@ write('sample.xml', '<root><name>kkFileView</name><e2e>true</e2e></root>');
|
||||
write('sample.csv', 'name,value\nkkFileView,1\ne2e,1\n');
|
||||
write('sample.html', '<!doctype html><html><body><h1>kkFileView fixture</h1></body></html>');
|
||||
|
||||
// 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 (err) {
|
||||
console.error('Failed to create sample.zip fixture. Ensure "zip" is installed and available in PATH.');
|
||||
throw err instanceof Error ? err : new Error(String(err));
|
||||
} finally {
|
||||
fs.rmSync(zipWork, { recursive: true, force: true });
|
||||
}
|
||||
}
|
||||
|
||||
// 1x1 png
|
||||
write(
|
||||
'sample.png',
|
||||
|
||||
35
tests/e2e/scripts/generate-office-fixtures.py
Normal file
35
tests/e2e/scripts/generate-office-fixtures.py
Normal file
@@ -0,0 +1,35 @@
|
||||
#!/usr/bin/env python3
|
||||
from pathlib import Path
|
||||
|
||||
from docx import Document
|
||||
from openpyxl import Workbook
|
||||
from pptx import Presentation
|
||||
|
||||
fixtures = Path(__file__).resolve().parent.parent / "fixtures"
|
||||
fixtures.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
# DOCX
|
||||
_doc = Document()
|
||||
_doc.add_heading("kkFileView E2E", level=1)
|
||||
_doc.add_paragraph("This is a DOCX fixture for Phase-2 E2E.")
|
||||
_doc.save(fixtures / "sample.docx")
|
||||
|
||||
# XLSX
|
||||
_wb = Workbook()
|
||||
_ws = _wb.active
|
||||
_ws.title = "Sheet1"
|
||||
_ws["A1"] = "name"
|
||||
_ws["B1"] = "value"
|
||||
_ws["A2"] = "kkFileView"
|
||||
_ws["B2"] = 2
|
||||
_wb.save(fixtures / "sample.xlsx")
|
||||
|
||||
# PPTX
|
||||
_prs = Presentation()
|
||||
slide_layout = _prs.slide_layouts[1]
|
||||
slide = _prs.slides.add_slide(slide_layout)
|
||||
slide.shapes.title.text = "kkFileView E2E"
|
||||
slide.placeholders[1].text = "This is a PPTX fixture for Phase-2 E2E."
|
||||
_prs.save(fixtures / "sample.pptx")
|
||||
|
||||
print("office fixtures generated in", fixtures)
|
||||
Reference in New Issue
Block a user