diff --git a/.gitea/workflows/build.yml b/.gitea/workflows/build.yml index 98f5a1d..924b6b4 100644 --- a/.gitea/workflows/build.yml +++ b/.gitea/workflows/build.yml @@ -21,6 +21,9 @@ jobs: - name: Install dev dependencies run: npm ci || npm install + - name: Install PyMuPDF (PDF text assertions) + run: python3 -m pip install --quiet pymupdf + - name: Run tests run: npm test diff --git a/test/pdf.test.js b/test/pdf.test.js index b02362b..b47799e 100644 --- a/test/pdf.test.js +++ b/test/pdf.test.js @@ -38,7 +38,19 @@ function extractPdfText(bytes) { 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); assert.ok(bytes instanceof Uint8Array); 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); assert.strictEqual(doc.getPageCount(), 1); + if (!fitzAvailable()) { + t.skip('PyMuPDF (fitz) not available; skipping PDF text assertions'); + return; + } + const text = extractPdfText(bytes); 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');