Skip to content

Commit

Permalink
tests: migrate back to mocha
Browse files Browse the repository at this point in the history
  • Loading branch information
shigma committed Apr 24, 2024
1 parent 3093808 commit a3b73d1
Show file tree
Hide file tree
Showing 14 changed files with 85 additions and 86 deletions.
3 changes: 2 additions & 1 deletion package.json
Expand Up @@ -15,7 +15,7 @@
"dep": "yarn yakumo upgrade",
"pub": "yarn yakumo publish",
"lint": "eslint --cache",
"test": "yarn yakumo test --import tsx",
"test": "yarn yakumo mocha --import tsx",
"test:text": "shx rm -rf coverage && c8 -r text yarn test",
"test:json": "shx rm -rf coverage && c8 -r json yarn test",
"test:html": "shx rm -rf coverage && c8 -r html yarn test"
Expand All @@ -38,6 +38,7 @@
"typescript": "^5.3.2",
"yakumo": "^1.0.0-beta.12",
"yakumo-esbuild": "^1.0.0-beta.5",
"yakumo-mocha": "^1.0.0-beta.2",
"yakumo-tsc": "^1.0.0-beta.3",
"yml-register": "^1.2.5"
}
Expand Down
7 changes: 3 additions & 4 deletions packages/core/tests/associate.spec.ts
@@ -1,10 +1,9 @@
import { Context, Service } from '../src'
import { describe, test } from 'node:test'
import { expect } from 'chai'
import {} from './utils'

