Skip to content
This repository has been archived by the owner on Jul 5, 2024. It is now read-only.

Commit

Permalink
chore: fix codecov (#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
KATT authored Sep 30, 2023
1 parent 221d70a commit 6110c2e
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 3 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
coverage/
lib/
node_modules/
.DS_Store
1 change: 1 addition & 0 deletions src/extend/temporal.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const instant: TsonType<Temporal.Instant, string> = {
};

const tson = createTson({
nonce: () => "__tson",
types: [plainDate, instant],
});
test("PlainDate", () => {
Expand Down
2 changes: 1 addition & 1 deletion src/handlers/tsonUnknownObjectGuard.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { isPlainObject } from "../isPlainObject.js";
import { TsonType } from "../types.js";
import { isPlainObject } from "../utils.js";

export class UnknownObjectGuardError extends Error {
/**
Expand Down
31 changes: 31 additions & 0 deletions src/isPlainObject.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { expect, test } from "vitest";

import { isPlainObject } from "./isPlainObject.js";

test("should return true for plain objects", () => {
expect(isPlainObject({})).toBe(true);
expect(isPlainObject({ a: 1 })).toBe(true);
expect(isPlainObject(Object.create(null))).toBe(true);
});

test("should return false for non-objects", () => {
expect(isPlainObject(null)).toBe(false);
expect(isPlainObject(undefined)).toBe(false);
expect(isPlainObject(42)).toBe(false);
expect(isPlainObject("foo")).toBe(false);
expect(isPlainObject(true)).toBe(false);
expect(isPlainObject(Symbol())).toBe(false);
});

test("should return false for non-plain objects", () => {
expect(isPlainObject([])).toBe(false);
expect(isPlainObject(new Date())).toBe(false);
expect(isPlainObject(/foo/)).toBe(false);
expect(
isPlainObject(() => {
// noop
}),
).toBe(false);

expect(isPlainObject(Object.prototype)).toBe(false);
});
File renamed without changes.
33 changes: 33 additions & 0 deletions src/tson.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { expect, test } from "vitest";

import { createTson } from "./tson.js";
import { TsonType } from "./types.js";

test("multiple handlers for primitive string found", () => {
const stringHandler: TsonType<string, never> = {
primitive: "string",
};
expect(() => {
createTson({
types: [stringHandler, stringHandler],
});
}).toThrowErrorMatchingInlineSnapshot(
'"Multiple handlers for primitive string found"',
);
});

test("duplicate keys", () => {
const stringHandler: TsonType<string, string> = {
deserialize: (v) => v,
key: "string",
serialize: (v) => v,
test: (v) => typeof v === "string",
};
expect(() => {
createTson({
types: [stringHandler, stringHandler],
});
}).toThrowErrorMatchingInlineSnapshot(
'"Multiple handlers for key string found"',
);
});
4 changes: 2 additions & 2 deletions src/tson.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// eslint-disable-next-line eslint-comments/disable-enable-pair
/* eslint-disable eslint-comments/disable-enable-pair */
/* eslint-disable @typescript-eslint/no-explicit-any */
import { isPlainObject } from "./isPlainObject.js";
import {
TsonAllTypes,
TsonDeserializeFn,
Expand All @@ -16,7 +17,6 @@ import {
TsonTypeTesterCustom,
TsonTypeTesterPrimitive,
} from "./types.js";
import { isPlainObject } from "./utils.js";

function isTsonTuple(v: unknown, nonce: string): v is TsonTuple {
return Array.isArray(v) && v.length === 3 && v[2] === nonce;
Expand Down

0 comments on commit 6110c2e

Please sign in to comment.