diff --git a/ts/docx/run/formatting.ts b/ts/docx/run/formatting.ts index ccad4cc349..d8f0257e03 100644 --- a/ts/docx/run/formatting.ts +++ b/ts/docx/run/formatting.ts @@ -1,5 +1,5 @@ import { Attributes, XmlComponent } from "../xml-components"; -export { Underline } from './underline'; +export { Underline } from "./underline"; export class Bold extends XmlComponent { diff --git a/ts/docx/xml-components/default-attributes.ts b/ts/docx/xml-components/default-attributes.ts index ec2641fb66..231a632e3d 100644 --- a/ts/docx/xml-components/default-attributes.ts +++ b/ts/docx/xml-components/default-attributes.ts @@ -18,9 +18,9 @@ export abstract class XmlAttributeComponent extends BaseXmlComponent { public toXml(): object { const attrs = {}; - if (this.root != undefined) { + if (this.root !== undefined) { _.forOwn(this.root, (value, key) => { - if (value != undefined) { + if (value !== undefined) { const newKey = this.xmlKeys[key]; attrs[newKey] = value; } diff --git a/ts/export/index.ts b/ts/export/index.ts index 2c4a25509a..e9db28839a 100644 --- a/ts/export/index.ts +++ b/ts/export/index.ts @@ -1,2 +1,2 @@ export { LocalPacker } from "./packer/local"; -export { ExpressPacker } from "./packer/express"; \ No newline at end of file +export { ExpressPacker } from "./packer/express"; diff --git a/ts/export/packer/express.ts b/ts/export/packer/express.ts index e7dad5dc08..e0be8b3cae 100644 --- a/ts/export/packer/express.ts +++ b/ts/export/packer/express.ts @@ -5,7 +5,6 @@ import { Numbering } from "../../numbering"; import { Properties } from "../../properties"; import { Packer } from "./packer"; - export class ExpressPacker extends Packer { private res: express.Response; diff --git a/ts/styles/style/index.ts b/ts/styles/style/index.ts index e2fae80a75..708603297a 100644 --- a/ts/styles/style/index.ts +++ b/ts/styles/style/index.ts @@ -15,7 +15,9 @@ export interface IStyleAttributes { } class StyleAttributes extends XmlAttributeComponent { + /* tslint:disable */ private _attr: IStyleAttributes; + /* tslint:enable */ constructor(properties: IStyleAttributes) { super({ diff --git a/ts/tests/_testTemplate.ts b/ts/tests/_testTemplate.ts index c7f727e661..c9b4421481 100644 --- a/ts/tests/_testTemplate.ts +++ b/ts/tests/_testTemplate.ts @@ -1,19 +1,15 @@ import { assert } from "chai"; - -function jsonify(obj: Object) { - let stringifiedJson = JSON.stringify(obj); - return JSON.parse(stringifiedJson); -} +import { Utility } from "./utility"; describe("", () => { beforeEach(() => { - + // TODO }); describe("#methodName()", () => { it("should ", () => { - + // TODO }); }); -}); \ No newline at end of file +}); diff --git a/ts/tests/docx/paragraph/tabStopTests.ts b/ts/tests/docx/paragraph/tabStopTests.ts index 2d2703138f..13ffb3c307 100644 --- a/ts/tests/docx/paragraph/tabStopTests.ts +++ b/ts/tests/docx/paragraph/tabStopTests.ts @@ -1,10 +1,6 @@ -import { LeftTabStop, MaxRightTabStop } from "../../../docx/paragraph/tab-stop"; import { assert } from "chai"; - -function jsonify(obj: Object) { - let stringifiedJson = JSON.stringify(obj); - return JSON.parse(stringifiedJson); -} +import { LeftTabStop, MaxRightTabStop } from "../../../docx/paragraph/tab-stop"; +import { Utility } from "../../utility"; describe("LeftTabStop", () => { let tabStop: LeftTabStop; @@ -15,23 +11,23 @@ describe("LeftTabStop", () => { describe("#constructor()", () => { it("should create a Tab Stop with correct attributes", () => { - let newJson = jsonify(tabStop); - let attributes = { + const newJson = Utility.jsonify(tabStop); + const attributes = { val: "left", - pos: 100 + pos: 100, }; assert.equal(JSON.stringify(newJson.root[0].root[0].root), JSON.stringify(attributes)); }); it("should create a Tab Stop with w:tab", () => { - let newJson = jsonify(tabStop); + const newJson = Utility.jsonify(tabStop); assert.equal(newJson.root[0].rootKey, "w:tab"); }); }); }); describe("RightTabStop", () => { - + // TODO }); describe("MaxRightTabStop", () => { @@ -43,18 +39,18 @@ describe("MaxRightTabStop", () => { describe("#constructor()", () => { it("should create a Tab Stop with correct attributes", () => { - let newJson = jsonify(tabStop); + const newJson = Utility.jsonify(tabStop); - let attributes = { + const attributes = { val: "right", - pos: 9026 + pos: 9026, }; assert.equal(JSON.stringify(newJson.root[0].root[0].root), JSON.stringify(attributes)); }); it("should create a Tab Stop with w:tab", () => { - let newJson = jsonify(tabStop); + const newJson = Utility.jsonify(tabStop); assert.equal(newJson.root[0].rootKey, "w:tab"); }); }); -}); \ No newline at end of file +}); diff --git a/ts/tests/docx/paragraph/unorderedListTests.ts b/ts/tests/docx/paragraph/unorderedListTests.ts index f6a4636b65..c6c5080791 100644 --- a/ts/tests/docx/paragraph/unorderedListTests.ts +++ b/ts/tests/docx/paragraph/unorderedListTests.ts @@ -27,4 +27,4 @@ describe("NumberProperties", () => { assert.equal(newJson.root[1].root[0].root.val, 5); }); }); -}); \ No newline at end of file +}); diff --git a/ts/tests/docx/run/breakTests.ts b/ts/tests/docx/run/breakTests.ts index b71b44fd37..86904765ea 100644 --- a/ts/tests/docx/run/breakTests.ts +++ b/ts/tests/docx/run/breakTests.ts @@ -1,10 +1,6 @@ -import { Break } from "../../../docx/run/break"; import { assert } from "chai"; - -function jsonify(obj: Object) { - let stringifiedJson = JSON.stringify(obj); - return JSON.parse(stringifiedJson); -} +import { Break } from "../../../docx/run/break"; +import { Utility } from "../../utility"; describe("Break", () => { let currentBreak: Break; @@ -15,8 +11,8 @@ describe("Break", () => { describe("#constructor()", () => { it("should create a Break with correct root key", () => { - let newJson = jsonify(currentBreak); + const newJson = Utility.jsonify(currentBreak); assert.equal(newJson.rootKey, "w:br"); }); }); -}); \ No newline at end of file +}); diff --git a/ts/tests/docx/run/runTest.ts b/ts/tests/docx/run/runTest.ts index a57e517e5b..9691a0af34 100644 --- a/ts/tests/docx/run/runTest.ts +++ b/ts/tests/docx/run/runTest.ts @@ -2,10 +2,7 @@ import { assert, expect } from "chai"; import { Run } from "../../../docx/run"; import { TextRun } from "../../../docx/run/text-run"; import { Formatter } from "../../../export/formatter"; - -function jsonify(obj: object) { - return JSON.parse(JSON.stringify(obj)); -} +import { Utility } from "../../utility"; describe("Run", () => { let run: Run; @@ -17,7 +14,7 @@ describe("Run", () => { describe("#bold()", () => { it("it should add bold to the properties", () => { run.bold(); - const newJson = jsonify(run); + const newJson = Utility.jsonify(run); assert.equal(newJson.root[0].root[0].rootKey, "w:b"); }); }); @@ -25,7 +22,7 @@ describe("Run", () => { describe("#italic()", () => { it("it should add italics to the properties", () => { run.italic(); - const newJson = jsonify(run); + const newJson = Utility.jsonify(run); assert.equal(newJson.root[0].root[0].rootKey, "w:i"); }); }); @@ -33,7 +30,7 @@ describe("Run", () => { describe("#underline()", () => { it("it should add underline to the properties", () => { run.underline(); - const newJson = jsonify(run); + const newJson = Utility.jsonify(run); assert.equal(newJson.root[0].root[0].rootKey, "w:u"); }); }); @@ -41,7 +38,7 @@ describe("Run", () => { describe("#smallCaps()", () => { it("it should add smallCaps to the properties", () => { run.smallCaps(); - const newJson = jsonify(run); + const newJson = Utility.jsonify(run); assert.equal(newJson.root[0].root[0].rootKey, "w:smallCaps"); }); }); @@ -49,7 +46,7 @@ describe("Run", () => { describe("#caps()", () => { it("it should add caps to the properties", () => { run.allCaps(); - const newJson = jsonify(run); + const newJson = Utility.jsonify(run); assert.equal(newJson.root[0].root[0].rootKey, "w:caps"); }); }); @@ -57,7 +54,7 @@ describe("Run", () => { describe("#strike()", () => { it("it should add strike to the properties", () => { run.strike(); - const newJson = jsonify(run); + const newJson = Utility.jsonify(run); assert.equal(newJson.root[0].root[0].rootKey, "w:strike"); }); }); @@ -65,7 +62,7 @@ describe("Run", () => { describe("#doubleStrike()", () => { it("it should add caps to the properties", () => { run.doubleStrike(); - const newJson = jsonify(run); + const newJson = Utility.jsonify(run); assert.equal(newJson.root[0].root[0].rootKey, "w:dstrike"); }); }); @@ -73,7 +70,7 @@ describe("Run", () => { describe("#break()", () => { it("it should add break to the run", () => { run.break(); - const newJson = jsonify(run); + const newJson = Utility.jsonify(run); assert.equal(newJson.root[1].rootKey, "w:br"); }); }); @@ -81,7 +78,7 @@ describe("Run", () => { describe("#tab()", () => { it("it should add break to the run", () => { run.tab(); - const newJson = jsonify(run); + const newJson = Utility.jsonify(run); assert.equal(newJson.root[1].rootKey, "w:tab"); }); }); diff --git a/ts/tests/docx/run/scriptTests.ts b/ts/tests/docx/run/scriptTests.ts index 2f8c779b73..94d3d25c00 100644 --- a/ts/tests/docx/run/scriptTests.ts +++ b/ts/tests/docx/run/scriptTests.ts @@ -1,10 +1,6 @@ -import { SubScript, SuperScript } from "../../../docx/run/script"; import { assert } from "chai"; - -function jsonify(obj: Object) { - let stringifiedJson = JSON.stringify(obj); - return JSON.parse(stringifiedJson); -} +import { SubScript, SuperScript } from "../../../docx/run/script"; +import { Utility } from "../../utility"; describe("SubScript", () => { let subScript: SubScript; @@ -15,15 +11,15 @@ describe("SubScript", () => { describe("#constructor()", () => { it("should create a Sub Script with correct attributes", () => { - let newJson = jsonify(subScript); - let attributes = { - val: "subscript" + const newJson = Utility.jsonify(subScript); + const attributes = { + val: "subscript", }; assert.equal(JSON.stringify(newJson.root[0].root), JSON.stringify(attributes)); }); it("should create a Sub Script with correct root key", () => { - let newJson = jsonify(subScript); + const newJson = Utility.jsonify(subScript); assert.equal(newJson.rootKey, "w:vertAlign"); }); }); @@ -38,16 +34,16 @@ describe("SuperScript", () => { describe("#constructor()", () => { it("should create a Super Script with correct attributes", () => { - let newJson = jsonify(superScript); - let attributes = { - val: "superscript" + const newJson = Utility.jsonify(superScript); + const attributes = { + val: "superscript", }; assert.equal(JSON.stringify(newJson.root[0].root), JSON.stringify(attributes)); }); it("should create a Super Script with correct root key", () => { - let newJson = jsonify(superScript); + const newJson = Utility.jsonify(superScript); assert.equal(newJson.rootKey, "w:vertAlign"); }); }); -}); \ No newline at end of file +}); diff --git a/ts/tests/docx/run/strikeTests.ts b/ts/tests/docx/run/strikeTests.ts index 128c08fc6f..ef591566a6 100644 --- a/ts/tests/docx/run/strikeTests.ts +++ b/ts/tests/docx/run/strikeTests.ts @@ -1,10 +1,6 @@ -import { Strike, DoubleStrike } from "../../../docx/run/strike"; import { assert } from "chai"; - -function jsonify(obj: Object) { - let stringifiedJson = JSON.stringify(obj); - return JSON.parse(stringifiedJson); -} +import { DoubleStrike, Strike } from "../../../docx/run/strike"; +import { Utility } from "../../utility"; describe("Strike", () => { let strike: Strike; @@ -15,7 +11,7 @@ describe("Strike", () => { describe("#constructor()", () => { it("should create a Strike with correct root key", () => { - let newJson = jsonify(strike); + const newJson = Utility.jsonify(strike); assert.equal(newJson.rootKey, "w:strike"); }); }); @@ -30,8 +26,8 @@ describe("DoubleStrike", () => { describe("#constructor()", () => { it("should create a Double Strike with correct root key", () => { - let newJson = jsonify(strike); + const newJson = Utility.jsonify(strike); assert.equal(newJson.rootKey, "w:dstrike"); }); }); -}); \ No newline at end of file +}); diff --git a/ts/tests/docx/run/tabTests.ts b/ts/tests/docx/run/tabTests.ts index 7ae300ef8a..5a006943dd 100644 --- a/ts/tests/docx/run/tabTests.ts +++ b/ts/tests/docx/run/tabTests.ts @@ -1,10 +1,6 @@ -import { Tab } from "../../../docx/run/tab"; import { assert } from "chai"; - -function jsonify(obj: Object) { - let stringifiedJson = JSON.stringify(obj); - return JSON.parse(stringifiedJson); -} +import { Tab } from "../../../docx/run/tab"; +import { Utility } from "../../utility"; describe("Tab", () => { let tab: Tab; @@ -15,8 +11,8 @@ describe("Tab", () => { describe("#constructor()", () => { it("should create a Tab with correct root key", () => { - let newJson = jsonify(tab); + const newJson = Utility.jsonify(tab); assert.equal(newJson.rootKey, "w:tab"); }); }); -}); \ No newline at end of file +}); diff --git a/ts/tests/docx/run/textRunTests.ts b/ts/tests/docx/run/textRunTests.ts index 353df5dcc9..4b0f12f3a0 100644 --- a/ts/tests/docx/run/textRunTests.ts +++ b/ts/tests/docx/run/textRunTests.ts @@ -1,10 +1,6 @@ -import { TextRun } from "../../../docx/run/text-run"; import { assert } from "chai"; - -function jsonify(obj: Object) { - let stringifiedJson = JSON.stringify(obj); - return JSON.parse(stringifiedJson); -} +import { TextRun } from "../../../docx/run/text-run"; +import { Utility } from "../../utility"; describe("TextRun", () => { let run: TextRun; @@ -13,8 +9,8 @@ describe("TextRun", () => { it("should add text into run", () => { run = new TextRun("test"); - let newJson = jsonify(run); + const newJson = Utility.jsonify(run); assert.equal(newJson.root[1].root, "test"); }); }); -}); \ No newline at end of file +}); diff --git a/ts/tests/docx/run/underlineTests.ts b/ts/tests/docx/run/underlineTests.ts index 2fb34172f5..635516e1f0 100644 --- a/ts/tests/docx/run/underlineTests.ts +++ b/ts/tests/docx/run/underlineTests.ts @@ -1,13 +1,8 @@ import { assert, expect } from "chai"; - import { TextRun } from "../../../docx/run/text-run"; import * as u from "../../../docx/run/underline"; import { Formatter } from "../../../export/formatter"; - -function jsonify(obj: object) { - const stringifiedJson = JSON.stringify(obj); - return JSON.parse(stringifiedJson); -} +import { Utility } from "../../utility"; describe("Underline", () => { @@ -15,7 +10,7 @@ describe("Underline", () => { it("should create a new Underline object with u:u as the rootKey", () => { const underline = new u.Underline(); - const newJson = jsonify(underline); + const newJson = Utility.jsonify(underline); assert.equal(newJson.rootKey, "w:u"); }); @@ -42,13 +37,13 @@ describe("DashDotDotHeavyUnderline", () => { describe("#constructor()", () => { it("should have u:u as the rootKey", () => { const underline = new u.DashDotDotHeavyUnderline(); - const newJson = jsonify(underline); + const newJson = Utility.jsonify(underline); assert.equal(newJson.rootKey, "w:u"); }); it("should put value in attribute", () => { const underline = new u.DashDotDotHeavyUnderline(); - const newJson = jsonify(underline); + const newJson = Utility.jsonify(underline); assert.equal(newJson.root[0].root.val, "dashDotDotHeavy"); }); }); @@ -59,7 +54,7 @@ describe("DashDotDotHeavyUnderline", () => { describe("#constructor()", () => { it("should put value in attribute", () => { const underline = new u.DashDotHeavyUnderline(); - const newJson = jsonify(underline); + const newJson = Utility.jsonify(underline); assert.equal(newJson.root[0].root.val, "dashDotHeavy"); }); }); @@ -70,7 +65,7 @@ describe("DashDotDotHeavyUnderline", () => { describe("#constructor()", () => { it("should put value in attribute", () => { const underline = new u.DashLongHeavyUnderline(); - const newJson = jsonify(underline); + const newJson = Utility.jsonify(underline); assert.equal(newJson.root[0].root.val, "dashLongHeavy"); }); }); @@ -81,7 +76,7 @@ describe("DashDotDotHeavyUnderline", () => { describe("#constructor()", () => { it("should put value in attribute", () => { const underline = new u.DashLongUnderline(); - const newJson = jsonify(underline); + const newJson = Utility.jsonify(underline); assert.equal(newJson.root[0].root.val, "dashLong"); }); }); @@ -92,7 +87,7 @@ describe("DashDotDotHeavyUnderline", () => { describe("#constructor()", () => { it("should put value in attribute", () => { const underline = new u.DashUnderline(); - const newJson = jsonify(underline); + const newJson = Utility.jsonify(underline); assert.equal(newJson.root[0].root.val, "dash"); }); }); @@ -103,7 +98,7 @@ describe("DashDotDotHeavyUnderline", () => { describe("#constructor()", () => { it("should put value in attribute", () => { const underline = new u.DotDashUnderline(); - const newJson = jsonify(underline); + const newJson = Utility.jsonify(underline); assert.equal(newJson.root[0].root.val, "dotDash"); }); }); @@ -114,7 +109,7 @@ describe("DashDotDotHeavyUnderline", () => { describe("#constructor()", () => { it("should put value in attribute", () => { const underline = new u.DotDotDashUnderline(); - const newJson = jsonify(underline); + const newJson = Utility.jsonify(underline); assert.equal(newJson.root[0].root.val, "dotDotDash"); }); }); @@ -125,7 +120,7 @@ describe("DashDotDotHeavyUnderline", () => { describe("#constructor()", () => { it("should put value in attribute", () => { const underline = new u.DottedHeavyUnderline(); - const newJson = jsonify(underline); + const newJson = Utility.jsonify(underline); assert.equal(newJson.root[0].root.val, "dottedHeavy"); }); }); @@ -136,7 +131,7 @@ describe("DashDotDotHeavyUnderline", () => { describe("#constructor()", () => { it("should put value in attribute", () => { const underline = new u.DottedUnderline(); - const newJson = jsonify(underline); + const newJson = Utility.jsonify(underline); assert.equal(newJson.root[0].root.val, "dotted"); }); }); @@ -147,7 +142,7 @@ describe("DashDotDotHeavyUnderline", () => { describe("#constructor()", () => { it("should put value in attribute", () => { const underline = new u.DoubleUnderline(); - const newJson = jsonify(underline); + const newJson = Utility.jsonify(underline); assert.equal(newJson.root[0].root.val, "double"); }); }); @@ -158,7 +153,7 @@ describe("DashDotDotHeavyUnderline", () => { describe("#constructor()", () => { it("should put value in attribute", () => { const underline = new u.SingleUnderline(); - const newJson = jsonify(underline); + const newJson = Utility.jsonify(underline); assert.equal(newJson.root[0].root.val, "single"); }); }); @@ -169,7 +164,7 @@ describe("DashDotDotHeavyUnderline", () => { describe("#constructor()", () => { it("should put value in attribute", () => { const underline = new u.ThickUnderline(); - const newJson = jsonify(underline); + const newJson = Utility.jsonify(underline); assert.equal(newJson.root[0].root.val, "thick"); }); }); @@ -180,7 +175,7 @@ describe("DashDotDotHeavyUnderline", () => { describe("#constructor()", () => { it("should put value in attribute", () => { const underline = new u.WaveUnderline(); - const newJson = jsonify(underline); + const newJson = Utility.jsonify(underline); assert.equal(newJson.root[0].root.val, "wave"); }); }); @@ -191,7 +186,7 @@ describe("DashDotDotHeavyUnderline", () => { describe("#constructor()", () => { it("should put value in attribute", () => { const underline = new u.WavyDoubleUnderline(); - const newJson = jsonify(underline); + const newJson = Utility.jsonify(underline); assert.equal(newJson.root[0].root.val, "wavyDouble"); }); }); @@ -202,7 +197,7 @@ describe("DashDotDotHeavyUnderline", () => { describe("#constructor()", () => { it("should put value in attribute", () => { const underline = new u.WavyHeavyUnderline(); - const newJson = jsonify(underline); + const newJson = Utility.jsonify(underline); assert.equal(newJson.root[0].root.val, "wavyHeavy"); }); }); @@ -213,7 +208,7 @@ describe("DashDotDotHeavyUnderline", () => { describe("#constructor()", () => { it("should put value in attribute", () => { const underline = new u.WordsUnderline(); - const newJson = jsonify(underline); + const newJson = Utility.jsonify(underline); assert.equal(newJson.root[0].root.val, "words"); }); }); diff --git a/ts/tests/docx/xml-components/attributeTest.ts b/ts/tests/docx/xml-components/attributeTest.ts index 27e8ffdfe6..002a6bb82c 100644 --- a/ts/tests/docx/xml-components/attributeTest.ts +++ b/ts/tests/docx/xml-components/attributeTest.ts @@ -1,5 +1,5 @@ -import { Attributes } from "../../../docx/xml-components"; import { assert } from "chai"; +import { Attributes } from "../../../docx/xml-components"; describe("Attribute", () => { let attributes: Attributes; @@ -11,28 +11,28 @@ describe("Attribute", () => { describe("#constructor()", () => { it("should not add val with empty constructor", () => { - let newAttrs = new Attributes(); - let stringifiedJson = JSON.stringify(newAttrs); - let newJson = JSON.parse(stringifiedJson); + const newAttrs = new Attributes(); + const stringifiedJson = JSON.stringify(newAttrs); + const newJson = JSON.parse(stringifiedJson); assert.isUndefined(newJson.root.val); }); it("should have val as defined with populated constructor", () => { - let newAttrs = new Attributes({ - val: "test" + const newAttrs = new Attributes({ + val: "test", }); - let stringifiedJson = JSON.stringify(newAttrs); - let newJson = JSON.parse(stringifiedJson); + const stringifiedJson = JSON.stringify(newAttrs); + const newJson = JSON.parse(stringifiedJson); assert.equal(newJson.root.val, "test"); }); it("should have space value as defined with populated constructor", () => { - let newAttrs = new Attributes({ - space: "spaceTest" + const newAttrs = new Attributes({ + space: "spaceTest", }); - let stringifiedJson = JSON.stringify(newAttrs); - let newJson = JSON.parse(stringifiedJson); + const stringifiedJson = JSON.stringify(newAttrs); + const newJson = JSON.parse(stringifiedJson); assert.equal(newJson.root.space, "spaceTest"); }); }); -}); \ No newline at end of file +}); diff --git a/ts/tests/docx/xml-components/xmlComponentTests.ts b/ts/tests/docx/xml-components/xmlComponentTests.ts index 578a5dc2a4..65d635342f 100644 --- a/ts/tests/docx/xml-components/xmlComponentTests.ts +++ b/ts/tests/docx/xml-components/xmlComponentTests.ts @@ -1,10 +1,6 @@ -import { XmlComponent } from "../../../docx/xml-components"; import { assert } from "chai"; - -function jsonify(obj: Object) { - let stringifiedJson = JSON.stringify(obj); - return JSON.parse(stringifiedJson); -} +import { XmlComponent } from "../../../docx/xml-components"; +import { Utility } from "../../utility"; class TestComponent extends XmlComponent { @@ -20,7 +16,7 @@ describe("XmlComponent", () => { describe("#constructor()", () => { it("should create an Xml Component which has the correct rootKey", () => { - let newJson = jsonify(xmlComponent); + const newJson = Utility.jsonify(xmlComponent); assert.equal(newJson.rootKey, "w:test"); }); }); diff --git a/ts/tests/export/formatterTest.ts b/ts/tests/export/formatterTest.ts index ce7714050b..12222c583f 100644 --- a/ts/tests/export/formatterTest.ts +++ b/ts/tests/export/formatterTest.ts @@ -4,11 +4,7 @@ import * as docx from "../../docx"; import { Attributes } from "../../docx/xml-components"; import { Formatter } from "../../export/formatter"; import { Properties } from "../../properties"; - -function jsonify(obj: object): any { - const stringifiedJson = JSON.stringify(obj); - return JSON.parse(stringifiedJson); -} +import { Utility } from "../utility"; describe("Formatter", () => { let formatter: Formatter; @@ -43,7 +39,7 @@ describe("Formatter", () => { rsidSect: "test2", }); let newJson = formatter.format(attributes); - newJson = jsonify(newJson); + newJson = Utility.jsonify(newJson); assert.isDefined(newJson._attr["w:rsidSect"]); }); @@ -52,7 +48,7 @@ describe("Formatter", () => { val: "test", }); let newJson = formatter.format(attributes); - newJson = jsonify(newJson); + newJson = Utility.jsonify(newJson); assert.isDefined(newJson._attr["w:val"]); }); diff --git a/ts/tests/export/localPackerTest.ts b/ts/tests/export/localPackerTest.ts index 4387472cf6..fd422a64db 100644 --- a/ts/tests/export/localPackerTest.ts +++ b/ts/tests/export/localPackerTest.ts @@ -1,38 +1,41 @@ -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"; +import * as fs from "fs"; + +import { Document } from "../../docx/document"; +import { Paragraph } from "../../docx/paragraph"; +import { LocalPacker } from "../../export/packer/local"; +import { Properties } from "../../properties"; +import { DefaultStylesFactory } from "../../styles/factory"; +import { DefaultStyle } from "../../styles/sample"; describe("Packer", () => { let packer: LocalPacker; let stylesFactory: DefaultStylesFactory; beforeEach(() => { - let document = new Document(); - let paragraph = new Paragraph("test text"); - let heading = new Paragraph("Hello world").heading1(); + const document = new Document(); + const paragraph = new Paragraph("test text"); + const heading = new Paragraph("Hello world").heading1(); document.addParagraph(new Paragraph("title").title()); document.addParagraph(heading); document.addParagraph(new Paragraph("heading 2").heading2()); document.addParagraph(paragraph); - let properties = new Properties({ + const properties = new Properties({ creator: "Dolan Miu", revision: "1", - lastModifiedBy: "Dolan Miu" + lastModifiedBy: "Dolan Miu", }); stylesFactory = new DefaultStylesFactory(); packer = new LocalPacker(document, stylesFactory.newInstance(), properties); }); describe("#pack()", () => { + /* tslint:disable */ it("should create a standard docx file", function (done) { + /* tslint:enable */ this.timeout(99999999); packer.pack("build-tests/tests/test.docx"); - let int = setInterval(() => { + const int = setInterval(() => { const stats = fs.statSync("build-tests/tests/test.docx"); if (stats.size > 2000) { clearInterval(int); @@ -40,14 +43,14 @@ describe("Packer", () => { done(); } }, 1000); - let out = setTimeout(() => { + const out = setTimeout(() => { clearInterval(int); try { - assert(false, 'did not create a file within the alloted time'); + assert(false, "did not create a file within the alloted time"); } catch (e) { done(e); } }, 2000); }); }); -}); \ No newline at end of file +}); diff --git a/ts/tests/numberingTest.ts b/ts/tests/numberingTest.ts index 1d79475b17..00bd6afb10 100644 --- a/ts/tests/numberingTest.ts +++ b/ts/tests/numberingTest.ts @@ -4,13 +4,10 @@ import { Numbering } from "../numbering"; import { AbstractNumbering } from "../numbering/abstract-numbering"; import { Num } from "../numbering/num"; -function jsonify(obj: object) { - return JSON.parse(JSON.stringify(obj)); -} - describe("Numbering", () => { let numbering: Numbering; + beforeEach(() => { numbering = new Numbering(); }); @@ -22,8 +19,8 @@ describe("Numbering", () => { const abstractNums = tree["w:numbering"].filter((el) => el["w:abstractNum"]); expect(abstractNums).to.have.lengthOf(1); expect(abstractNums[0]["w:abstractNum"]).to.deep.include.members([ - {_attr: {"w:abstractNumId": 0, "w15:restartNumberingAfterBreak": 0}}, - {"w:multiLevelType": [{_attr: {"w:val": "hybridMultilevel"}}]}, + { _attr: { "w:abstractNumId": 0, "w15:restartNumberingAfterBreak": 0 } }, + { "w:multiLevelType": [{ _attr: { "w:val": "hybridMultilevel" } }] }, ]); abstractNums.filter((el) => el["w:lvl"]).forEach((el, ix) => { @@ -32,10 +29,10 @@ describe("Numbering", () => { "_attr", "w:start", "w:lvlJc", "w:numFmt", "w:pPr", "w:rPr", ]); expect(el["w:lvl"]).to.have.deep.members([ - {_attr: {"w:ilvl": ix, "w15:tentative": 1}}, - {"w:start": [{_attr: {"w:val": 1}}]}, - {"w:lvlJc": [{_attr: {"w:val": "left"}}]}, - {"w:numFmt": [{_attr: {"w:val": "bullet"}}]}, + { _attr: { "w:ilvl": ix, "w15:tentative": 1 } }, + { "w:start": [{ _attr: { "w:val": 1 } }] }, + { "w:lvlJc": [{ _attr: { "w:val": "left" } }] }, + { "w:numFmt": [{ _attr: { "w:val": "bullet" } }] }, ]); // Once chai 4.0.0 lands and #644 is resolved, we can add the following to the test: // {"w:lvlText": [{"_attr": {"w:val": "•"}}]}, @@ -65,8 +62,8 @@ describe("Numbering", () => { const n = numbering.createConcreteNumbering(a2); expect(n).to.be.instanceof(Num); const tree = new Formatter().format(numbering); - const serializedN = tree["w:numbering"].find( - (obj) => obj["w:num"] && obj["w:num"][0]._attr["w:numId"] === n.id + const serializedN = tree["w:numbering"].find((obj) => + obj["w:num"] && obj["w:num"][0]._attr["w:numId"] === n.id, ); expect(serializedN["w:num"][1]["w:abstractNumId"][0]._attr["w:val"]).to.equal(a2.id); }); @@ -91,22 +88,22 @@ describe("AbstractNumbering", () => { const abstractNumbering = new AbstractNumbering(1); const level = abstractNumbering.createLevel(3, "lowerLetter", "%1)", "end"); const tree = new Formatter().format(level); - expect(tree['w:lvl']).to.include({_attr: {"w:ilvl": 3, "w15:tentative": 1}}) - expect(tree['w:lvl']).to.include({"w:start": [{_attr: {"w:val": 1}}]}) - expect(tree['w:lvl']).to.include({"w:lvlJc": [{_attr: {"w:val": "end"}}]}) - expect(tree['w:lvl']).to.include({"w:numFmt": [{_attr: {"w:val": "lowerLetter"}}]}) - expect(tree['w:lvl']).to.include({"w:lvlText": [{"_attr": {"w:val": "%1)"}}]}) + expect(tree["w:lvl"]).to.include({ _attr: { "w:ilvl": 3, "w15:tentative": 1 } }); + expect(tree["w:lvl"]).to.include({ "w:start": [{ _attr: { "w:val": 1 } }] }); + expect(tree["w:lvl"]).to.include({ "w:lvlJc": [{ _attr: { "w:val": "end" } }] }); + expect(tree["w:lvl"]).to.include({ "w:numFmt": [{ _attr: { "w:val": "lowerLetter" } }] }); + expect(tree["w:lvl"]).to.include({ "w:lvlText": [{ _attr: { "w:val": "%1)" } }] }); }); it("uses 'start' as the default alignment", () => { const abstractNumbering = new AbstractNumbering(1); const level = abstractNumbering.createLevel(3, "lowerLetter", "%1)"); const tree = new Formatter().format(level); - expect(tree['w:lvl']).to.include({_attr: {"w:ilvl": 3, "w15:tentative": 1}}) - expect(tree['w:lvl']).to.include({"w:start": [{_attr: {"w:val": 1}}]}) - expect(tree['w:lvl']).to.include({"w:lvlJc": [{_attr: {"w:val": "start"}}]}) - expect(tree['w:lvl']).to.include({"w:numFmt": [{_attr: {"w:val": "lowerLetter"}}]}) - expect(tree['w:lvl']).to.include({"w:lvlText": [{"_attr": {"w:val": "%1)"}}]}) + expect(tree["w:lvl"]).to.include({ _attr: { "w:ilvl": 3, "w15:tentative": 1 } }); + expect(tree["w:lvl"]).to.include({ "w:start": [{ _attr: { "w:val": 1 } }] }); + expect(tree["w:lvl"]).to.include({ "w:lvlJc": [{ _attr: { "w:val": "start" } }] }); + expect(tree["w:lvl"]).to.include({ "w:numFmt": [{ _attr: { "w:val": "lowerLetter" } }] }); + expect(tree["w:lvl"]).to.include({ "w:lvlText": [{ _attr: { "w:val": "%1)" } }] }); }); }); }); diff --git a/ts/tests/utility.ts b/ts/tests/utility.ts index 51389b6b37..f89701b726 100644 --- a/ts/tests/utility.ts +++ b/ts/tests/utility.ts @@ -1,5 +1,5 @@ export class Utility { - public static jsonify(obj: Object) { + public static jsonify(obj: object): any { const stringifiedJson = JSON.stringify(obj); return JSON.parse(stringifiedJson); }