From 65f514388c99fc67c55bb52dbfe09b746d1b2639 Mon Sep 17 00:00:00 2001 From: CRBroughton Date: Thu, 18 Apr 2024 07:44:08 +0100 Subject: [PATCH 1/5] feat: :sparkles: Add the isArray and isNonArray - Checks if a type is either an array or not an array --- .changeset/lazy-seas-tan.md | 5 +++++ index.ts | 4 ++++ tests/isArray.test.ts | 15 +++++++++++++++ 3 files changed, 24 insertions(+) create mode 100644 .changeset/lazy-seas-tan.md create mode 100644 tests/isArray.test.ts diff --git a/.changeset/lazy-seas-tan.md b/.changeset/lazy-seas-tan.md new file mode 100644 index 0000000..c685267 --- /dev/null +++ b/.changeset/lazy-seas-tan.md @@ -0,0 +1,5 @@ +--- +"@crbroughton/ts-test-utils": minor +--- + +Add the isArray and isNonArray - Checks if a type is either an array or not an array diff --git a/index.ts b/index.ts index 9412e8d..e7465b5 100644 --- a/index.ts +++ b/index.ts @@ -11,3 +11,7 @@ export type Excludes = [T] extends [U] ? false : true export type Assignable = U extends T ? true : false export type Extends = U extends T ? true : false + +export type isArray = T extends any[] ? true : false + +export type isNonArray = isArray extends true ? false : true diff --git a/tests/isArray.test.ts b/tests/isArray.test.ts new file mode 100644 index 0000000..8d55c8a --- /dev/null +++ b/tests/isArray.test.ts @@ -0,0 +1,15 @@ +/* eslint-disable unused-imports/no-unused-vars */ +import { describe, it } from 'bun:test' +import type { Expect, isArray } from '../index' + +describe('isArray tests', () => { + it('Passes the isArray test when the type is an array', () => { + type Result = Expect> + // ^? + }) + it('Failed the isArray test when the type is not an array', () => { + // @ts-expect-error - Fails the exclusion + type Result = Expect> + // ^? + }) +}) From 8d9d171f47353b8a3c241bf54c55e05af511e031 Mon Sep 17 00:00:00 2001 From: CRBroughton Date: Thu, 18 Apr 2024 07:49:38 +0100 Subject: [PATCH 2/5] fix: :bug: fi test for extends type --- tests/Extends.test.ts | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/tests/Extends.test.ts b/tests/Extends.test.ts index 18fa93e..3163106 100644 --- a/tests/Extends.test.ts +++ b/tests/Extends.test.ts @@ -9,12 +9,9 @@ describe('Extends tests', () => { type Result = Expect> // ^? }) - it('Failed the includes test when the resulting type does not include the sub-type', () => { + it('Failed the extends test when the resulting type does not extend the sub-type', () => { // @ts-expect-error - Object / Record failing the equality checker - type Result = Expect> + type Result = Expect> // ^? }) }) - - - From c3d02cb54544b72bba395b11c1b631c4df38b695 Mon Sep 17 00:00:00 2001 From: CRBroughton Date: Thu, 18 Apr 2024 07:55:51 +0100 Subject: [PATCH 3/5] feat: :wrench: add typecheck command, update builder to run typechecker --- bun.lockb | Bin 200637 -> 200637 bytes package.json | 3 ++- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/bun.lockb b/bun.lockb index e6a39ead5753c790b4ea99584f2a0c2e08ae8143..41dee90d40e073d4f5c6cfeb5138b3da385cee67 100755 GIT binary patch delta 27 jcmdlxpJ(rUo`x32Ele-@*%{*u^o;b3w}0SgI{P00kfI7- delta 27 jcmdlxpJ(rUo`x32Ele-@nV1-+Kg?qi-_9h!wEI5*lAa0- diff --git a/package.json b/package.json index d132d78..22e721e 100644 --- a/package.json +++ b/package.json @@ -22,7 +22,8 @@ "dist" ], "scripts": { - "build": "bun run build.ts", + "typecheck": "tsc --skipLibCheck --noEmit", + "build": "bun run typecheck && bun run build.ts", "lint": "eslint .", "lint:fix": "eslint . --fix", "changeset": "npx changeset", From 8e0d6de34a8181bee92f9451f191bce9c8bb1d4f Mon Sep 17 00:00:00 2001 From: CRBroughton Date: Thu, 18 Apr 2024 07:59:33 +0100 Subject: [PATCH 4/5] chore: :green_heart: add CI pipeline file for tests and typechecking --- .github/workflows/bun.yml | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 .github/workflows/bun.yml diff --git a/.github/workflows/bun.yml b/.github/workflows/bun.yml new file mode 100644 index 0000000..c19b562 --- /dev/null +++ b/.github/workflows/bun.yml @@ -0,0 +1,34 @@ +name: Bun Tests + +env: + VERSION: v1.10.2 + +on: + push: + branches: [develop, master] + pull_request: + branches: [develop, master] +jobs: + bun_test: + timeout-minutes: 60 + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-node@v3 + with: + node-version: 18 + - uses: oven-sh/setup-bun@v1 + with: + bun-version: latest + - name: Install dependencies + run: bun install + - name: Run unit tests + run: bun test + - name: Run typechecker + run: bun run typechecker + - uses: actions/upload-artifact@v3 + if: always() + with: + name: bun-report + path: bun-report/ + retention-days: 30 From 8bd5f59d280d06661faa85f0b0cf84e1725456d2 Mon Sep 17 00:00:00 2001 From: CRBroughton Date: Thu, 18 Apr 2024 08:01:11 +0100 Subject: [PATCH 5/5] chore: :green_heart: fix typecheck command --- .github/workflows/bun.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/bun.yml b/.github/workflows/bun.yml index c19b562..883ddac 100644 --- a/.github/workflows/bun.yml +++ b/.github/workflows/bun.yml @@ -25,7 +25,7 @@ jobs: - name: Run unit tests run: bun test - name: Run typechecker - run: bun run typechecker + run: bun run typecheck - uses: actions/upload-artifact@v3 if: always() with: