Removed old TS tests

This commit is contained in:
Alexander Cerutti
2023-04-11 23:09:55 +02:00
parent 57ac18154c
commit e4e7ba1587
6 changed files with 1 additions and 1636 deletions

View File

@@ -5,9 +5,8 @@
"main": "lib/index.js",
"scripts": {
"build": "npm run build:src",
"build:all": "npm run build:src && npm run build:examples && npm run build:spec",
"build:all": "npm run build:src && npm run build:examples",
"build:src": "rimraf lib && npx tsc -p tsconfig.dist.json",
"build:spec": "rimraf \"./spec/*.!(ts)\" && npx tsc -p tsconfig.spec.json",
"prepublishOnly": "npm run build",
"test": "NODE_OPTIONS=\"--experimental-vm-modules --no-warnings\" jest -c jest.config.cjs --silent"
},

View File

@@ -1,123 +0,0 @@
import { Stream } from "stream";
import { Buffer } from "buffer";
import * as Messages from "../lib/messages";
import { default as Bundle, filesSymbol } from "../lib/Bundle";
describe("Bundle", () => {
let bundle: InstanceType<typeof Bundle>;
beforeEach(() => {
bundle = new Bundle("application/vnd.apple.pkpass");
});
describe("freezable", () => {
it("should expose freeze method and bundle itself to be frozen", () => {
const [bundle, freeze] = Bundle.freezable("any/any");
freeze();
expect(bundle.isFrozen).toBe(true);
});
});
describe("mimeType", () => {
it("should throw an error if no mime-type is specified in the constructor", () => {
// @ts-expect-error
expect(() => new Bundle()).toThrowError(
Error,
Messages.BUNDLE.MIME_TYPE_MISSING,
);
});
it("should expose the mime-type as public property", () => {
expect(bundle.mimeType).toBe("application/vnd.apple.pkpass");
});
});
describe("addBuffer", () => {
it("should allow to add buffers", () => {
const buffer = Buffer.alloc(0);
bundle.addBuffer("pass.json", buffer);
expect(bundle[filesSymbol]).toEqual({ "pass.json": buffer });
});
});
describe("exporting", () => {
describe("getAsStream", () => {
it("should return a stream", () => {
addEmptyFilesToBundle(bundle);
expect(bundle.getAsStream()).toBeInstanceOf(Stream);
});
it("should freeze the bundle", () => {
bundle.getAsStream();
expect(bundle.isFrozen).toBe(true);
});
it("should throw error if a file is attempted to be added when bundle is frozen", () => {
addEmptyFilesToBundle(bundle);
bundle.getAsStream();
expect(() =>
bundle.addBuffer("icon.png", Buffer.alloc(0)),
).toThrowError(Error, Messages.BUNDLE.CLOSED);
});
});
describe("getAsBuffer", () => {
it("should return a buffer", () => {
addEmptyFilesToBundle(bundle);
expect(bundle.getAsBuffer()).toBeInstanceOf(Buffer);
});
it("should freeze the bundle", () => {
bundle.getAsBuffer();
expect(bundle.isFrozen).toBe(true);
});
it("should throw error if a file is attempted to be added when bundle is frozen", () => {
addEmptyFilesToBundle(bundle);
bundle.getAsBuffer();
expect(() =>
bundle.addBuffer("icon.png", Buffer.alloc(0)),
).toThrowError(Error, Messages.BUNDLE.CLOSED);
});
});
describe("getAsRaw", () => {
it("should freeze the bundle", () => {
bundle.getAsRaw();
expect(bundle.isFrozen).toBe(true);
});
it("should return an object with filePath as key and Buffer as value", () => {
bundle.addBuffer("pass.json", Buffer.alloc(0));
bundle.addBuffer("signature", Buffer.alloc(0));
bundle.addBuffer("en.lproj/pass.strings", Buffer.alloc(0));
bundle.addBuffer("en.lproj/icon.png", Buffer.alloc(0));
const list = bundle.getAsRaw();
expect(list["pass.json"]).not.toBeUndefined();
expect(list["pass.json"]).toBeInstanceOf(Buffer);
expect(list["signature"]).not.toBeUndefined();
expect(list["signature"]).toBeInstanceOf(Buffer);
expect(list["en.lproj/pass.strings"]).not.toBeUndefined();
expect(list["en.lproj/pass.strings"]).toBeInstanceOf(Buffer);
expect(list["en.lproj/icon.png"]).not.toBeUndefined();
expect(list["en.lproj/icon.png"]).toBeInstanceOf(Buffer);
});
});
});
});
function addEmptyFilesToBundle(bundle: Bundle) {
const buffer = Buffer.alloc(0);
bundle.addBuffer("pass.json", buffer);
bundle.addBuffer("icon@2x.png", buffer);
bundle.addBuffer("icon@3x.png", buffer);
}

