From a7d55a52f380331acc01046f6dcba8f729e102be Mon Sep 17 00:00:00 2001 From: Dolan Miu Date: Tue, 12 Jul 2022 16:57:25 +0100 Subject: [PATCH 1/3] #1583 Comments to always write default data --- src/export/packer/next-compiler.spec.ts | 2 +- src/export/packer/next-compiler.ts | 31 ++++++++++--------------- src/file/file.ts | 5 +--- 3 files changed, 14 insertions(+), 24 deletions(-) diff --git a/src/export/packer/next-compiler.spec.ts b/src/export/packer/next-compiler.spec.ts index c31a8c4ce7..1c1a867a12 100644 --- a/src/export/packer/next-compiler.spec.ts +++ b/src/export/packer/next-compiler.spec.ts @@ -111,7 +111,7 @@ describe("Compiler", () => { const spy = sinon.spy(compiler["formatter"], "format"); compiler.compile(file); - expect(spy.callCount).to.equal(12); + expect(spy.callCount).to.equal(13); }); it("should work with media datas", () => { diff --git a/src/export/packer/next-compiler.ts b/src/export/packer/next-compiler.ts index 59776fe1c4..3179af9a2e 100644 --- a/src/export/packer/next-compiler.ts +++ b/src/export/packer/next-compiler.ts @@ -406,26 +406,19 @@ export class Compiler { path: "word/settings.xml", }, Comments: { - data: (() => { - if (!file.Comments) { - return; - } - - const data = xml( - this.formatter.format(file.Comments, { - viewWrapper: file.Document, - file, - }), - { - indent: prettify, - declaration: { - standalone: "yes", - encoding: "UTF-8", - }, + data: xml( + this.formatter.format(file.Comments, { + viewWrapper: file.Document, + file, + }), + { + indent: prettify, + declaration: { + standalone: "yes", + encoding: "UTF-8", }, - ); - return data; - })(), + }, + ), path: "word/comments.xml", }, }; diff --git a/src/file/file.ts b/src/file/file.ts index afd13e5b6f..b640ba9b33 100644 --- a/src/file/file.ts +++ b/src/file/file.ts @@ -71,10 +71,7 @@ export class File { }, ); - if (options.comments) { - this.comments = new Comments(options.comments); - } - + this.comments = new Comments(options.comments ?? { children: [] }); this.fileRelationships = new Relationships(); this.customProperties = new CustomProperties(options.customProperties ?? []); this.appProperties = new AppProperties(); From e84641c13c876356e70cc448be69c17f221b0de8 Mon Sep 17 00:00:00 2001 From: Dolan Miu Date: Tue, 12 Jul 2022 18:11:44 +0100 Subject: [PATCH 2/3] #1583 Add more tests to media data --- src/export/packer/next-compiler.spec.ts | 37 ++++++++++++++++++++++--- 1 file changed, 33 insertions(+), 4 deletions(-) diff --git a/src/export/packer/next-compiler.spec.ts b/src/export/packer/next-compiler.spec.ts index 1c1a867a12..3cd56c211f 100644 --- a/src/export/packer/next-compiler.spec.ts +++ b/src/export/packer/next-compiler.spec.ts @@ -4,7 +4,8 @@ import * as sinon from "sinon"; import { File } from "@file/file"; import { Footer, Header } from "@file/header"; -import { Paragraph } from "@file/paragraph"; +import { ImageRun, Paragraph } from "@file/paragraph"; +import * as convenienceFunctions from "@util/convenience-functions"; import { Compiler } from "./next-compiler"; @@ -15,6 +16,14 @@ describe("Compiler", () => { compiler = new Compiler(); }); + before(() => { + sinon.stub(convenienceFunctions, "uniqueId").callsFake(() => "test"); + }); + + after(() => { + (convenienceFunctions.uniqueId as sinon.SinonStub).restore(); + }); + describe("#compile()", () => { it("should pack all the content", async function () { this.timeout(99999999); @@ -117,12 +126,32 @@ describe("Compiler", () => { it("should work with media datas", () => { // This test is required because before, there was a case where Document was formatted twice, which was inefficient // This also caused issues such as running prepForXml multiple times as format() was ran multiple times. - const paragraph = new Paragraph(""); const file = new File({ sections: [ { - properties: {}, - children: [paragraph], + headers: { + default: new Header({ + children: [new Paragraph("test")], + }), + }, + footers: { + default: new Footer({ + children: [new Paragraph("test")], + }), + }, + children: [ + new Paragraph({ + children: [ + new ImageRun({ + data: Buffer.from("", "base64"), + transformation: { + width: 100, + height: 100, + }, + }), + ], + }), + ], }, ], }); From 02a5aaf5d83781eaeb333df8a7b9c9ec86c8876a Mon Sep 17 00:00:00 2001 From: Dolan Miu Date: Tue, 12 Jul 2022 18:14:20 +0100 Subject: [PATCH 3/3] Bump coverage threshold --- .nycrc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.nycrc b/.nycrc index 532628ce04..2d0c37e9f9 100644 --- a/.nycrc +++ b/.nycrc @@ -1,9 +1,9 @@ { "check-coverage": true, - "statements": 99.43, - "branches": 96.6, - "functions": 99.47, - "lines": 99.43, + "statements": 99.62, + "branches": 96.81, + "functions": 99.82, + "lines": 99.62, "include": [ "src/**/*.ts" ],