diff options
| author | Michael Williamson <mike@zwobble.org> | 2021-08-27 19:42:39 +0100 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2021-08-27 19:42:39 +0100 |
| commit | b6ab371b1f004a627f7390c442b6406d1f2be499 (patch) | |
| tree | 046ea608e145bd7c27fb203d319a08f530375ead /test | |
| parent | e0bb3d1cdac963f2c07ab782ad945d585a9babeb (diff) | |
Update JSZip to 3.2.0
Diffstat (limited to 'test')
| -rw-r--r-- | test/docx/style-map.tests.js | 89 | ||||
| -rw-r--r-- | test/zipfile.tests.js | 22 |
2 files changed, 57 insertions, 54 deletions
diff --git a/test/docx/style-map.tests.js b/test/docx/style-map.tests.js index 4ddb127..5f60dd6 100644 --- a/test/docx/style-map.tests.js +++ b/test/docx/style-map.tests.js @@ -7,77 +7,77 @@ var styleMap = require("../../lib/docx/style-map"); var test = require("../test")(module); test('reading embedded style map on document without embedded style map returns null', function() { - var zip = normalDocx(); - - return styleMap.readStyleMap(zip).then(function(contents) { - assert.equal(contents, null); + return normalDocx().then(function(zip) { + return styleMap.readStyleMap(zip).then(function(contents) { + assert.equal(contents, null); + }); }); }); test('embedded style map can be read after being written', function() { - var zip = normalDocx(); - - return styleMap.writeStyleMap(zip, "p => h1").then(function() { - return styleMap.readStyleMap(zip).then(function(contents) { - assert.equal(contents, "p => h1"); + return normalDocx().then(function(zip) { + return styleMap.writeStyleMap(zip, "p => h1").then(function() { + return styleMap.readStyleMap(zip).then(function(contents) { + assert.equal(contents, "p => h1"); + }); }); }); }); test('embedded style map is written to separate file', function() { - var zip = normalDocx(); - - return styleMap.writeStyleMap(zip, "p => h1").then(function() { - return zip.read("mammoth/style-map", "utf8").then(function(contents) { - assert.equal(contents, "p => h1"); + return normalDocx().then(function(zip) { + return styleMap.writeStyleMap(zip, "p => h1").then(function() { + return zip.read("mammoth/style-map", "utf8").then(function(contents) { + assert.equal(contents, "p => h1"); + }); }); }); }); test('embedded style map is referenced in relationships', function() { - var zip = normalDocx(); - - return styleMap.writeStyleMap(zip, "p => h1").then(function() { - return zip.read("word/_rels/document.xml.rels", "utf8").then(function(contents) { - assert.equal(contents, expectedRelationshipsXml); + return normalDocx().then(function(zip) { + return styleMap.writeStyleMap(zip, "p => h1").then(function() { + return zip.read("word/_rels/document.xml.rels", "utf8").then(function(contents) { + assert.equal(contents, expectedRelationshipsXml); + }); }); }); }); test('re-embedding style map replaces original', function() { - var zip = normalDocx(); - - return styleMap.writeStyleMap(zip, "p => h1").then(function() { - return styleMap.writeStyleMap(zip, "p => h2"); - }).then(function() { - return zip.read("word/_rels/document.xml.rels", "utf8").then(function(contents) { - assert.equal(contents, expectedRelationshipsXml); - }); - }).then(function() { - return styleMap.readStyleMap(zip).then(function(contents) { - assert.equal(contents, "p => h2"); + return normalDocx().then(function(zip) { + return styleMap.writeStyleMap(zip, "p => h1").then(function() { + return styleMap.writeStyleMap(zip, "p => h2"); + }).then(function() { + return zip.read("word/_rels/document.xml.rels", "utf8").then(function(contents) { + assert.equal(contents, expectedRelationshipsXml); + }); + }).then(function() { + return styleMap.readStyleMap(zip).then(function(contents) { + assert.equal(contents, "p => h2"); + }); }); }); }); test('embedded style map has override content type in [Content_Types].xml', function() { - var zip = normalDocx(); - - return styleMap.writeStyleMap(zip, "p => h1").then(function() { - return zip.read("[Content_Types].xml", "utf8").then(function(contents) { - assert.equal(contents, expectedContentTypesXml); + return normalDocx().then(function(zip) { + return styleMap.writeStyleMap(zip, "p => h1").then(function() { + return zip.read("[Content_Types].xml", "utf8").then(function(contents) { + assert.equal(contents, expectedContentTypesXml); + }); }); }); }); test('replacing style map keeps content type', function() { - var zip = normalDocx(); - - return styleMap.writeStyleMap(zip, "p => h1").then(function() { - return styleMap.writeStyleMap(zip, "p => h2"); - }).then(function() { - return zip.read("[Content_Types].xml", "utf8").then(function(contents) { - assert.equal(contents, expectedContentTypesXml); + return normalDocx().then(function(zip) { + return styleMap.writeStyleMap(zip, "p => h1").then(function() { + return styleMap.writeStyleMap(zip, "p => h2"); + }).then(function() { + return zip.read("[Content_Types].xml", "utf8").then(function(contents) { + assert.equal(contents, expectedContentTypesXml); + }); }); }); }); @@ -106,7 +106,8 @@ function normalDocx() { '</Types>'; zip.file("word/_rels/document.xml.rels", originalRelationshipsXml); zip.file("[Content_Types].xml", originalContentTypesXml); - var buffer = zip.generate({type: "arraybuffer"}); - return zipfile.openArrayBuffer(buffer); + return zip.generateAsync({type: "arraybuffer"}).then(function(buffer) { + return zipfile.openArrayBuffer(buffer); + }); } diff --git a/test/zipfile.tests.js b/test/zipfile.tests.js index 5383c49..cf11804 100644 --- a/test/zipfile.tests.js +++ b/test/zipfile.tests.js @@ -6,21 +6,23 @@ var zipfile = require("../lib/zipfile"); var test = require("./test")(module); test('file in zip can be read after being written', function() { - var zip = emptyZipFile(); - assert(!zip.exists("song/title")); - - zip.write("song/title", "Dark Blue"); - - assert(zip.exists("song/title")); - return zip.read("song/title", "utf8").then(function(contents) { - assert.equal(contents, "Dark Blue"); + return emptyZipFile().then(function(zip) { + assert(!zip.exists("song/title")); + + zip.write("song/title", "Dark Blue"); + + assert(zip.exists("song/title")); + return zip.read("song/title", "utf8").then(function(contents) { + assert.equal(contents, "Dark Blue"); + }); }); }); function emptyZipFile() { var zip = new JSZip(); - var buffer = zip.generate({type: "arraybuffer"}); - return zipfile.openArrayBuffer(buffer); + return zip.generateAsync({type: "arraybuffer"}).then(function(arrayBuffer) { + return zipfile.openArrayBuffer(arrayBuffer); + }); } |
