Add tests for catching errors for exporter packer.pack
This commit is contained in:
@ -60,6 +60,7 @@
|
|||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/chai": "^3.4.35",
|
"@types/chai": "^3.4.35",
|
||||||
"@types/mocha": "^2.2.39",
|
"@types/mocha": "^2.2.39",
|
||||||
|
"@types/sinon": "^4.3.1",
|
||||||
"awesome-typescript-loader": "^3.4.1",
|
"awesome-typescript-loader": "^3.4.1",
|
||||||
"chai": "^3.5.0",
|
"chai": "^3.5.0",
|
||||||
"glob": "^7.1.2",
|
"glob": "^7.1.2",
|
||||||
@ -70,6 +71,7 @@
|
|||||||
"replace-in-file": "^3.1.0",
|
"replace-in-file": "^3.1.0",
|
||||||
"rimraf": "^2.5.2",
|
"rimraf": "^2.5.2",
|
||||||
"shelljs": "^0.7.7",
|
"shelljs": "^0.7.7",
|
||||||
|
"sinon": "^5.0.7",
|
||||||
"tslint": "^5.1.0",
|
"tslint": "^5.1.0",
|
||||||
"typedoc": "^0.9.0",
|
"typedoc": "^0.9.0",
|
||||||
"typescript": "2.6.2",
|
"typescript": "2.6.2",
|
||||||
|
43
src/export/packer/express.spec.ts
Normal file
43
src/export/packer/express.spec.ts
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
// tslint:disable:typedef space-before-function-paren
|
||||||
|
// tslint:disable:no-empty
|
||||||
|
// tslint:disable:no-any
|
||||||
|
import { assert } from "chai";
|
||||||
|
import { stub } from "sinon";
|
||||||
|
|
||||||
|
import { ExpressPacker } from "../../export/packer/express";
|
||||||
|
import { File, Paragraph } from "../../file";
|
||||||
|
|
||||||
|
describe("LocalPacker", () => {
|
||||||
|
let packer: ExpressPacker;
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
const file = new File({
|
||||||
|
creator: "Dolan Miu",
|
||||||
|
revision: "1",
|
||||||
|
lastModifiedBy: "Dolan Miu",
|
||||||
|
});
|
||||||
|
const paragraph = new Paragraph("test text");
|
||||||
|
const heading = new Paragraph("Hello world").heading1();
|
||||||
|
file.addParagraph(new Paragraph("title").title());
|
||||||
|
file.addParagraph(heading);
|
||||||
|
file.addParagraph(new Paragraph("heading 2").heading2());
|
||||||
|
file.addParagraph(paragraph);
|
||||||
|
|
||||||
|
const expressResMock = {
|
||||||
|
on: () => {},
|
||||||
|
attachment: () => {},
|
||||||
|
};
|
||||||
|
|
||||||
|
packer = new ExpressPacker(file, expressResMock as any);
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("#pack()", () => {
|
||||||
|
it("should handle exception if it throws any", () => {
|
||||||
|
const compiler = stub((packer as any).packer, "compile");
|
||||||
|
compiler.throwsException();
|
||||||
|
return packer.pack("build/tests/test").catch((error) => {
|
||||||
|
assert.isDefined(error);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
@ -1,5 +1,7 @@
|
|||||||
/* 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 { stub } from "sinon";
|
||||||
|
|
||||||
import { LocalPacker } from "../../export/packer/local";
|
import { LocalPacker } from "../../export/packer/local";
|
||||||
import { File, Paragraph } from "../../file";
|
import { File, Paragraph } from "../../file";
|
||||||
@ -29,14 +31,36 @@ describe("LocalPacker", () => {
|
|||||||
await packer.pack("build/tests/test");
|
await packer.pack("build/tests/test");
|
||||||
fs.statSync("build/tests/test.docx");
|
fs.statSync("build/tests/test.docx");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("should handle exception if it throws any", () => {
|
||||||
|
// tslint:disable-next-line:no-any
|
||||||
|
const compiler = stub((packer as any).packer, "compile");
|
||||||
|
compiler.throwsException();
|
||||||
|
return packer.pack("build/tests/test").catch((error) => {
|
||||||
|
assert.isDefined(error);
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("#packPdf", () => {
|
describe("#packPdf", () => {
|
||||||
it("should create a standard PDF file", async function() {
|
it("should create a standard PDF file", async function() {
|
||||||
this.timeout(99999999);
|
this.timeout(99999999);
|
||||||
|
|
||||||
|
// tslint:disable-next-line:no-any
|
||||||
|
const pdfConverterConvert = stub((packer as any).pdfConverter, "convert");
|
||||||
|
pdfConverterConvert.returns("Test PDF Contents");
|
||||||
|
|
||||||
await packer.packPdf("build/tests/pdf-test");
|
await packer.packPdf("build/tests/pdf-test");
|
||||||
fs.statSync("build/tests/pdf-test.pdf");
|
fs.statSync("build/tests/pdf-test.pdf");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("should handle exception if it throws any", () => {
|
||||||
|
// tslint:disable-next-line:no-any
|
||||||
|
const compiler = stub((packer as any).packer, "compile");
|
||||||
|
compiler.throwsException();
|
||||||
|
return packer.packPdf("build/tests/pdf-test").catch((error) => {
|
||||||
|
assert.isDefined(error);
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
Reference in New Issue
Block a user