Skip to content

Commit 77b9f3a

Browse files
test(annotator): tolerate PDF.js warnings in export regression test
1 parent 3e714f9 commit 77b9f3a

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

‎src/extensions/annotator/painter/annot/__tests__/pdf_export.test.ts‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,21 +131,24 @@ function getNestedNumberArray(dictionary: PDFDict, key: string, index = 0): numb
131131
}
132132

133133
function readAnnotationsWithRealPdfJs(fixturePath: string): Array<Record<string, unknown>> {
134+
const outputMarker = '__INKLAYER_PDFJS_ANNOTATIONS__'
134135
const script = [
135136
"import { readFileSync } from 'node:fs'",
136137
"import { getDocument } from 'pdfjs-dist/legacy/build/pdf.mjs'",
137138
'const task = getDocument({ data: new Uint8Array(readFileSync(process.argv[1])) })',
138139
'const document = await task.promise',
139140
'const page = await document.getPage(1)',
140141
'const annotations = await page.getAnnotations()',
141-
'process.stdout.write(JSON.stringify(annotations, (_key, value) => ArrayBuffer.isView(value) ? Array.from(value) : value))',
142-
'await task.destroy()'
142+
'await task.destroy()',
143+
`process.stdout.write('${outputMarker}' + JSON.stringify(annotations, (_key, value) => ArrayBuffer.isView(value) ? Array.from(value) : value))`
143144
].join(';')
144145
const output = execFileSync(process.execPath, ['--input-type=module', '-e', script, fixturePath], {
145146
encoding: 'utf8',
146147
timeout: 5000
147148
})
148-
return JSON.parse(output) as Array<Record<string, unknown>>
149+
const markerIndex = output.lastIndexOf(outputMarker)
150+
if (markerIndex === -1) throw new Error('PDF.js annotation subprocess returned no result marker.')
151+
return JSON.parse(output.slice(markerIndex + outputMarker.length)) as Array<Record<string, unknown>>
149152
}
150153

151154
function getPpmPixels(data: Buffer): { width: number; height: number; pixels: Buffer } {

0 commit comments

Comments
 (0)