From e12c1e59acd5fc66ec274395f3c0f88713daf5b4 Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Sun, 28 May 2023 19:16:44 +0100 Subject: Add toArrayBuffer when embedding a style map --- test/mammoth.tests.js | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) (limited to 'test') diff --git a/test/mammoth.tests.js b/test/mammoth.tests.js index 9f0e902..3b1726e 100644 --- a/test/mammoth.tests.js +++ b/test/mammoth.tests.js @@ -122,14 +122,33 @@ test('embedded style maps can be disabled', function() { }); }); -test('embedded style map can be written and then read', function() { +test('embedded style map can be written using toBuffer() and then read', function() { var docxPath = path.join(__dirname, "test-data/single-paragraph.docx"); return promises.nfcall(fs.readFile, docxPath) .then(function(buffer) { return mammoth.embedStyleMap({buffer: buffer}, "p => h1"); }) .then(function(docx) { - return mammoth.convertToHtml({buffer: docx.toBuffer()}); + var buffer = docx.toBuffer(); + assert.ok(Buffer.isBuffer(buffer)); + return mammoth.convertToHtml({buffer: buffer}); + }) + .then(function(result) { + assert.equal(result.value, "

Walking on imported air

"); + assert.deepEqual(result.messages, []); + }); +}); + +test('embedded style map can be written using toArrayBuffer() and then read', function() { + var docxPath = path.join(__dirname, "test-data/single-paragraph.docx"); + return promises.nfcall(fs.readFile, docxPath) + .then(function(buffer) { + return mammoth.embedStyleMap({buffer: buffer}, "p => h1"); + }) + .then(function(docx) { + var arrayBuffer = docx.toArrayBuffer(); + assert.ok(!Buffer.isBuffer(arrayBuffer)); + return mammoth.convertToHtml({buffer: Buffer.from(arrayBuffer)}); }) .then(function(result) { assert.equal(result.value, "

Walking on imported air

"); -- cgit v1.2.3