Fix tests and build

Remove unused code and dependencies
This commit is contained in:
Dolan Miu
2023-06-08 13:30:31 +01:00
parent a0a88412ff
commit 09ab91eeef
19 changed files with 22322 additions and 26082 deletions

View File

@ -1,5 +1,4 @@
import { assert, beforeEach, describe, expect, it } from "vitest";
import * as sinon from "sinon";
import { assert, beforeEach, describe, expect, it, vi } from "vitest";
import { Formatter } from "@export/formatter";
import { CoreProperties } from "@file/core-properties";
@ -109,10 +108,10 @@ describe("Formatter", () => {
it("should call the prep method only once", () => {
const paragraph = new Paragraph("");
const spy = sinon.spy(paragraph, "prepForXml");
const spy = vi.spyOn(paragraph, "prepForXml");
formatter.format(paragraph);
expect(spy.calledOnce).to.equal(true);
expect(spy).toBeCalledTimes(1);
});
});
});

View File

@ -1,6 +1,5 @@
/* tslint:disable:typedef space-before-function-paren */
import { afterAll, beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
import * as sinon from "sinon";
import * as fflate from "fflate";
import { File } from "@file/file";
@ -140,10 +139,10 @@ describe("Compiler", () => {
});
// tslint:disable-next-line: no-string-literal
const spy = sinon.spy(compiler["formatter"], "format");
const spy = vi.spyOn(compiler["formatter"], "format");
compiler.compile(file);
expect(spy.callCount).to.equal(13);
expect(spy).toBeCalledTimes(13);
});
it("should work with media datas", () => {
@ -179,8 +178,7 @@ describe("Compiler", () => {
],
});
// tslint:disable-next-line: no-string-literal
sinon.stub(compiler["imageReplacer"], "getMediaData").returns([
vi.spyOn(compiler["imageReplacer"], "getMediaData").mockReturnValue([
{
stream: Buffer.from(""),
fileName: "test",

View File

@ -1,5 +1,4 @@
import { describe, expect, it } from "vitest";
import * as sinon from "sinon";
import { describe, expect, it, vi } from "vitest";
import { FooterWrapper } from "./footer-wrapper";
import { Media } from "./media";
@ -10,15 +9,15 @@ describe("FooterWrapper", () => {
describe("#add", () => {
it("should call the underlying footer's addParagraph", () => {
const file = new FooterWrapper(new Media(), 1);
const spy = sinon.spy(file.View, "add");
const spy = vi.spyOn(file.View, "add");
file.add(new Paragraph({}));
expect(spy.called).to.equal(true);
expect(spy).toBeCalled();
});
it("should call the underlying footer's addParagraph", () => {
const file = new FooterWrapper(new Media(), 1);
const spy = sinon.spy(file.View, "add");
const spy = vi.spyOn(file.View, "add");
file.add(
new Table({
rows: [
@ -33,18 +32,18 @@ describe("FooterWrapper", () => {
}),
);
expect(spy.called).to.equal(true);
expect(spy).toBeCalled();
});
});
describe("#addChildElement", () => {
it("should call the underlying footer's addChildElement", () => {
const file = new FooterWrapper(new Media(), 1);
const spy = sinon.spy(file.View, "addChildElement");
const spy = vi.spyOn(file.View, "addChildElement");
// eslint-disable-next-line @typescript-eslint/no-explicit-any
file.addChildElement({} as any);
expect(spy.called).to.equal(true);
expect(spy).toBeCalled();
});
});

View File

@ -1,5 +1,4 @@
import { describe, expect, it } from "vitest";
import * as sinon from "sinon";
import { describe, expect, it, vi } from "vitest";
import { HeaderWrapper } from "./header-wrapper";
import { Media } from "./media";
@ -10,15 +9,15 @@ describe("HeaderWrapper", () => {
describe("#add", () => {
it("should call the underlying header's addChildElement for Paragraph", () => {
const wrapper = new HeaderWrapper(new Media(), 1);
const spy = sinon.spy(wrapper.View, "add");
const spy = vi.spyOn(wrapper.View, "add");
wrapper.add(new Paragraph({}));
expect(spy.called).to.equal(true);
expect(spy).toBeCalled();
});
it("should call the underlying header's addChildElement for Table", () => {
const wrapper = new HeaderWrapper(new Media(), 1);
const spy = sinon.spy(wrapper.View, "add");
const spy = vi.spyOn(wrapper.View, "add");
wrapper.add(
new Table({
rows: [
@ -33,18 +32,18 @@ describe("HeaderWrapper", () => {
}),
);
expect(spy.called).to.equal(true);
expect(spy).toBeCalled();
});
});
describe("#addChildElement", () => {
it("should call the underlying header's addChildElement", () => {
const file = new HeaderWrapper(new Media(), 1);
const spy = sinon.spy(file.View, "addChildElement");
const spy = vi.spyOn(file.View, "addChildElement");
// eslint-disable-next-line @typescript-eslint/no-explicit-any
file.addChildElement({} as any);
expect(spy.called).to.equal(true);
expect(spy).toBeCalled();
});
});

View File

@ -1,5 +1,4 @@
import { afterEach, beforeEach, describe, expect, it } from "vitest";
import * as sinon from "sinon";
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
import { Formatter } from "@export/formatter";
@ -43,15 +42,15 @@ describe("CommentReference", () => {
});
describe("Comment", () => {
let clock: sinon.SinonFakeTimers;
beforeEach(() => {
const now = new Date("1999-01-01T00:00:00.000Z");
clock = sinon.useFakeTimers(now.getTime());
vi.useFakeTimers({
now: now.getTime(),
});
});
afterEach(() => {
clock.restore();
vi.restoreAllMocks();
});
describe("#constructor()", () => {

View File

@ -2,8 +2,7 @@ import { IViewWrapper } from "@file/document-wrapper";
import { File } from "@file/file";
import { Paragraph, TextRun } from "@file/paragraph";
import { IContext } from "@file/xml-components";
import { describe, expect, it } from "vitest";
import * as sinon from "sinon";
import { describe, expect, it, vi } from "vitest";
import { PatchType } from "./from-docx";
@ -63,7 +62,8 @@ describe("replacer", () => {
},
"hello",
[],
sinon.mock() as unknown as IContext,
// eslint-disable-next-line functional/prefer-readonly-type
vi.fn<[], IContext>()(),
);
expect(output).to.deep.equal({