Files
docx-js/ts/export/packer/local.spec.ts

64 lines
2.2 KiB
TypeScript
Raw Normal View History

2017-12-05 00:16:21 +00:00
/* tslint:disable:typedef space-before-function-paren */
2017-03-09 22:56:08 +00:00
import { assert } from "chai";
import * as fs from "fs";
2017-03-09 22:56:08 +00:00
import { Document } from "../../docx/document";
import { Paragraph } from "../../docx/paragraph";
2017-03-09 22:56:08 +00:00
import { LocalPacker } from "../../export/packer/local";
import { Properties } from "../../properties";
import { DefaultStylesFactory } from "../../styles/factory";
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(() => {
2017-03-09 22:56:08 +00:00
const document = new Document();
const paragraph = new Paragraph("test text");
const 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);
2017-03-09 22:56:08 +00:00
const properties = new Properties({
2016-07-19 18:45:07 +01:00
creator: "Dolan Miu",
2016-04-08 23:01:50 +01:00
revision: "1",
2017-03-09 22:56:08 +00: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);
2017-12-05 00:16:21 +00:00
packer.pack("build-tests/tests/test");
2017-03-09 22:56:08 +00:00
const int = setInterval(() => {
const stats = fs.statSync("build-tests/tests/test.docx");
if (stats.size > 2000) {
clearInterval(int);
clearTimeout(out);
done();
}
}, 1000);
2017-03-09 22:56:08 +00:00
const out = setTimeout(() => {
clearInterval(int);
try {
2017-03-09 22:56:08 +00:00
assert(false, "did not create a file within the alloted time");
} catch (e) {
done(e);
}
}, 2000);
2016-03-31 18:03:16 +01:00
});
2017-12-05 00:16:21 +00:00
it("should create a standard PDF file", async function () {
this.timeout(99999999);
await packer.packPdf("build-tests/tests/pdf-test");
fs.statSync("build-tests/tests/pdf-test.pdf");
});
2016-03-31 18:03:16 +01:00
});
2017-03-09 22:56:08 +00:00
});