describe('Association', () => {
test('service injection', async () => {
it('service injection', async () => {
const root = new Context()

class Foo extends Service {
Expand All @@ -29,7 +28,7 @@ describe('Association', () => {
expect(root.foo.bar).to.be.undefined
})

test('property injection', async () => {
it('property injection', async () => {
const root = new Context()

class Foo extends Service {
Expand All @@ -55,7 +54,7 @@ describe('Association', () => {
expect(root.foo.baz()).to.be.instanceof(Foo)
})

test('associated type', async () => {
it('associated type', async () => {
interface Session {
bar(): this
}
Expand Down
16 changes: 8 additions & 8 deletions packages/core/tests/dispose.spec.ts
@@ -1,11 +1,11 @@
import { Context } from '../src'
import { expect } from 'chai'
import { describe, mock, test } from 'node:test'
import { mock } from 'node:test'
import { noop, remove } from 'cosmokit'
import { event, getHookSnapshot } from './utils'

describe('Disposables', () => {
test('fork.dispose', () => {
it('fork.dispose', () => {
const plugin = (ctx: Context) => {
ctx.on(event, callback)
ctx.plugin((ctx) => {
Expand Down Expand Up @@ -42,7 +42,7 @@ describe('Disposables', () => {
expect(callback.mock.calls).to.have.length(1)
})

test('memory leak test', async () => {
it('memory leak test', async () => {
function plugin(ctx: Context) {
ctx.on('ready', noop)
ctx.on(event, noop)
Expand All @@ -59,7 +59,7 @@ describe('Disposables', () => {
expect(after).to.deep.equal(getHookSnapshot(root))
})

test('dispose event', () => {
it('dispose event', () => {
const root = new Context()
const dispose = mock.fn(noop)
const plugin = (ctx: Context) => {
Expand All @@ -75,7 +75,7 @@ describe('Disposables', () => {
expect(dispose.mock.calls).to.have.length(1)
})

test('dispose event', async () => {
it('dispose event', async () => {
const root = new Context()
const error = mock.fn()
const dispose = mock.fn(() => {
Expand All @@ -95,7 +95,7 @@ describe('Disposables', () => {
expect(error.mock.calls).to.have.length(1)
})

test('root dispose', async () => {
it('root dispose', async () => {
const root = new Context()
const callback = mock.fn(noop)
const { length } = root.state.disposables
Expand All @@ -117,7 +117,7 @@ describe('Disposables', () => {
})

describe('ctx.effect()', () => {
test('manual dispose', async () => {
it('manual dispose', async () => {
const root = new Context()
const dispose = mock.fn(noop)
const items: Item[] = []
Expand Down Expand Up @@ -153,7 +153,7 @@ describe('Disposables', () => {
expect(items).to.have.length(0)
})

test('plugin dispose', () => {
it('plugin dispose', () => {
const root = new Context()
const dispose = mock.fn(noop)

Expand Down
17 changes: 8 additions & 9 deletions packages/core/tests/events.spec.ts
@@ -1,7 +1,6 @@
import { Context } from '../src'
import { expect } from 'chai'
import { describe, mock, test } from 'node:test'
import { noop } from 'cosmokit'
import { mock } from 'node:test'
import { event, Filter, Session } from './utils'

export function createArray<T>(length: number, create: (index: number) => T) {
Expand All @@ -16,7 +15,7 @@ function setup() {
}

describe('Event Listener', () => {
test('context.prototype.on', () => {
it('context.prototype.on', () => {
const { root } = setup()
const callback = mock.fn()
const dispose = root.on(event, callback)
Expand All @@ -29,7 +28,7 @@ describe('Event Listener', () => {
expect(callback.mock.calls).to.have.length(2)
})

test('context.prototype.once', () => {
it('context.prototype.once', () => {
const { root } = setup()
const callback = mock.fn()
const dispose = root.once(event, callback)
Expand All @@ -42,7 +41,7 @@ describe('Event Listener', () => {
expect(callback.mock.calls).to.have.length(1)
})

test('context.prototype.off', () => {
it('context.prototype.off', () => {
const { root } = setup()
const callback = mock.fn()
root.on(event, callback)
Expand All @@ -56,7 +55,7 @@ describe('Event Listener', () => {
})

describe('Events Emitter', () => {
test('context.prototype.parallel', async () => {
it('context.prototype.parallel', async () => {
const { root } = setup()
await root.parallel(event)
const callback = mock.fn()
Expand All @@ -75,7 +74,7 @@ describe('Events Emitter', () => {
await expect(root.parallel(event)).to.be.rejectedWith('test')
})

test('context.prototype.emit', async () => {
it('context.prototype.emit', async () => {
const { root } = setup()
root.emit(event)
const callback = mock.fn()
Expand All @@ -94,7 +93,7 @@ describe('Events Emitter', () => {
expect(() => root.emit(event)).to.throw('test')
})

test('context.prototype.serial', async () => {
it('context.prototype.serial', async () => {
const { root } = setup()
root.serial(event)
const callback = mock.fn()
Expand All @@ -113,7 +112,7 @@ describe('Events Emitter', () => {
await expect(root.serial(event)).to.be.rejectedWith('message')
})

test('context.prototype.bail', async () => {
it('context.prototype.bail', async () => {
const { root } = setup()
root.bail(event)
const callback = mock.fn()
Expand Down
3 changes: 1 addition & 2 deletions packages/core/tests/extend.spec.ts
@@ -1,9 +1,8 @@
import { expect } from 'chai'
import { describe, test } from 'node:test'
import { Context } from '../src'

describe('Extend', () => {
test('basic support', () => {
it('basic support', () => {
class S1 {}
class S2 {}
class S3 {}
Expand Down
10 changes: 5 additions & 5 deletions packages/core/tests/fork.spec.ts
@@ -1,11 +1,11 @@
import { Context } from '../src'
import { noop } from 'cosmokit'
import { expect } from 'chai'
import { describe, mock, test } from 'node:test'
import { mock } from 'node:test'
import { event, Filter, Session, filter } from './utils'

describe('Fork', () => {
test('basic support', () => {
it('basic support', () => {
const callback = mock.fn()
const reusable = (ctx: Context) => {
let foo = 0
Expand Down Expand Up @@ -57,7 +57,7 @@ describe('Fork', () => {
expect(callback.mock.calls).to.have.length(0)
})

test('shorthand syntax', () => {
it('shorthand syntax', () => {
const callback = mock.fn()
const reusable = {
reusable: true,
Expand Down Expand Up @@ -89,7 +89,7 @@ describe('Fork', () => {
expect(callback.mock.calls).to.have.length(0)
})

test('deferred execution', () => {
it('deferred execution', () => {
const root = new Context()
root.provide('foo')
const listener = mock.fn()
Expand Down Expand Up @@ -131,7 +131,7 @@ describe('Fork', () => {
expect(listener.mock.calls).to.have.length(3)
})

test('state.uid', () => {
it('state.uid', () => {
const root = new Context()
const callback1 = mock.fn()
expect(root.state.uid).to.equal(0)
Expand Down
10 changes: 5 additions & 5 deletions packages/core/tests/isolate.spec.ts
@@ -1,10 +1,10 @@
import { Context, Service } from '../src'
import { expect } from 'chai'
import { describe, mock, test } from 'node:test'
import { mock } from 'node:test'
import { event } from './utils'

describe('Isolation', () => {
test('isolated context', async () => {
it('isolated context', async () => {
const root = new Context()
root.provide('foo')
const ctx = root.isolate('foo')
Expand Down Expand Up @@ -39,7 +39,7 @@ describe('Isolation', () => {
expect(inner.mock.calls).to.have.length(2)
})

test('isolated fork', () => {
it('isolated fork', () => {
const root = new Context()
root.provide('foo')
const callback = mock.fn(() => {})
Expand Down Expand Up @@ -68,7 +68,7 @@ describe('Isolation', () => {
expect(dispose.mock.calls).to.have.length(0)
})

test('shared label', () => {
it('shared label', () => {
const root = new Context()
root.provide('foo')
const callback = mock.fn(() => {})
Expand Down Expand Up @@ -103,7 +103,7 @@ describe('Isolation', () => {
expect(dispose.mock.calls).to.have.length(4)
})

test('isolated event', async () => {
it('isolated event', async () => {
class Foo extends Service {
constructor(ctx: Context) {
super(ctx, 'foo', true)
Expand Down
16 changes: 8 additions & 8 deletions packages/core/tests/plugin.spec.ts
@@ -1,11 +1,11 @@
import { Context } from '../src'
import { expect } from 'chai'
import { describe, mock, test } from 'node:test'
import { mock } from 'node:test'
import { inspect } from 'util'
import { checkError } from './utils'

describe('Plugin', () => {
test('apply functional plugin', () => {
it('apply functional plugin', () => {
const root = new Context()
const callback = mock.fn()
const options = { foo: 'bar' }
Expand All @@ -15,7 +15,7 @@ describe('Plugin', () => {
expect(callback.mock.calls[0].arguments[1]).to.deep.equal(options)
})

test('apply object plugin', () => {
it('apply object plugin', () => {
const root = new Context()
const callback = mock.fn()
const options = { bar: 'foo' }
Expand All @@ -26,14 +26,14 @@ describe('Plugin', () => {
expect(callback.mock.calls[0].arguments[1]).to.deep.equal(options)
})

test('apply invalid plugin', () => {
it('apply invalid plugin', () => {
const root = new Context()
expect(() => root.plugin(undefined as any)).to.throw()
expect(() => root.plugin({} as any)).to.throw()
expect(() => root.plugin({ apply: {} } as any)).to.throw()
})

test('apply duplicate plugin', () => {
it('apply duplicate plugin', () => {
const root = new Context()
const callback = mock.fn()
root.plugin({ apply: callback })
Expand All @@ -42,7 +42,7 @@ describe('Plugin', () => {
expect(callback.mock.calls).to.have.length(1)
})

test('apply plugin when dispose', () => {
it('apply plugin when dispose', () => {
const root = new Context()
const callback = mock.fn()
const fork = root.plugin((ctx) => {
Expand All @@ -55,7 +55,7 @@ describe('Plugin', () => {
expect(callback.mock.calls).to.have.length(0)
})

test('context inspect', async () => {
it('context inspect', async () => {
const root = new Context()

expect(inspect(root)).to.equal('Context <root>')
Expand Down Expand Up @@ -84,7 +84,7 @@ describe('Plugin', () => {
await checkError(root)
})

test('registry', () => {
it('registry', () => {
// make coverage happy
const root = new Context()
root.registry.keys()
Expand Down

0 comments on commit a3b73d1

Please sign in to comment.