Simplify tests and made compile async

This commit is contained in:
Dolan
2017-12-06 01:32:57 +00:00
parent ebec10e312
commit 5889f20f1e
3 changed files with 7 additions and 25 deletions

View File

@ -22,10 +22,10 @@ export class ExpressPacker implements IPacker {
}); });
} }
public pack(name: string): void { public async pack(name: string): Promise<void> {
name = name.replace(/.docx$/, ""); name = name.replace(/.docx$/, "");
this.res.attachment(`${name}.docx`); this.res.attachment(`${name}.docx`);
this.packer.compile(this.res); await this.packer.compile(this.res);
} }
} }

View File

@ -1,6 +1,4 @@
/* tslint:disable:typedef space-before-function-paren */ /* tslint:disable:typedef space-before-function-paren */
import { assert } from "chai";
import * as fs from "fs"; import * as fs from "fs";
import { Document } from "../../docx/document"; import { Document } from "../../docx/document";
@ -31,26 +29,10 @@ describe("LocalPacker", () => {
}); });
describe("#pack()", () => { describe("#pack()", () => {
it("should create a standard docx file", function (done) { it("should create a standard docx file", async function () {
this.timeout(99999999); this.timeout(99999999);
packer.pack("build-tests/tests/test"); await packer.pack("build-tests/tests/test");
fs.statSync("build-tests/tests/test.docx");
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);
}); });
}); });

View File

@ -21,11 +21,11 @@ export class LocalPacker implements IPacker {
this.packer = new Compiler(document, styles, properties, numbering, media); this.packer = new Compiler(document, styles, properties, numbering, media);
} }
public pack(filePath: string): void { public async pack(filePath: string): Promise<void> {
filePath = filePath.replace(/.docx$/, ""); filePath = filePath.replace(/.docx$/, "");
this.stream = fs.createWriteStream(`${filePath}.docx`); this.stream = fs.createWriteStream(`${filePath}.docx`);
this.packer.compile(this.stream); await this.packer.compile(this.stream);
} }
public async packPdf(filePath: string): Promise<void> { public async packPdf(filePath: string): Promise<void> {