Skip to content

Commit

Permalink
Update test runner
Browse files Browse the repository at this point in the history
  • Loading branch information
ai committed Nov 23, 2023
1 parent 7a5cd91 commit bfc868c
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 59 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ jobs:
- name: Install dependencies
run: pnpm install --frozen-lockfile --ignore-scripts
- name: Run unit tests
run: pnpm unit
run: pnpm bnt
benchmark:
name: Benchmark
runs-on: ubuntu-latest
Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@
"subscribe"
],
"scripts": {
"unit": "tsm ./node_modules/uvu/bin.js . '\\.test\\.(ts|js)$'",
"test:coverage": "c8 pnpm unit",
"test:coverage": "c8 pnpm bnt",
"test:lint": "eslint .",
"test:types": "check-dts",
"test:size": "size-limit",
Expand All @@ -37,9 +36,11 @@
"devDependencies": {
"@logux/eslint-config": "^52.0.2",
"@size-limit/preset-small-lib": "^11.0.0",
"@types/node": "^20.9.4",
"@typescript-eslint/eslint-plugin": "^6.12.0",
"@typescript-eslint/parser": "^6.12.0",
"benchmark": "^2.1.4",
"better-node-test": "^0.3.1",
"c8": "^8.0.1",
"check-dts": "^0.7.2",
"clean-publish": "^4.2.0",
Expand All @@ -51,8 +52,7 @@
"eslint-plugin-promise": "^6.1.1",
"size-limit": "^11.0.0",
"tsm": "^2.3.0",
"typescript": "^5.3.2",
"uvu": "^0.5.6"
"typescript": "^5.3.2"
},
"size-limit": [
{
Expand Down
63 changes: 22 additions & 41 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 11 additions & 13 deletions test/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { test } from 'uvu'
import { equal, not } from 'uvu/assert'
import { deepStrictEqual, doesNotThrow, equal } from 'node:assert'
import { test } from 'node:test'

import { createNanoEvents } from '../index.js'

test('is empty from the beginning', () => {
let ee = createNanoEvents()
equal(ee.events, {})
deepStrictEqual(ee.events, {})
})

test('adds listeners', () => {
Expand All @@ -15,7 +15,7 @@ test('adds listeners', () => {
ee.on('two', () => true)
ee.on('two', () => true)

equal(Object.keys(ee.events), ['one', 'two'])
deepStrictEqual(Object.keys(ee.events), ['one', 'two'])
equal(ee.events.one?.length, 1)
equal(ee.events.two?.length, 2)
})
Expand All @@ -33,7 +33,7 @@ test('calls listener', () => {
ee.emit('event', 31, 32, 33)
ee.emit('event', 41, 42, 43, 44)

equal(calls, [[], [11], [21, 22], [31, 32, 33], [41, 42, 43, 44]])
deepStrictEqual(calls, [[], [11], [21, 22], [31, 32, 33], [41, 42, 43, 44]])
})

test('unbinds listener', () => {
Expand All @@ -53,15 +53,15 @@ test('unbinds listener', () => {
unbind()
ee.emit('event', 2)

equal(calls1, [1])
equal(calls2, [1, 2])
deepStrictEqual(calls1, [1])
deepStrictEqual(calls2, [1, 2])
})

test('calls unbind after cleaning events', () => {
let ee = createNanoEvents()
let unbind = ee.on('event', () => undefined)
ee.events = {}
not.throws(() => {
doesNotThrow(() => {
unbind()
})
})
Expand Down Expand Up @@ -97,7 +97,7 @@ test('removes listener during event', () => {
})

ee.emit('event')
equal(calls, [1, 2])
deepStrictEqual(calls, [1, 2])
})

test('allows to use arrow function to bind a context', () => {
Expand All @@ -116,11 +116,11 @@ test('allows to use arrow function to bind a context', () => {

let unbind = ee.on('event', app.getListener())

not.throws(() => {
doesNotThrow(() => {
ee.emit('event')
})

equal(app.check, ['t', 'e', 's', 't'])
deepStrictEqual(app.check, ['t', 'e', 's', 't'])

unbind()
})
Expand All @@ -146,5 +146,3 @@ test('allows to replace listeners', () => {
ee1.emit('B')
equal(bCalls, 1)
})

test.run()

0 comments on commit bfc868c

Please sign in to comment.