View File

@@ -1,227 +0,0 @@
import { PKPass } from "../lib";
import FieldsArray from "../lib/FieldsArray";
import * as Messages from "../lib/messages";
import * as Schemas from "../lib/schemas";
describe("FieldsArray", () => {
let fa: FieldsArray;
let frozen = false;
let pool: Set<string>;
beforeEach(() => {
frozen = false;
pool = new Set<string>();
fa = new FieldsArray(
{
get isFrozen() {
return frozen;
},
} as PKPass /** Fake pass. This is okay for testing */,
pool,
Schemas.Field,
);
});
it("should extend an array", () => {
expect(fa instanceof Array).toBe(true);
});
describe("push", () => {
it("should prevent adding new fields if pass is frozen", () => {
frozen = true;
expect(() => fa.push({ key: "t1", value: "v1" })).toThrowError(
Error,
Messages.BUNDLE.CLOSED,
);
});
it("should allow adding fields", () => {
expect(fa.push({ key: "t1", value: "v1" })).toBe(1);
expect(fa.length).toBe(1);
expect(fa[0]).toEqual({ key: "t1", value: "v1" });
});
it("should preserve order of input items when adding fields", () => {
expect(
fa.push({ key: "t1", value: "v1" }, { key: "t2", value: "v2" }),
).toBe(2);
expect(fa.length).toBe(2);
expect(fa[0]).toEqual({ key: "t1", value: "v1" });
expect(fa[1]).toEqual({ key: "t2", value: "v2" });
});
it("should add the key to the pool", () => {
fa.push({ key: "t1", value: "v1" });
expect(pool.has("t1")).toBe(true);
});
it("should log a warning if key already exists and omit that object", () => {
fa.push({ key: "t1", value: "v1" });
console.warn = jasmine.createSpy("log");
fa.push({ key: "t1", value: "v1" });
expect(console.warn).toHaveBeenCalledWith(
Messages.FIELDS.REPEATED_KEY.replace("%s", "t1"),
);
expect(fa.length).toBe(1);
});
it("should log a warning if input items contain undefined and, then, ignore it", () => {
console.warn = jasmine.createSpy("log");
fa.push(undefined, { key: "t1", value: "v1" });
expect(console.warn).toHaveBeenCalledWith(
Messages.FIELDS.INVALID.replace("%s", "undefined"),
);
expect(fa.length).toBe(1);
});
});
describe("pop", () => {
beforeEach(() => {
fa.push({ key: "t1", value: "v1" });
});
it("should prevent popping out fields if pass is frozen", () => {
frozen = true;
expect(() => fa.pop()).toThrowError(Error, Messages.BUNDLE.CLOSED);
});
it("should popping out fields", () => {
expect(fa.pop()).toEqual({ key: "t1", value: "v1" });
expect(fa.length).toBe(0);
expect(fa[0]).toBeUndefined();
});
it("should remove the key from the pool", () => {
expect(pool.has("t1")).toBe(true);
fa.pop();
expect(pool.has("t1")).toBe(false);
});
});
describe("splice", () => {
beforeEach(() => {
fa.push({ key: "t1", value: "v1" });
});
it("should prevent splicing fields if pass is frozen", () => {
frozen = true;
expect(() =>
fa.splice(0, 1, { key: "k1", value: "v1" }),
).toThrowError(Error, Messages.BUNDLE.CLOSED);
});
it("should remove the key from the pool", () => {
expect(pool.has("t1")).toBe(true);
fa.splice(0, 1, { key: "k1", value: "v2" });
expect(pool.has("t1")).toBe(false);
expect(pool.has("k1")).toBe(true);
});
it("should log a warning if key already exists and omit that object", () => {
fa.push({ key: "t2", value: "v2" });
fa.push({ key: "t3", value: "v3" });
fa.push({ key: "t4", value: "v4" });
console.warn = jasmine.createSpy("log");
fa.splice(0, 1, { key: "t2", value: "v2" });
expect(console.warn).toHaveBeenCalledWith(
Messages.FIELDS.REPEATED_KEY.replace("%s", "t2"),
);
expect(fa.length).toBe(3);
});
});
describe("shift", () => {
beforeEach(() => {
fa.push({ key: "t1", value: "v1" });
fa.push({ key: "t2", value: "v2" });
});
it("should prevent popping out fields if pass is frozen", () => {
frozen = true;
expect(() => fa.shift()).toThrowError(
Error,
Messages.BUNDLE.CLOSED,
);
});
it("should shift out fields", () => {
expect(fa.shift()).toEqual({ key: "t1", value: "v1" });
expect(fa.length).toBe(1);
expect(fa[0]).toEqual({ key: "t2", value: "v2" });
});
it("should remove the key from the pool", () => {
expect(pool.has("t1")).toBe(true);
fa.shift();
expect(pool.has("t1")).toBe(false);
});
});
describe("unshift", () => {
it("should prevent adding new fields if pass is frozen", () => {
frozen = true;
expect(() => fa.unshift({ key: "t1", value: "v1" })).toThrowError(
Error,
Messages.BUNDLE.CLOSED,
);
});
it("should allow adding fields", () => {
expect(fa.unshift({ key: "t1", value: "v1" })).toBe(1);
expect(fa.length).toBe(1);
expect(fa[0]).toEqual({ key: "t1", value: "v1" });
});
it("should add the key to the pool", () => {
fa.unshift({ key: "t1", value: "v1" });
expect(pool.has("t1")).toBe(true);
});
it("should log a warning if key already exists and omit that object", () => {
fa.push({ key: "t1", value: "v1" });
console.warn = jasmine.createSpy("log");
fa.unshift({ key: "t1", value: "v1" });
expect(console.warn).toHaveBeenCalledWith(
Messages.FIELDS.REPEATED_KEY.replace("%s", "t1"),
);
expect(fa.length).toBe(1);
});
it("should preserve order of input items when adding fields", () => {
expect(
fa.push({ key: "t1", value: "v1" }, { key: "t2", value: "v2" }),
).toBe(2);
expect(fa.length).toBe(2);
expect(fa[0]).toEqual({ key: "t1", value: "v1" });
expect(fa[1]).toEqual({ key: "t2", value: "v2" });
});
});
});

