Skip to content

Commit

Permalink
feat: use Vitest
Browse files Browse the repository at this point in the history
  • Loading branch information
yamiteru committed Apr 16, 2024
1 parent 06851e1 commit 6849f3d
Show file tree
Hide file tree
Showing 49 changed files with 112 additions and 99 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@

dist
node_modules
coverage

bun.lockb
11 changes: 8 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,19 @@
"build:stats": "bun run scripts/stats.ts",
"build:clean": "rm -rf build",
"build:imports": "bun run scripts/imports.ts",
"test": "bun test --coverage ./src/**/test.ts",
"test:run": "vitest run",
"test:watch": "vitest",
"test:coverage": "vitest run --coverage",
"check": "bunx @biomejs/biome check --apply ./"
},
"devDependencies": {
"@biomejs/biome": "1.6.4",
"@types/bun": "latest",
"@vitest/coverage-v8": "^1.5.0",
"release-it": "17.2.0",
"tsup": "8.0.2"
"tsup": "8.0.2",
"vite-tsconfig-paths": "^4.3.2",
"vitest": "1.5.0"
},
"peerDependencies": {
"typescript": "5.4.5"
Expand All @@ -55,7 +60,7 @@
"access": "public"
},
"dependencies": {
"@the-minimal/error": "0.0.2",
"@the-minimal/error": "0.0.3",
"@the-minimal/types": "0.0.4"
}
}
8 changes: 4 additions & 4 deletions src/validators/and/test.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { expect, it } from "bun:test";
import { maxValue } from "@validators/maxValue";
import { number } from "@validators/number";
import { expect, it } from "vitest";
import { and } from "./index";

const validator = and([number, maxValue(2)]);

it("should not throw", () => {
expect(() => validation(2)).not.toThrow();
expect(() => validator(2)).not.toThrow();
});

it("should throw", () => {
expect(() => validation("")).toThrow();
expect(() => validation(3)).toThrow();
expect(() => validator("")).toThrow();
expect(() => validator(3)).toThrow();
});
8 changes: 4 additions & 4 deletions src/validators/and2/test.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { expect, it } from "bun:test";
import { maxValue } from "@validators/maxValue";
import { number } from "@validators/number";
import { expect, it } from "vitest";
import { and2 } from "./index";

const validator = and2(number, maxValue(2));

it("should not throw", () => {
expect(() => validation(2)).not.toThrow();
expect(() => validator(2)).not.toThrow();
});

it("should throw", () => {
expect(() => validation("")).toThrow();
expect(() => validation(3)).toThrow();
expect(() => validator("")).toThrow();
expect(() => validator(3)).toThrow();
});
10 changes: 5 additions & 5 deletions src/validators/and3/test.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import { expect, it } from "bun:test";
import { maxValue } from "@validators/maxValue";
import { minValue } from "@validators/minValue";
import { number } from "@validators/number";
import { expect, it } from "vitest";
import { and3 } from "./index";

const validator = and3(number, minValue(0), maxValue(2));

it("should not throw", () => {
expect(() => validation(2)).not.toThrow();
expect(() => validator(2)).not.toThrow();
});

it("should throw", () => {
expect(() => validation("")).toThrow();
expect(() => validation(-1)).toThrow();
expect(() => validation(3)).toThrow();
expect(() => validator("")).toThrow();
expect(() => validator(-1)).toThrow();
expect(() => validator(3)).toThrow();
});
4 changes: 2 additions & 2 deletions src/validators/any/test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { expect, it } from "bun:test";
import { any } from "@validators/any/index";
import { any } from "@validators/any";
import { expect, it } from "vitest";

