Fix tests
This commit is contained in:
@ -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");
|
||||
|
Reference in New Issue
Block a user