Skip to content

Commit

Permalink
Remove redundant done-callback functions from unit-tests which are …
Browse files Browse the repository at this point in the history
…`async`

For unit-tests which are asynchronous, using a `done`-callback is redundant and future Jasmine versions will stop supporting that pattern.
  • Loading branch information
Snuffleupagus committed Mar 21, 2021
1 parent 4814e23 commit eeda221
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 57 deletions.
4 changes: 1 addition & 3 deletions test/unit/annotation_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ describe("annotation", function () {

let pdfManagerMock, idFactoryMock, partialEvaluator;

beforeAll(async function (done) {
beforeAll(async function () {
pdfManagerMock = new PDFManagerMock({
docBaseUrl: null,
});
Expand Down Expand Up @@ -108,8 +108,6 @@ describe("annotation", function () {
fontCache: new RefSetCache(),
builtInCMapCache,
});

done();
});

afterAll(function () {
Expand Down
100 changes: 46 additions & 54 deletions test/unit/api_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2033,78 +2033,70 @@ describe("api", function () {
.catch(done.fail);
});

it("caches image resources at the document/page level as expected (issue 11878)", async function (done) {
it("caches image resources at the document/page level as expected (issue 11878)", async function () {
const { NUM_PAGES_THRESHOLD } = GlobalImageCache,
EXPECTED_WIDTH = 2550,
EXPECTED_HEIGHT = 3300;

const loadingTask = getDocument(buildGetDocumentParams("issue11878.pdf"));
const pdfDoc = await loadingTask.promise;
let firstImgData = null;

try {
const pdfDoc = await loadingTask.promise;
for (let i = 1; i <= pdfDoc.numPages; i++) {
const pdfPage = await pdfDoc.getPage(i);
const opList = await pdfPage.getOperatorList();

for (let i = 1; i <= pdfDoc.numPages; i++) {
const pdfPage = await pdfDoc.getPage(i);
const opList = await pdfPage.getOperatorList();
const { commonObjs, objs } = pdfPage;
const imgIndex = opList.fnArray.indexOf(OPS.paintImageXObject);
const [objId, width, height] = opList.argsArray[imgIndex];

const { commonObjs, objs } = pdfPage;
const imgIndex = opList.fnArray.indexOf(OPS.paintImageXObject);
const [objId, width, height] = opList.argsArray[imgIndex];
if (i < NUM_PAGES_THRESHOLD) {
expect(objId).toEqual(`img_p${i - 1}_1`);

if (i < NUM_PAGES_THRESHOLD) {
expect(objId).toEqual(`img_p${i - 1}_1`);

expect(objs.has(objId)).toEqual(true);
expect(commonObjs.has(objId)).toEqual(false);
} else {
expect(objId).toEqual(
`g_${loadingTask.docId}_img_p${NUM_PAGES_THRESHOLD - 1}_1`
);
expect(objs.has(objId)).toEqual(true);
expect(commonObjs.has(objId)).toEqual(false);
} else {
expect(objId).toEqual(
`g_${loadingTask.docId}_img_p${NUM_PAGES_THRESHOLD - 1}_1`
);

expect(objs.has(objId)).toEqual(false);
expect(commonObjs.has(objId)).toEqual(true);
}
expect(width).toEqual(EXPECTED_WIDTH);
expect(height).toEqual(EXPECTED_HEIGHT);
expect(objs.has(objId)).toEqual(false);
expect(commonObjs.has(objId)).toEqual(true);
}
expect(width).toEqual(EXPECTED_WIDTH);
expect(height).toEqual(EXPECTED_HEIGHT);

// Ensure that the actual image data is identical for all pages.
if (i === 1) {
firstImgData = objs.get(objId);
// Ensure that the actual image data is identical for all pages.
if (i === 1) {
firstImgData = objs.get(objId);

expect(firstImgData.width).toEqual(EXPECTED_WIDTH);
expect(firstImgData.height).toEqual(EXPECTED_HEIGHT);
expect(firstImgData.width).toEqual(EXPECTED_WIDTH);
expect(firstImgData.height).toEqual(EXPECTED_HEIGHT);

expect(firstImgData.kind).toEqual(ImageKind.RGB_24BPP);
expect(firstImgData.data instanceof Uint8ClampedArray).toEqual(
true
);
expect(firstImgData.data.length).toEqual(25245000);
} else {
const objsPool = i >= NUM_PAGES_THRESHOLD ? commonObjs : objs;
const currentImgData = objsPool.get(objId);
expect(firstImgData.kind).toEqual(ImageKind.RGB_24BPP);
expect(firstImgData.data instanceof Uint8ClampedArray).toEqual(true);
expect(firstImgData.data.length).toEqual(25245000);
} else {
const objsPool = i >= NUM_PAGES_THRESHOLD ? commonObjs : objs;
const currentImgData = objsPool.get(objId);

expect(currentImgData.width).toEqual(firstImgData.width);
expect(currentImgData.height).toEqual(firstImgData.height);
expect(currentImgData.width).toEqual(firstImgData.width);
expect(currentImgData.height).toEqual(firstImgData.height);

expect(currentImgData.kind).toEqual(firstImgData.kind);
expect(currentImgData.data instanceof Uint8ClampedArray).toEqual(
true
);
expect(
currentImgData.data.every((value, index) => {
return value === firstImgData.data[index];
})
).toEqual(true);
}
expect(currentImgData.kind).toEqual(firstImgData.kind);
expect(currentImgData.data instanceof Uint8ClampedArray).toEqual(
true
);
expect(
currentImgData.data.every((value, index) => {
return value === firstImgData.data[index];
})
).toEqual(true);
}

await loadingTask.destroy();
firstImgData = null;
done();
} catch (ex) {
done.fail(ex);
}

await loadingTask.destroy();
firstImgData = null;
});
});
describe("Multiple `getDocument` instances", function () {
Expand Down

0 comments on commit eeda221

Please sign in to comment.