mirror of
https://github.com/mozilla/pdf.js.git
synced 2026-06-23 00:15:51 +02:00
Collect coverage data from all workers when closing integration-tests
The "Merge PDF" integration-tests will (indirectly) invoke `PDFViewerApplication.open` as part of loading the new PDF document, which will end up creating a new `PDFWorker` instance. Currently worker coverage is only collected at the end of each integration-test, which means that in these cases we miss the coverage data from any "previous" workers.
This commit is contained in:
parent
feec28583d
commit
2dc73ad2a7
@ -151,19 +151,6 @@ function closePages(pages) {
|
||||
|
||||
async function closeSinglePage(page) {
|
||||
const coverage = await page.evaluate(async () => {
|
||||
// Collect coverage data from the worker before the document is closed.
|
||||
let workerCoverage = null;
|
||||
const handler =
|
||||
window.PDFViewerApplication.pdfDocument?._transport?.messageHandler;
|
||||
if (handler) {
|
||||
try {
|
||||
workerCoverage = await handler.sendWithPromise(
|
||||
"GetWorkerCoverage",
|
||||
null
|
||||
);
|
||||
} catch {}
|
||||
}
|
||||
|
||||
// Close the viewer gracefully, and clear local storage to avoid state
|
||||
// leaking from one test to another.
|
||||
await window.PDFViewerApplication.testingClose();
|
||||
@ -175,16 +162,14 @@ async function closeSinglePage(page) {
|
||||
// logic kicks in (see https://github.com/puppeteer/puppeteer/issues/2427).
|
||||
return {
|
||||
page: window.__coverage__ ? JSON.stringify(window.__coverage__) : null,
|
||||
worker: workerCoverage ? JSON.stringify(workerCoverage) : null,
|
||||
workers: window.__worker_coverage__?.map(c => JSON.stringify(c)) ?? null,
|
||||
};
|
||||
});
|
||||
|
||||
if (coverage.page) {
|
||||
mergeCoverageIntoGlobal(JSON.parse(coverage.page));
|
||||
}
|
||||
if (coverage.worker) {
|
||||
mergeCoverageIntoGlobal(JSON.parse(coverage.worker));
|
||||
}
|
||||
coverage.workers?.map(c => mergeCoverageIntoGlobal(JSON.parse(c)));
|
||||
|
||||
await page.close({ runBeforeUnload: false });
|
||||
}
|
||||
|
||||
17
web/app.js
17
web/app.js
@ -1165,6 +1165,23 @@ const PDFViewerApplication = {
|
||||
// Ignoring errors, to ensure that document closing won't break.
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof PDFJSDev !== "undefined" && PDFJSDev.test("COVERAGE")) {
|
||||
// Collect coverage data from the worker before the document is closed.
|
||||
//
|
||||
// Note that `PDFViewerApplication.open` may be invoked multiple times
|
||||
// during an integration-test (see e.g. the "Merge PDF" tests).
|
||||
const handler = this.pdfDocument?._transport?.messageHandler;
|
||||
if (handler) {
|
||||
try {
|
||||
const workerCoverage = await handler.sendWithPromise(
|
||||
"GetWorkerCoverage",
|
||||
null
|
||||
);
|
||||
(window.__worker_coverage__ ??= []).push(workerCoverage);
|
||||
} catch {}
|
||||
}
|
||||
}
|
||||
const promises = [];
|
||||
|
||||
promises.push(this.pdfLoadingTask.destroy());
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user