Skip to content

Commit

Permalink
ci: add typecheck step
Browse files Browse the repository at this point in the history
  • Loading branch information
AriPerkkio committed Jun 14, 2024
1 parent 74993b1 commit de168ec
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 9 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ jobs:
- name: Build
run: pnpm build

- name: Typecheck
run: pnpm typecheck

- name: Lint
run: pnpm lint

Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@
"dev": "tsup --watch",
"build": "tsup",
"publish": "clean-publish",
"lint": "eslint --max-warnings=0"
"lint": "eslint --max-warnings=0",
"typecheck": "tsc --noEmit"
},
"devDependencies": {
"@types/node": "^20.12.8",
Expand Down
11 changes: 7 additions & 4 deletions test/move.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import { fileURLToPath } from 'node:url'

const __dirname = dirname(fileURLToPath(import.meta.url))

const { transferableSymbol, valueSymbol } = Tinypool
const transferableSymbol = Tinypool.transferableSymbol as never
const valueSymbol = Tinypool.valueSymbol as never

test('Marking an object as movable works as expected', async () => {
const obj: any = {
Expand All @@ -24,7 +25,7 @@ test('Marking an object as movable works as expected', async () => {
})

test('Marking primitives and null works as expected', async () => {
expect(Tinypool.move(null)).toBe(null)
expect(Tinypool.move(null!)).toBe(null)
expect(Tinypool.move(1 as any)).toBe(1)
expect(Tinypool.move(false as any)).toBe(false)
expect(Tinypool.move('test' as any)).toBe('test')
Expand Down Expand Up @@ -66,8 +67,10 @@ test('Using MessagePort works as expected', async () => {
const mc = new MessageChannel()
const movable = Tinypool.move(mc.port1)
expect(isMovable(movable)).toBe(true)
expect(movable[valueSymbol] instanceof MessagePort).toBe(true)
expect(movable[transferableSymbol] instanceof MessagePort).toBe(true)
expect((movable[valueSymbol] as unknown) instanceof MessagePort).toBe(true)
expect((movable[transferableSymbol] as unknown) instanceof MessagePort).toBe(
true
)
expect(movable[transferableSymbol]).toEqual(mc.port1)
})

Expand Down
8 changes: 6 additions & 2 deletions test/task-queue.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ test('tasks can share a Worker if requested (both tests finish)', async () => {
const buffers = [
new Int32Array(new SharedArrayBuffer(4)),
new Int32Array(new SharedArrayBuffer(4)),
]
] as const

expect(pool.threads.length).toBe(1)
expect(pool.queueSize).toBe(0)
Expand Down Expand Up @@ -254,8 +254,10 @@ test('custom task queue works', async () => {

expect(Tinypool.queueOptionsSymbol in task).toBeTruthy()
if ((task as any).task.a === 3) {
// @ts-expect-error -- intentional
expect(task[Tinypool.queueOptionsSymbol]).toBeNull()
} else {
// @ts-expect-error -- intentional
expect(task[Tinypool.queueOptionsSymbol].option).toEqual(
(task as any).task.a
)
Expand All @@ -266,6 +268,8 @@ test('custom task queue works', async () => {
const index = this.tasks.indexOf(task)
this.tasks.splice(index, 1)
}

cancel() {}
}

const pool = new Tinypool({
Expand All @@ -276,7 +280,7 @@ test('custom task queue works', async () => {
minThreads: 1,
})

function makeTask(task, option) {
function makeTask(task: any, option: any) {
return { ...task, [Tinypool.queueOptionsSymbol]: { option } }
}

Expand Down
4 changes: 2 additions & 2 deletions test/uncaught-exception-from-handler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ test('uncaught exception in immediate after task yields error event', async () =

// Hack a bit to make sure we get the 'exit'/'error' events.
expect(pool.threads.length).toBe(1)
pool.threads[0].ref()
pool.threads[0]!.ref?.()

// This is the main aassertion here.
expect((await errorEvent)[0].message).toEqual('not_caught')
expect((await errorEvent)[0]!.message).toEqual('not_caught')
})

test('using parentPort is treated as an error', async () => {
Expand Down

0 comments on commit de168ec

Please sign in to comment.