ci: install PyMuPDF in runner; skip PDF text assertions when fitz is unavailable
build-extension / build (push) Failing after 20s
build-extension / build (push) Failing after 20s
This commit is contained in:
@@ -21,6 +21,9 @@ jobs:
|
|||||||
- name: Install dev dependencies
|
- name: Install dev dependencies
|
||||||
run: npm ci || npm install
|
run: npm ci || npm install
|
||||||
|
|
||||||
|
- name: Install PyMuPDF (PDF text assertions)
|
||||||
|
run: python3 -m pip install --quiet pymupdf
|
||||||
|
|
||||||
- name: Run tests
|
- name: Run tests
|
||||||
run: npm test
|
run: npm test
|
||||||
|
|
||||||
|
|||||||
+18
-1
@@ -38,7 +38,19 @@ function extractPdfText(bytes) {
|
|||||||
return execFileSync('python3', ['-c', script], { encoding: 'utf8' });
|
return execFileSync('python3', ['-c', script], { encoding: 'utf8' });
|
||||||
}
|
}
|
||||||
|
|
||||||
test('buildStudyLoadPdf returns valid PDF bytes', async () => {
|
// PyMuPDF (fitz) is only needed for the text-extraction assertions below. It is
|
||||||
|
// installed in CI, but if it is missing locally we skip those assertions rather
|
||||||
|
// than hard-failing.
|
||||||
|
function fitzAvailable() {
|
||||||
|
try {
|
||||||
|
execFileSync('python3', ['-c', 'import fitz'], { stdio: 'ignore' });
|
||||||
|
return true;
|
||||||
|
} catch {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
test('buildStudyLoadPdf returns valid PDF bytes', async (t) => {
|
||||||
const bytes = await buildStudyLoadPdf(sampleData);
|
const bytes = await buildStudyLoadPdf(sampleData);
|
||||||
assert.ok(bytes instanceof Uint8Array);
|
assert.ok(bytes instanceof Uint8Array);
|
||||||
const head = Buffer.from(bytes.slice(0, 5)).toString('latin1');
|
const head = Buffer.from(bytes.slice(0, 5)).toString('latin1');
|
||||||
@@ -46,6 +58,11 @@ test('buildStudyLoadPdf returns valid PDF bytes', async () => {
|
|||||||
const doc = await PDFLib.PDFDocument.load(bytes);
|
const doc = await PDFLib.PDFDocument.load(bytes);
|
||||||
assert.strictEqual(doc.getPageCount(), 1);
|
assert.strictEqual(doc.getPageCount(), 1);
|
||||||
|
|
||||||
|
if (!fitzAvailable()) {
|
||||||
|
t.skip('PyMuPDF (fitz) not available; skipping PDF text assertions');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const text = extractPdfText(bytes);
|
const text = extractPdfText(bytes);
|
||||||
assert.ok(text.includes('CIS 2101'), 'PDF text should contain course code CIS 2101');
|
assert.ok(text.includes('CIS 2101'), 'PDF text should contain course code CIS 2101');
|
||||||
assert.ok(text.includes("STUDENT'S STUDY LOAD"), 'PDF text should contain the title');
|
assert.ok(text.includes("STUDENT'S STUDY LOAD"), 'PDF text should contain the title');
|
||||||
|
|||||||
Reference in New Issue
Block a user