test: add vitest & initial tests
This commit is contained in:
parent
6f0ad3e1d5
commit
4f6f441b3b
4 changed files with 772 additions and 2 deletions
|
@ -27,6 +27,7 @@
|
|||
"scripts": {
|
||||
"preinstall": "npx only-allow pnpm",
|
||||
"start": "npx simple-server .",
|
||||
"test": "vitest",
|
||||
"demo": "npx simple-server .",
|
||||
"site": "pnpm --filter site start",
|
||||
"build": "pnpm run clean && tsc && pnpm run copy:source",
|
||||
|
@ -60,7 +61,8 @@
|
|||
"husky": "^9.1.6",
|
||||
"prettier": "^3.3.3",
|
||||
"size-limit": "^11.1.6",
|
||||
"typescript": "^5.6.3"
|
||||
"typescript": "^5.6.3",
|
||||
"vitest": "^2.1.4"
|
||||
},
|
||||
"size-limit": [
|
||||
{
|
||||
|
|
742
pnpm-lock.yaml
742
pnpm-lock.yaml
File diff suppressed because it is too large
Load diff
|
@ -3,7 +3,6 @@ export function serialize(value) {
|
|||
case "number":
|
||||
case "boolean":
|
||||
case "object":
|
||||
case "undefined":
|
||||
return JSON.stringify(value);
|
||||
default:
|
||||
return value;
|
||||
|
|
27
test/serialize.test.ts
Normal file
27
test/serialize.test.ts
Normal file
|
@ -0,0 +1,27 @@
|
|||
import { describe, expect, test } from "vitest";
|
||||
import { serialize } from "../src/utils/serialize.mjs";
|
||||
|
||||
describe("serialize", () => {
|
||||
test("should stringify number", () => {
|
||||
const result = serialize(3);
|
||||
expect(result).toBeTypeOf("string");
|
||||
expect(result).toEqual("3");
|
||||
});
|
||||
|
||||
test("should stringify boolean", () => {
|
||||
const result = serialize(false);
|
||||
expect(result).toBeTypeOf("string");
|
||||
expect(result).toEqual("false");
|
||||
});
|
||||
|
||||
test("should stringify object", () => {
|
||||
const result = serialize({ hello: "world" });
|
||||
expect(result).toBeTypeOf("string");
|
||||
expect(result).toEqual('{"hello":"world"}');
|
||||
});
|
||||
|
||||
test("should return undefined", () => {
|
||||
const result = serialize(undefined);
|
||||
expect(result).toBeUndefined();
|
||||
});
|
||||
});
|
Loading…
Reference in a new issue