Skip to content

Commit

Permalink
Added test to repro issue #166
Browse files Browse the repository at this point in the history
  • Loading branch information
jjhbw committed Nov 13, 2020
1 parent d0d21ee commit d39b479
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
Binary file added src/__tests__/fixtures/imageSimple.docx
Binary file not shown.
52 changes: 52 additions & 0 deletions src/__tests__/images.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,3 +176,55 @@ it('004: can inject an image in the document header (regression test for #113)',
// the main document
return expect(createReport(opts)).resolves.toBeInstanceOf(Uint8Array);
});

it('005: can inject PNG files using ArrayBuffers without errors (related to issue #166)', async () => {
const template = await fs.promises.readFile(
path.join(__dirname, 'fixtures', 'imageSimple.docx')
);

const buff = await fs.promises.readFile(
path.join(__dirname, 'fixtures', 'sample.png')
);

function toArrayBuffer(buf: Buffer): ArrayBuffer {
const ab = new ArrayBuffer(buf.length);
const view = new Uint8Array(ab);
for (let i = 0; i < buf.length; ++i) {
view[i] = buf[i];
}
return ab;
}

const fromAB = await createReport({
template,
data: {},
additionalJsContext: {
injectImg: () => {
return {
width: 6,
height: 6,
data: toArrayBuffer(buff),
extension: '.png',
};
},
},
});

const fromB = await createReport({
template,
data: {},
additionalJsContext: {
injectImg: () => {
return {
width: 6,
height: 6,
data: buff,
extension: '.png',
};
},
},
});
expect(fromAB).toBeInstanceOf(Uint8Array);
expect(fromB).toBeInstanceOf(Uint8Array);
expect(fromAB).toStrictEqual(fromB);
});

0 comments on commit d39b479

Please sign in to comment.