Files
docx-js/ts/tests/export/localPackerTest.ts

53 lines
1.9 KiB
TypeScript
Raw Normal View History

import * as fs from "fs";
import { LocalPacker } from "../../export/packer/local";
import { Document } from "../../docx/document";
import { Properties } from "../../properties";
import { DefaultStyle } from "../../styles/sample";
import { Paragraph } from "../../docx/paragraph";
import { DefaultStylesFactory } from "../../styles/factory";
import { assert } from "chai";
2016-03-31 18:03:16 +01:00
2016-07-01 22:09:55 +01:00
describe("Packer", () => {
2016-05-26 15:08:34 +01:00
let packer: LocalPacker;
let stylesFactory: DefaultStylesFactory;
2016-03-31 18:03:16 +01:00
beforeEach(() => {
2016-05-26 15:08:34 +01:00
let document = new Document();
let paragraph = new Paragraph("test text");
let heading = new Paragraph("Hello world").heading1();
2016-05-10 00:32:00 +01:00
document.addParagraph(new Paragraph("title").title());
document.addParagraph(heading);
2016-05-10 00:32:00 +01:00
document.addParagraph(new Paragraph("heading 2").heading2());
2016-04-05 22:11:21 +01:00
document.addParagraph(paragraph);
2016-05-26 15:08:34 +01:00
let properties = new Properties({
2016-07-19 18:45:07 +01:00
creator: "Dolan Miu",
2016-04-08 23:01:50 +01:00
revision: "1",
2016-07-19 18:45:07 +01:00
lastModifiedBy: "Dolan Miu"
2016-04-05 01:49:12 +01:00
});
stylesFactory = new DefaultStylesFactory();
2016-07-04 18:47:13 +01:00
packer = new LocalPacker(document, stylesFactory.newInstance(), properties);
2016-03-31 18:03:16 +01:00
});
2016-05-26 15:08:34 +01:00
describe("#pack()", () => {
2016-07-01 22:09:55 +01:00
it("should create a standard docx file", function (done) {
this.timeout(99999999);
packer.pack("build-tests/tests/test.docx");
let int = setInterval(() => {
const stats = fs.statSync("build-tests/tests/test.docx");
if (stats.size > 2000) {
clearInterval(int);
clearTimeout(out);
done();
}
}, 1000);
let out = setTimeout(() => {
clearInterval(int);
try {
assert(false, 'did not create a file within the alloted time');
} catch (e) {
done(e);
}
}, 2000);
2016-03-31 18:03:16 +01:00
});
});
});