File diff suppressed because it is too large Load Diff

View File

@@ -1,39 +0,0 @@
import { processDate, removeHidden } from "../lib/utils";
describe("Utils", () => {
describe("removeHidden", () => {
it("should remove files that start with dot", () => {
const filesList = [
"a.png",
"b.png",
".DS_Store",
"not_the_droids_you_are_looking_for.txt",
];
expect(removeHidden(filesList)).toEqual([
"a.png",
"b.png",
"not_the_droids_you_are_looking_for.txt",
]);
});
});
describe("processDate", () => {
it("should throw Invalid date if args[0] is not a date", () => {
//@ts-expect-error
expect(() => processDate(5)).toThrow("Invalid date");
//@ts-expect-error
expect(() => processDate({})).toThrow("Invalid date");
//@ts-expect-error
expect(() => processDate("ciao")).toThrow("Invalid date");
//@ts-expect-error
expect(() => processDate(true)).toThrow("Invalid date");
});
it("should convert a Date object to a valid W3C date", () => {
expect(processDate(new Date(2020, 6, 1, 0, 0, 0, 0))).toBe(
"2020-07-01T00:00:00Z",
);
});
});
});

View File

@@ -1,9 +0,0 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"sourceMap": true
},
"include": [
"spec/**/*",
]
}