Simplify tests and made compile async
This commit is contained in:
@ -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$/, "");
|
||||
|
||||
this.res.attachment(`${name}.docx`);
|
||||
this.packer.compile(this.res);
|
||||
await this.packer.compile(this.res);
|
||||
}
|
||||
}
|
||||
|
@ -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");
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -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<void> {
|
||||
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<void> {
|
||||
|
Reference in New Issue
Block a user