Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bun #16

Merged
merged 4 commits into from
Aug 23, 2024
Merged

Bun #16

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
name: Publish

on: [push]
on:
push:
tags:
- v*

jobs:
buildNPublish:
if: contains(github.ref, 'refs/tags/v')
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: actions/setup-node@v1
with:
node-version: 13
- uses: actions/checkout@v4
- uses: oven-sh/setup-bun@v2
- run: bun install
- run: yarn
- run: yarn test
- run: yarn build
Expand Down
7 changes: 3 additions & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@ jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: actions/setup-node@v1
with:
node-version: 14
- uses: actions/checkout@v4
- uses: oven-sh/setup-bun@v2
- run: bun install
- run: yarn
- run: yarn build
- run: yarn test
9 changes: 3 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
{
"name": "@nexys/validation",
"version": "2.1.6",
"version": "2.1.7",
"description": "Validation",
"keywords": [
"validation",
"typescript",
"koa"
],
"scripts": {
"test": "rm -rf dist && jest --verbose",
"test": "bun test",
"build": "tsc"
},
"main": "dist/index.js",
Expand All @@ -24,10 +24,7 @@
"license": "MIT",
"private": false,
"devDependencies": {
"@types/jest": "^25.2.3",
"@types/nock": "^11.1.0",
"jest": "^26.0.1",
"ts-jest": "^25.3.1",
"@types/bun": "^1.1.6",
"typescript": "^5.5.4"
}
}
6 changes: 4 additions & 2 deletions src/array.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { test, expect } from "bun:test";

import * as M from "./main";
import { Shape } from "./type";
import * as U from "./utils";
Expand Down Expand Up @@ -137,8 +139,8 @@ test("expects array of integers", () => {
const shape: Shape = {
ids: { $array: { type: "number" } },
};
const body = { ids: [1,2,3] };

const body = { ids: [1, 2, 3] };
const m = M.checkObject(body, shape);

expect(m).toEqual({});
Expand Down
5 changes: 3 additions & 2 deletions src/main.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { test, expect, describe } from "bun:test";
import * as M from "./main";
import { Shape } from "./type";

Expand Down Expand Up @@ -118,7 +119,7 @@ describe("checkObject", () => {
const r = M.checkObject(input, shape);

// in this case, an extra params was added (middle name), make sure that it was removed from object after validation
expect(input.profile.middleName).toEqual(undefined);
expect(input.profile.middleName).toEqual(undefined as any);

expect(r).toEqual({
email: ["This field is required"],
Expand All @@ -135,7 +136,7 @@ describe("checkObject", () => {
const r = M.checkObject(input, shape, false);

// in this case, an extra params was added (middle name), make sure that it was removed from object after validation
expect(input.profile.middleName).toEqual(undefined);
expect(input.profile.middleName).toEqual(undefined as any);

expect(r).toEqual({
email: ["This field is required"],
Expand Down
12 changes: 7 additions & 5 deletions src/object.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { test, expect } from "bun:test";

import * as M from "./main";
import * as T from "./type";
import * as U from "./utils";
Expand Down Expand Up @@ -53,16 +55,16 @@ test("is object - optional nested", () => {
expect(m).toEqual({});
});

test('generic object - optional', () => {
test("generic object - optional", () => {
const shape: T.Shape = {
uuid: { extraCheck: U.checkUuid },
params: { type: "object", optional: true },
data: { type: "object", optional: true },
};
const input = {uuid: 'ef04fafc-af19-11eb-847c-42010aac003d'};

const input = { uuid: "ef04fafc-af19-11eb-847c-42010aac003d" };

const m = M.checkObject(input, shape);

expect(m).toEqual({});
})
});
30 changes: 16 additions & 14 deletions src/utils.test.ts
Original file line number Diff line number Diff line change
@@ -1,56 +1,58 @@
import { test, expect } from "bun:test";
import * as U from "./utils";

test("check email", () => {
expect(U.emailCheck("[email protected]")).toEqual(undefined);
expect(U.emailCheck("[email protected]")).toEqual(undefined as any);
expect(U.emailCheck("johndoe.com")).toEqual(["email invalid"]);
expect(U.emailCheck("[email protected]")).toEqual(undefined);
expect(U.emailCheck("[email protected]")).toEqual(undefined as any);
expect(U.emailCheck(" [email protected]")).toEqual([
"email must not contain any whitespace (before or after)",
]);
});

test("check password", () => {
expect(U.passwordCheck("[email protected]")).toEqual(undefined);
expect(U.passwordCheck("[email protected]")).toEqual(undefined as any);
expect(U.passwordCheck("jo")).toEqual(["password length smaller than 8"]);
});

test("check uuid", () => {
expect(U.checkUuid("983aa206-a047-48b6-82b0-96873d9e4dd5")).toEqual(
undefined
undefined as any
);
expect(U.checkUuid("jo")).toEqual(["uuid invalid"]);
});

test("regex check", () => {
const r: RegExp = /^My\d{3}$/;

expect(U.regexCheck("My123", r)).toEqual(undefined);
expect(U.regexCheck("My123", r)).toEqual(undefined as any);
expect(U.regexCheck("My1234", r)).toEqual([
"regex /^My\\d{3}$/ not satisfied",
]);
});

test("is id", () => {
expect(U.checkId(12)).toEqual(undefined);
expect(U.checkId(12)).toEqual(undefined as any);
expect(U.checkId(-1)).toEqual(["id must be greater than 0"]);
expect(U.checkId(1.54)).toEqual(["must be an integer"]);
});

test("is integer", () => {
expect(U.checkInteger(12)).toEqual(undefined);
expect(U.checkInteger(12)).toEqual(undefined as any);
expect(U.checkInteger(12.3)).toEqual(["must be an integer"]);
expect(U.checkInteger(-12)).toEqual(["negative numbers are not accepted"]);
});

test("check JSON", () => {
// Valid JSON strings
expect(U.checkJSON('{"name": "John", "age": 30}')).toEqual(undefined);
expect(U.checkJSON('[1, 2, 3, 4]')).toEqual(undefined);
expect(U.checkJSON('"This is a valid JSON string"')).toEqual(undefined);

expect(U.checkJSON('{"name": "John", "age": 30}')).toEqual(undefined as any);
expect(U.checkJSON("[1, 2, 3, 4]")).toEqual(undefined as any);
expect(U.checkJSON('"This is a valid JSON string"')).toEqual(
undefined as any
);

// Invalid JSON strings
expect(U.checkJSON('{name: "John", age: 30}')).toEqual(["must be a JSON"]);
expect(U.checkJSON('[1, 2, 3, 4')).toEqual(["must be a JSON"]);
expect(U.checkJSON('Invalid JSON')).toEqual(["must be a JSON"]);
expect(U.checkJSON("[1, 2, 3, 4")).toEqual(["must be a JSON"]);
expect(U.checkJSON("Invalid JSON")).toEqual(["must be a JSON"]);
});

3 changes: 1 addition & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@
// "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */
// "typeRoots": [], /* List of folders to include type definitions from. */
"types": [
"node",
"jest"
"node"
] /* Type declaration files to be included in compilation. */,
"allowSyntheticDefaultImports": true /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */,
"esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */,
Expand Down
Loading