it("should not throw", () => {
expect(() => any(2)).not.toThrow();
Expand Down
8 changes: 4 additions & 4 deletions src/validators/array/test.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { expect, it } from "bun:test";
import { number } from "@validators/number";
import { expect, it } from "vitest";
import { array } from "./index";

const validator = array(number);

it("should not throw", () => {
expect(() => validation([1, 2, 3])).not.toThrow();
expect(() => validator([1, 2, 3])).not.toThrow();
});

it("should throw", () => {
expect(() => validation(1)).toThrow();
expect(() => validation([1, "2", 3])).toThrow();
expect(() => validator(1)).toThrow();
expect(() => validator([1, "2", 3])).toThrow();
});
6 changes: 3 additions & 3 deletions src/validators/assert/test.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { expect, it } from "bun:test";
import { expect, it } from "vitest";
import { assert } from "./index";

const validator = assert((value) => value === 1, "test");

it("should not throw", () => {
expect(() => validation(1)).not.toThrow();
expect(() => validator(1)).not.toThrow();
});

it("should throw", () => {
expect(() => validation(2)).toThrow();
expect(() => validator(2)).toThrow();
});
4 changes: 2 additions & 2 deletions src/validators/bigint/test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { expect, it } from "bun:test";
import { bigint } from "@validators/bigint/index";
import { bigint } from "@validators/bigint";
import { expect, it } from "vitest";

it("should not throw", () => {
expect(() => bigint(BigInt(2))).not.toThrow();
Expand Down
2 changes: 1 addition & 1 deletion src/validators/boolean/test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { expect, it } from "bun:test";
import { boolean } from "@validators/boolean";
import { expect, it } from "vitest";

it("should not throw", () => {
expect(() => boolean(true)).not.toThrow();
Expand Down
2 changes: 1 addition & 1 deletion src/validators/date/test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { expect, it } from "bun:test";
import { date } from "@validators/date";
import { expect, it } from "vitest";

it("should not throw", () => {
expect(() => date(new Date())).not.toThrow();
Expand Down
4 changes: 2 additions & 2 deletions src/validators/email/test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { expect, it } from "bun:test";
import { email } from "@validators/email/index";
import { email } from "@validators/email";
import { expect, it } from "vitest";

it("should not throw", () => {
expect(() => email("yamiteru@icloud.com")).not.toThrow();
Expand Down
4 changes: 2 additions & 2 deletions src/validators/endsWith/test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { expect, it } from "bun:test";
import { endsWith } from "@validators/endsWith/index";
import { endsWith } from "@validators/endsWith";
import { expect, it } from "vitest";

const validator = endsWith("lo");

Expand Down
2 changes: 1 addition & 1 deletion src/validators/expect/test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { expect, it } from "bun:test";
import { string } from "@validators/string";
import { expect, it } from "vitest";
import { expect as _expect } from "./index";

const validator = _expect(string, (e) => `Error: ${e.message}`);
Expand Down
4 changes: 2 additions & 2 deletions src/validators/includes/test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { expect, it } from "bun:test";
import { includes } from "@validators/includes/index";
import { includes } from "@validators/includes";
import { expect, it } from "vitest";

const validator = includes("el");

Expand Down
2 changes: 1 addition & 1 deletion src/validators/instance/test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { expect, it } from "bun:test";
import { date } from "@validators/date";
import { expect, it } from "vitest";

it("should not throw", () => {
expect(() => date(new Date())).not.toThrow();
Expand Down
4 changes: 2 additions & 2 deletions src/validators/integer/test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { expect, it } from "bun:test";
import { integer } from "@validators/integer/index";
import { integer } from "@validators/integer";
import { expect, it } from "vitest";

it("should not throw", () => {
expect(() => integer(1)).not.toThrow();
Expand Down
4 changes: 2 additions & 2 deletions src/validators/isArray/test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { expect, it } from "bun:test";
import { isArray } from "@validators/isArray/index";
import { isArray } from "@validators/isArray";
import { expect, it } from "vitest";

it("should not throw", () => {
expect(() => isArray([])).not.toThrow();
Expand Down
4 changes: 2 additions & 2 deletions src/validators/isObject/test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { expect, it } from "bun:test";
import { isObject } from "@validators/isObject/index";
import { isObject } from "@validators/isObject";
import { expect, it } from "vitest";

it("should not throw", () => {
expect(() => isObject({})).not.toThrow();
Expand Down
2 changes: 1 addition & 1 deletion src/validators/lazy/test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { expect, it } from "bun:test";
import type { Assertion } from "@the-minimal/types";
import { lazy } from "@validators/lazy";
import { object } from "@validators/object";
import { optional } from "@validators/optional";
import { string } from "@validators/string";
import { expect, it } from "vitest";

type User = {
name: string;
Expand Down
4 changes: 2 additions & 2 deletions src/validators/length/test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { expect, it } from "bun:test";
import { length } from "@validators/length/index";
import { length } from "@validators/length";
import { expect, it } from "vitest";

const validator = length(1);

Expand Down
4 changes: 2 additions & 2 deletions src/validators/maxLength/test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { expect, it } from "bun:test";
import { maxLength } from "@validators/maxLength/index";
import { maxLength } from "@validators/maxLength";
import { expect, it } from "vitest";

const validator = maxLength(1);

Expand Down
6 changes: 3 additions & 3 deletions src/validators/maxValue/test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { expect, it } from "bun:test";
import { maxValue } from "@validators/maxValue/index";
import { maxValue } from "@validators/maxValue";
import { expect, it } from "vitest";

const validator = (value: unknown) => maxValue(1);
const validator = maxValue(1);

it("should not throw", () => {
expect(() => validator(0)).not.toThrow();
Expand Down
4 changes: 2 additions & 2 deletions src/validators/minLength/test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { expect, it } from "bun:test";
import { minLength } from "@validators/minLength/index";
import { minLength } from "@validators/minLength";
import { expect, it } from "vitest";

const validator = minLength(1);

Expand Down
4 changes: 2 additions & 2 deletions src/validators/minValue/test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { expect, it } from "bun:test";
import { minValue } from "@validators/minValue/index";
import { minValue } from "@validators/minValue";
import { expect, it } from "vitest";

const validator = minValue(1);

Expand Down
4 changes: 2 additions & 2 deletions src/validators/multipleOf/test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { expect, it } from "bun:test";
import { multipleOf } from "@validators/multipleOf/index";
import { multipleOf } from "@validators/multipleOf";
import { expect, it } from "vitest";

const validator = multipleOf(2);

Expand Down
4 changes: 2 additions & 2 deletions src/validators/nan/test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { expect, it } from "bun:test";
import { nan } from "@validators/nan/index";
import { nan } from "@validators/nan";
import { expect, it } from "vitest";

it("should not throw", () => {
expect(() => nan(Number.NaN)).not.toThrow();
Expand Down
4 changes: 2 additions & 2 deletions src/validators/notLength/test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { expect, it } from "bun:test";
import { notLength } from "@validators/notLength/index";
import { notLength } from "@validators/notLength";
import { expect, it } from "vitest";

const validator = notLength(2);

Expand Down
4 changes: 2 additions & 2 deletions src/validators/notValue/test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { expect, it } from "bun:test";
import { notValue } from "@validators/notValue/index";
import { notValue } from "@validators/notValue";
import { expect, it } from "vitest";

const validator = notValue(2);

Expand Down
2 changes: 1 addition & 1 deletion src/validators/nullable/test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { expect, it } from "bun:test";
import { string } from "@validators/string";
import { expect, it } from "vitest";
import { nullable } from "./index";

const validator = nullable(string);
Expand Down
2 changes: 1 addition & 1 deletion src/validators/nullish/test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { expect, it } from "bun:test";
import { string } from "@validators/string";
import { expect, it } from "vitest";
import { nullish } from "./index";

const validator = nullish(string);
Expand Down
4 changes: 2 additions & 2 deletions src/validators/number/test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { expect, it } from "bun:test";
import { number } from "@validators/number/index";
import { number } from "@validators/number";
import { expect, it } from "vitest";

it("should not throw", () => {
expect(() => number(1)).not.toThrow();
Expand Down
2 changes: 1 addition & 1 deletion src/validators/object/test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { expect, it } from "bun:test";
import { boolean } from "@validators/boolean";
import { number } from "@validators/number";
import { string } from "@validators/string";
import { expect, it } from "vitest";
import { object } from "./index";

const validator = object({
Expand Down
2 changes: 1 addition & 1 deletion src/validators/optional/test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { expect, it } from "bun:test";
import { string } from "@validators/string";
import { expect, it } from "vitest";
import { optional } from "./index";

const validator = optional(string);
Expand Down
2 changes: 1 addition & 1 deletion src/validators/options/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { assert } from "@validators/assert";

export const options = <$Options extends unknown[]>(options: $Options) =>
assert(options.includes, "options", options);
assert((v) => options.includes(v), "options", options);
4 changes: 2 additions & 2 deletions src/validators/options/test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { expect, it } from "bun:test";
import { options } from "@validators/options/index";
import { options } from "@validators/options";
import { expect, it } from "vitest";

const validator = options(["one", "two"]);

Expand Down
2 changes: 1 addition & 1 deletion src/validators/or/test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { expect, it } from "bun:test";
import { number } from "@validators/number";
import { string } from "@validators/string";
import { expect, it } from "vitest";
import { or } from "./index";

const validator = or([number, string]);
Expand Down
2 changes: 1 addition & 1 deletion src/validators/or2/test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { expect, it } from "bun:test";
import { number } from "@validators/number";
import { string } from "@validators/string";
import { expect, it } from "vitest";
import { or2 } from "./index";

const validator = or2(number, string);
Expand Down
2 changes: 1 addition & 1 deletion src/validators/or3/test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { expect, it } from "bun:test";
import { boolean } from "@validators/boolean";
import { number } from "@validators/number";
import { string } from "@validators/string";
import { expect, it } from "vitest";
import { or3 } from "./index";

const validator = or3(number, string, boolean);
Expand Down
2 changes: 1 addition & 1 deletion src/validators/regex/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { assert } from "@validators/assert";

export const regex = (pattern: RegExp) =>
assert(pattern.test as any, "regex", pattern);
assert((v) => pattern.test(v as any), "regex", pattern);
Loading

0 comments on commit 6849f3d

Please sign in to comment.