Skip to content

Commit

Permalink
chore: fix unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
shigma committed Mar 31, 2021
1 parent ca3aea4 commit cb8980e
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 18 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
"@types/chai": "^4.2.15",
"@types/chai-as-promised": "^7.1.3",
"@types/cross-spawn": "^6.0.2",
"@types/estree": "^0.0.47",
"@types/fs-extra": "^9.0.9",
"@types/mocha": "^8.2.2",
"@types/node": "^14.14.37",
Expand Down
2 changes: 1 addition & 1 deletion packages/koishi-core/tests/context.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ describe('Context API', () => {
expect(inspect(app)).to.equal('Context <root>')

app.plugin(function foo(ctx) {
expect(inspect(ctx)).to.equal('Context <unknown>')
expect(inspect(ctx)).to.equal('Context <anonymous>')
})

app.plugin({
Expand Down
16 changes: 1 addition & 15 deletions packages/plugin-teach/tests/environment.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Database, Context, Assets } from 'koishi-core'
import { Database, Context } from 'koishi-core'
import { defineProperty, Observed, clone, intersection } from 'koishi-utils'
import { Dialogue, DialogueTest, equal, Config, apply } from 'koishi-plugin-teach'
import { App } from 'koishi-test-utils'
Expand Down Expand Up @@ -106,27 +106,13 @@ function getProduct({ startTime, endTime }: Dialogue, time: number) {
return (startTime - time) * (time - endTime) * (endTime - startTime)
}

class MockAssets implements Assets {
types = ['image'] as const

async upload(url: string) {
return url
}

async stats() {
return {}
}
}

export default function (config: Config) {
const app = new App({
userCacheAge: Number.EPSILON,
nickname: ['koishi', 'satori'],
mockDatabase: true,
})

app.assets = new MockAssets()

const u2id = '200', u3id = '300', u4id = '400'
const g1id = '100', g2id = '200'
const u2 = app.session(u2id)
Expand Down
10 changes: 8 additions & 2 deletions packages/plugin-teach/tests/misc.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { App } from 'koishi-test-utils'
import { Logger, Time } from 'koishi-utils'
import { Assets, Logger, Time } from 'koishi-core'
import createEnvironment from './environment'
import { install } from '@sinonjs/fake-timers'
import * as teach from 'koishi-plugin-teach'
Expand Down Expand Up @@ -43,7 +43,13 @@ describe('Teach Plugin - Miscellaneous', () => {
describe('Assets', () => {
const logger = new Logger('teach')
const { app, u3g1 } = createEnvironment({})
const upload = jest.spyOn(app.assets, 'upload')
const upload = jest.fn(async (url: string) => url)

app.assets = new class MockAssets implements Assets {
types = ['image'] as const
stats = async () => ({})
upload = upload
}()

it('upload succeed', async () => {
upload.mockResolvedValue('https://127.0.0.1/image/baz')
Expand Down

0 comments on commit cb8980e

Please sign in to comment.