Fix tests
This commit is contained in:
893
package-lock.json
generated
893
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -32,7 +32,6 @@
|
||||
"style": "prettier -l \"{src,scripts,demo}/**/*.{ts,html}\"",
|
||||
"style.fix": "npm run style -- --write",
|
||||
"cspell": "cspell \"{src,demo,docs,scripts}/**/*.{ts,scss,html,md}\" && cspell \"./*.*\"",
|
||||
"fix-types": "ts-node --skip-project scripts/types-absolute-fixer.ts",
|
||||
"e2e": "ts-node scripts/e2e.ts",
|
||||
"serve.docs": "cd docs && docsify serve",
|
||||
"extract": "ts-node --project tsconfig.spec.json scripts/extract-document.ts",
|
||||
@ -99,6 +98,7 @@
|
||||
"eslint-plugin-unicorn": "^46.0.0",
|
||||
"execa": "^7.1.1",
|
||||
"glob": "^9.3.0",
|
||||
"jsdom": "^22.1.0",
|
||||
"jszip": "^3.1.5",
|
||||
"mocha": "^10.0.0",
|
||||
"nyc": "^15.1.0",
|
||||
|
@ -1,6 +1,7 @@
|
||||
/* 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";
|
||||
import { Footer, Header } from "@file/header";
|
||||
@ -9,6 +10,21 @@ import * as convenienceFunctions from "@util/convenience-functions";
|
||||
|
||||
import { Compiler } from "./next-compiler";
|
||||
|
||||
const unzip = (zipFile: Uint8Array): Promise<ReadonlySet<string>> => {
|
||||
const set = new Set<string>();
|
||||
const unzipper = new fflate.Unzip((file) => {
|
||||
set.add(file.name);
|
||||
});
|
||||
|
||||
return new Promise<ReadonlySet<string>>((resolve) => {
|
||||
setTimeout(() => {
|
||||
resolve(set);
|
||||
}, 1000);
|
||||
|
||||
unzipper.push(zipFile, true);
|
||||
});
|
||||
};
|
||||
|
||||
describe("Compiler", () => {
|
||||
let compiler: Compiler;
|
||||
|
||||
@ -35,10 +51,10 @@ describe("Compiler", () => {
|
||||
},
|
||||
});
|
||||
const zipFile = await compiler.compile(file);
|
||||
const fileNames = Object.keys(zipFile.files).map((f) => zipFile.files[f].name);
|
||||
const fileNames = await unzip(zipFile);
|
||||
|
||||
expect(fileNames).is.an.instanceof(Array);
|
||||
expect(fileNames).has.length(17);
|
||||
expect(fileNames).has.length(13);
|
||||
expect(fileNames).to.include("word/document.xml");
|
||||
expect(fileNames).to.include("word/document.xml");
|
||||
expect(fileNames).to.include("word/styles.xml");
|
||||
expect(fileNames).to.include("docProps/core.xml");
|
||||
@ -60,7 +76,7 @@ describe("Compiler", () => {
|
||||
|
||||
it(
|
||||
"should pack all additional headers and footers",
|
||||
() => {
|
||||
async () => {
|
||||
const file = new File({
|
||||
sections: [
|
||||
{
|
||||
@ -92,12 +108,10 @@ describe("Compiler", () => {
|
||||
],
|
||||
});
|
||||
|
||||
const zipFile = compiler.compile(file);
|
||||
const fileNames = Object.keys(zipFile.files).map((f) => zipFile.files[f].name);
|
||||
|
||||
expect(fileNames).is.an.instanceof(Array);
|
||||
expect(fileNames).has.length(25);
|
||||
const zipFile = await compiler.compile(file);
|
||||
const fileNames = await unzip(zipFile);
|
||||
|
||||
expect(fileNames).has.length(21);
|
||||
expect(fileNames).to.include("word/header1.xml");
|
||||
expect(fileNames).to.include("word/_rels/header1.xml.rels");
|
||||
expect(fileNames).to.include("word/header2.xml");
|
||||
|
@ -1,6 +1,5 @@
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import * as chai from "chai";
|
||||
import * as sinon from "sinon";
|
||||
import JSZip from "jszip";
|
||||
import chaiAsPromised from "chai-as-promised";
|
||||
|
||||
@ -207,8 +206,7 @@ describe("from-docx", () => {
|
||||
describe("patchDocument", () => {
|
||||
describe("document.xml and [Content_Types].xml", () => {
|
||||
beforeEach(() => {
|
||||
sinon.stub(JSZip, "loadAsync").callsFake(
|
||||
() =>
|
||||
vi.spyOn(JSZip, "loadAsync").mockReturnValue(
|
||||
new Promise<JSZip>((resolve) => {
|
||||
const zip = new JSZip();
|
||||
|
||||
@ -292,8 +290,7 @@ describe("from-docx", () => {
|
||||
|
||||
describe("document.xml and [Content_Types].xml with relationships", () => {
|
||||
beforeEach(() => {
|
||||
sinon.stub(JSZip, "loadAsync").callsFake(
|
||||
() =>
|
||||
vi.spyOn(JSZip, "loadAsync").mockReturnValue(
|
||||
new Promise<JSZip>((resolve) => {
|
||||
const zip = new JSZip();
|
||||
|
||||
@ -338,8 +335,7 @@ describe("from-docx", () => {
|
||||
|
||||
describe("document.xml", () => {
|
||||
beforeEach(() => {
|
||||
sinon.stub(JSZip, "loadAsync").callsFake(
|
||||
() =>
|
||||
vi.spyOn(JSZip, "loadAsync").mockReturnValue(
|
||||
new Promise<JSZip>((resolve) => {
|
||||
const zip = new JSZip();
|
||||
|
||||
@ -374,8 +370,7 @@ describe("from-docx", () => {
|
||||
|
||||
describe("Images", () => {
|
||||
beforeEach(() => {
|
||||
sinon.stub(JSZip, "loadAsync").callsFake(
|
||||
() =>
|
||||
vi.spyOn(JSZip, "loadAsync").mockReturnValue(
|
||||
new Promise<JSZip>((resolve) => {
|
||||
const zip = new JSZip();
|
||||
|
||||
|
@ -33,4 +33,7 @@ export default defineConfig({
|
||||
include: [/node_modules/],
|
||||
},
|
||||
},
|
||||
test: {
|
||||
environment: "jsdom",
|
||||
},
|
||||
});
|
||||
|
Reference in New Issue
Block a user