diff --git a/ts/export/packer/express.ts b/ts/export/packer/express.ts index db5706543c..f5f2789f1d 100644 --- a/ts/export/packer/express.ts +++ b/ts/export/packer/express.ts @@ -22,10 +22,10 @@ export class ExpressPacker implements IPacker { }); } - public pack(name: string): void { + public async pack(name: string): Promise { name = name.replace(/.docx$/, ""); this.res.attachment(`${name}.docx`); - this.packer.compile(this.res); + await this.packer.compile(this.res); } } diff --git a/ts/export/packer/local.spec.ts b/ts/export/packer/local.spec.ts index 3de061f270..79caf6dd9c 100644 --- a/ts/export/packer/local.spec.ts +++ b/ts/export/packer/local.spec.ts @@ -1,6 +1,4 @@ /* tslint:disable:typedef space-before-function-paren */ - -import { assert } from "chai"; import * as fs from "fs"; import { Document } from "../../docx/document"; @@ -31,26 +29,10 @@ describe("LocalPacker", () => { }); describe("#pack()", () => { - it("should create a standard docx file", function (done) { + it("should create a standard docx file", async function () { this.timeout(99999999); - packer.pack("build-tests/tests/test"); - - const int = setInterval(() => { - const stats = fs.statSync("build-tests/tests/test.docx"); - if (stats.size > 2000) { - clearInterval(int); - clearTimeout(out); - done(); - } - }, 1000); - const out = setTimeout(() => { - clearInterval(int); - try { - assert(false, "did not create a file within the alloted time"); - } catch (e) { - done(e); - } - }, 2000); + await packer.pack("build-tests/tests/test"); + fs.statSync("build-tests/tests/test.docx"); }); }); diff --git a/ts/export/packer/local.ts b/ts/export/packer/local.ts index 1f94830037..1fefb6cb20 100644 --- a/ts/export/packer/local.ts +++ b/ts/export/packer/local.ts @@ -21,11 +21,11 @@ export class LocalPacker implements IPacker { this.packer = new Compiler(document, styles, properties, numbering, media); } - public pack(filePath: string): void { + public async pack(filePath: string): Promise { filePath = filePath.replace(/.docx$/, ""); this.stream = fs.createWriteStream(`${filePath}.docx`); - this.packer.compile(this.stream); + await this.packer.compile(this.stream); } public async packPdf(filePath: string): Promise {