From cf175f7b5863a192772d06ae0baccd251018fbe6 Mon Sep 17 00:00:00 2001 From: Shigma <1700011071@pku.edu.cn> Date: Sun, 26 Jan 2020 13:03:17 +0800 Subject: [PATCH] feat(test-utils): BREAKING no reply --- packages/koishi-core/tests/runtime.spec.ts | 44 +++++++++---------- packages/koishi-core/tests/suggestion.spec.ts | 20 ++++----- packages/koishi-core/tests/validation.spec.ts | 18 ++++---- packages/plugin-common/tests/exec.spec.ts | 2 +- packages/plugin-common/tests/exit.spec.ts | 4 +- packages/plugin-common/tests/help.spec.ts | 2 +- packages/plugin-common/tests/repeater.spec.ts | 14 +++--- .../plugin-common/tests/respondent.spec.ts | 2 +- packages/test-utils/src/session.ts | 2 +- 9 files changed, 54 insertions(+), 54 deletions(-) diff --git a/packages/koishi-core/tests/runtime.spec.ts b/packages/koishi-core/tests/runtime.spec.ts index ea47d50695..b3cff30751 100644 --- a/packages/koishi-core/tests/runtime.spec.ts +++ b/packages/koishi-core/tests/runtime.spec.ts @@ -38,10 +38,10 @@ describe('command prefix', () => { await session1.shouldHaveReply('foo bar', 'foobar') await session2.shouldHaveReply('foo bar', 'foobar') - await session1.shouldHaveNoResponse('!foo bar') - await session2.shouldHaveNoResponse('!foo bar') - await session1.shouldHaveNoResponse('.foo bar') - await session2.shouldHaveNoResponse('.foo bar') + await session1.shouldHaveNoReply('!foo bar') + await session2.shouldHaveNoReply('!foo bar') + await session1.shouldHaveNoReply('.foo bar') + await session2.shouldHaveNoReply('.foo bar') }) test('single prefix', async () => { @@ -49,11 +49,11 @@ describe('command prefix', () => { app.prepare() await session1.shouldHaveReply('foo bar', 'foobar') - await session2.shouldHaveNoResponse('foo bar') + await session2.shouldHaveNoReply('foo bar') await session1.shouldHaveReply('!foo bar', 'foobar') await session2.shouldHaveReply('!foo bar', 'foobar') - await session1.shouldHaveNoResponse('.foo bar') - await session2.shouldHaveNoResponse('.foo bar') + await session1.shouldHaveNoReply('.foo bar') + await session2.shouldHaveNoReply('.foo bar') }) test('multiple prefixes', async () => { @@ -61,7 +61,7 @@ describe('command prefix', () => { app.prepare() await session1.shouldHaveReply('foo bar', 'foobar') - await session2.shouldHaveNoResponse('foo bar') + await session2.shouldHaveNoReply('foo bar') await session1.shouldHaveReply('!foo bar', 'foobar') await session2.shouldHaveReply('!foo bar', 'foobar') await session1.shouldHaveReply('.foo bar', 'foobar') @@ -74,8 +74,8 @@ describe('command prefix', () => { await session1.shouldHaveReply('foo bar', 'foobar') await session2.shouldHaveReply('foo bar', 'foobar') - await session1.shouldHaveNoResponse('!foo bar') - await session2.shouldHaveNoResponse('!foo bar') + await session1.shouldHaveNoReply('!foo bar') + await session2.shouldHaveNoReply('!foo bar') await session1.shouldHaveReply('.foo bar', 'foobar') await session2.shouldHaveReply('.foo bar', 'foobar') }) @@ -96,7 +96,7 @@ describe('nickname prefix', () => { test('no nickname', async () => { await session1.shouldHaveReply('foo bar', 'foobar') - await session2.shouldHaveNoResponse('foo bar') + await session2.shouldHaveNoReply('foo bar') await session1.shouldHaveReply('-foo bar', 'foobar') await session2.shouldHaveReply('-foo bar', 'foobar') await session2.shouldHaveReply(`[CQ:at,qq=${app.selfId}] foo bar`, 'foobar') @@ -112,8 +112,8 @@ describe('nickname prefix', () => { await session2.shouldHaveReply('koishi\n foo bar', 'foobar') await session1.shouldHaveReply('@koishi foo bar', 'foobar') await session2.shouldHaveReply('@koishi foo bar', 'foobar') - await session1.shouldHaveNoResponse('komeiji, foo bar') - await session2.shouldHaveNoResponse('komeiji, foo bar') + await session1.shouldHaveNoReply('komeiji, foo bar') + await session2.shouldHaveNoReply('komeiji, foo bar') }) test('multiple nicknames', async () => { @@ -121,7 +121,7 @@ describe('nickname prefix', () => { app.prepare() await session1.shouldHaveReply('foo bar', 'foobar') - await session2.shouldHaveNoResponse('foo bar') + await session2.shouldHaveNoReply('foo bar') await session1.shouldHaveReply('-foo bar', 'foobar') await session2.shouldHaveReply('-foo bar', 'foobar') await session1.shouldHaveReply('koishi, foo bar', 'foobar') @@ -218,25 +218,25 @@ describe('shortcuts', () => { test('single shortcut', async () => { await session2.shouldHaveReply(' bar1 ', 'foobar') await session2.shouldHaveReply(' bar2 ', 'fooobar') - await session2.shouldHaveNoResponse('bar1 bar') - await session2.shouldHaveNoResponse('bar2 -t bar') + await session2.shouldHaveNoReply('bar1 bar') + await session2.shouldHaveNoReply('bar2 -t bar') }) test('no command prefix', async () => { - await session2.shouldHaveNoResponse('#bar1') - await session2.shouldHaveNoResponse('#bar2') - await session2.shouldHaveNoResponse('#bar3') - await session2.shouldHaveNoResponse('#baz') + await session2.shouldHaveNoReply('#bar1') + await session2.shouldHaveNoReply('#bar2') + await session2.shouldHaveNoReply('#bar3') + await session2.shouldHaveNoReply('#baz') }) test('nickname prefix & fuzzy', async () => { - await session2.shouldHaveNoResponse('bar3 -t baz') + await session2.shouldHaveNoReply('bar3 -t baz') await session2.shouldHaveReply(`[CQ:at,qq=${app.selfId}] bar3 -t baz`, 'fooobaz') }) test('one argument & fuzzy', async () => { await session2.shouldHaveReply('bar4 bar baz', 'foobar baz') - await session2.shouldHaveNoResponse('bar4bar baz') + await session2.shouldHaveNoReply('bar4bar baz') await session2.shouldHaveReply(`[CQ:at,qq=${app.selfId}] bar4bar baz`, 'foobar baz') }) }) diff --git a/packages/koishi-core/tests/suggestion.spec.ts b/packages/koishi-core/tests/suggestion.spec.ts index c13d2235a1..d71ad9bb1f 100644 --- a/packages/koishi-core/tests/suggestion.spec.ts +++ b/packages/koishi-core/tests/suggestion.spec.ts @@ -33,37 +33,37 @@ describe('Command Suggestions', () => { test('execute command', async () => { await session1.shouldHaveReply('foo bar', 'foobar') - await session1.shouldHaveNoResponse(' ') + await session1.shouldHaveNoReply(' ') }) test('no suggestions found', async () => { - await session1.shouldHaveNoResponse('bar foo') + await session1.shouldHaveNoReply('bar foo') }) test('apply suggestions 1', async () => { await session1.shouldHaveReply('fo bar', expectedSuggestionText) await session2.shouldHaveReply('fooo -t bar') await session1.shouldHaveReply(' ', 'foobar') - await session1.shouldHaveNoResponse(' ') + await session1.shouldHaveNoReply(' ') }) test('apply suggestions 2', async () => { await session2.shouldHaveReply('foooo -t bar', expectedSuggestionText2) await session1.shouldHaveReply('foo bar') await session2.shouldHaveReply(' ', 'fooobar') - await session2.shouldHaveNoResponse(' ') + await session2.shouldHaveNoReply(' ') }) test('ignore suggestions 1', async () => { await session1.shouldHaveReply('fo bar', expectedSuggestionText) - await session1.shouldHaveNoResponse('bar foo') - await session1.shouldHaveNoResponse(' ') + await session1.shouldHaveNoReply('bar foo') + await session1.shouldHaveNoReply(' ') }) test('ignore suggestions 2', async () => { await session2.shouldHaveReply('fo bar', expectedSuggestionText) await session2.shouldHaveReply('foo bar') - await session2.shouldHaveNoResponse(' ') + await session2.shouldHaveNoReply(' ') }) test('multiple suggestions', async () => { @@ -71,7 +71,7 @@ describe('Command Suggestions', () => { messages.COMMAND_SUGGESTION_PREFIX, format(messages.SUGGESTION_TEXT, '“foo”或“fooo”'), ].join('')) - await session1.shouldHaveNoResponse(' ') + await session1.shouldHaveNoReply(' ') }) }) @@ -98,7 +98,7 @@ describe('Custom Suggestions with Arguments', () => { }) test('show suggestions', async () => { - await session.shouldHaveNoResponse(' ') + await session.shouldHaveNoReply(' ') await session.shouldHaveReply('for', `prefix${format(messages.SUGGESTION_TEXT, '“foo”')}suffix`) await session.shouldHaveReply(' ', 'text:foo') }) @@ -128,7 +128,7 @@ describe('Custom Suggestions with Options', () => { }) test('show suggestions', async () => { - await session.shouldHaveNoResponse(' ') + await session.shouldHaveNoReply(' ') await session.shouldHaveReply('for', `prefix${format(messages.SUGGESTION_TEXT, '“foo”')}suffix`) await session.shouldHaveReply(' ', 'text:foo') }) diff --git a/packages/koishi-core/tests/validation.spec.ts b/packages/koishi-core/tests/validation.spec.ts index 46e5066122..4d868a5874 100644 --- a/packages/koishi-core/tests/validation.spec.ts +++ b/packages/koishi-core/tests/validation.spec.ts @@ -41,28 +41,28 @@ afterAll(() => app.stop()) describe('middleware validation', () => { test('user.flag.ignore', async () => { await session1.shouldHaveReply('cmd2', 'cmd2:123') - await session3.shouldHaveNoResponse('cmd2') + await session3.shouldHaveNoReply('cmd2') }) test('group.assignee', async () => { await session4.shouldHaveReply('cmd1 --baz', 'cmd1:123') await session4.shouldHaveReply('mid', 'mid') - await session5.shouldHaveNoResponse('cmd1 --baz') + await session5.shouldHaveNoReply('cmd1 --baz') await session5.shouldHaveReply(`[CQ:at,qq=${app.selfId}] cmd1 --baz`, 'cmd1:123') }) test('group.flag.noCommand', async () => { await app.database.setGroup(321, { flag: GroupFlag.noCommand }) await session4.shouldHaveReply('mid', 'mid') - await session4.shouldHaveNoResponse('cmd1 --baz') - await session4.shouldHaveNoResponse(`[CQ:at,qq=${app.selfId}] cmd1 --baz`) + await session4.shouldHaveNoReply('cmd1 --baz') + await session4.shouldHaveNoReply(`[CQ:at,qq=${app.selfId}] cmd1 --baz`) await app.database.setGroup(321, { flag: 0 }) }) test('group.flag.noResponse', async () => { await app.database.setGroup(321, { flag: GroupFlag.noResponse }) - await session4.shouldHaveNoResponse('mid') - await session4.shouldHaveNoResponse('cmd1 --baz') + await session4.shouldHaveNoReply('mid') + await session4.shouldHaveNoReply('cmd1 --baz') await session4.shouldHaveReply(`[CQ:at,qq=${app.selfId}] cmd1 --baz`, 'cmd1:123') await app.database.setGroup(321, { flag: 0 }) }) @@ -74,7 +74,7 @@ describe('command validation', () => { await session2.shouldHaveReply('cmd1', messages.LOW_AUTHORITY) await session1.shouldHaveReply('cmd1 --bar', messages.LOW_AUTHORITY) app.command('cmd1', { showWarning: false }) - await session1.shouldHaveNoResponse('cmd1 --bar') + await session1.shouldHaveNoReply('cmd1 --bar') }) test('check usage', async () => { @@ -84,7 +84,7 @@ describe('command validation', () => { await session1.shouldHaveReply('cmd1', messages.USAGE_EXHAUSTED) await session1.shouldHaveReply('cmd1 --baz', 'cmd1:123') app.command('cmd1', { showWarning: false }) - await session1.shouldHaveNoResponse('cmd1') + await session1.shouldHaveNoReply('cmd1') }) test('check frequency', async () => { @@ -92,6 +92,6 @@ describe('command validation', () => { await session2.shouldHaveReply('cmd2', 'cmd2:456') await session2.shouldHaveReply('cmd2', messages.TOO_FREQUENT) app.command('cmd2', { showWarning: false }) - await session2.shouldHaveNoResponse('cmd2') + await session2.shouldHaveNoReply('cmd2') }) }) diff --git a/packages/plugin-common/tests/exec.spec.ts b/packages/plugin-common/tests/exec.spec.ts index a17ed9d0c9..2690924203 100644 --- a/packages/plugin-common/tests/exec.spec.ts +++ b/packages/plugin-common/tests/exec.spec.ts @@ -7,7 +7,7 @@ const session = app.createSession('user', 123) app.plugin(exec) test('no input', async () => { - await session.shouldHaveNoResponse('$') + await session.shouldHaveNoReply('$') }) test('stdout', async () => { diff --git a/packages/plugin-common/tests/exit.spec.ts b/packages/plugin-common/tests/exit.spec.ts index a052042204..5c170f295c 100644 --- a/packages/plugin-common/tests/exit.spec.ts +++ b/packages/plugin-common/tests/exit.spec.ts @@ -13,13 +13,13 @@ beforeEach(() => mock.mockClear()) afterAll(() => process.exit = processExit) test('terminate', async () => { - await session.shouldHaveNoResponse(`koishi, 关机`) + await session.shouldHaveNoReply(`koishi, 关机`) expect(mock).toBeCalledTimes(1) expect(mock).toBeCalledWith(0) }) test('restart', async () => { - await session.shouldHaveNoResponse(`koishi, 重启`) + await session.shouldHaveNoReply(`koishi, 重启`) expect(mock).toBeCalledTimes(1) expect(mock).toBeCalledWith(-1) }) diff --git a/packages/plugin-common/tests/help.spec.ts b/packages/plugin-common/tests/help.spec.ts index 46b3241586..225260860c 100644 --- a/packages/plugin-common/tests/help.spec.ts +++ b/packages/plugin-common/tests/help.spec.ts @@ -42,7 +42,7 @@ describe('help command', () => { await session1.shouldMatchSnapshot('bar -h') await session1.shouldMatchSnapshot('foo -h') await session1.shouldMatchSnapshot('help help -e') - await session2.shouldHaveNoResponse('help.foo -h') + await session2.shouldHaveNoReply('help.foo -h') await session2.shouldMatchSnapshot('help help.foo') }) diff --git a/packages/plugin-common/tests/repeater.spec.ts b/packages/plugin-common/tests/repeater.spec.ts index 8529f15730..b415e621ba 100644 --- a/packages/plugin-common/tests/repeater.spec.ts +++ b/packages/plugin-common/tests/repeater.spec.ts @@ -13,10 +13,10 @@ test('repeat', async () => { interruptCheck: false, }) - await session1.shouldHaveNoResponse('foo') + await session1.shouldHaveNoReply('foo') await session1.shouldHaveReply('foo', 'foo') - await session1.shouldHaveNoResponse('foo') - await session1.shouldHaveNoResponse('foo') + await session1.shouldHaveNoReply('foo') + await session1.shouldHaveNoReply('foo') }) test('interrupt', async () => { @@ -30,7 +30,7 @@ test('interrupt', async () => { interruptCheck: false, }) - await session1.shouldHaveNoResponse('foo') + await session1.shouldHaveNoReply('foo') await session1.shouldHaveReply('foo', 'foo') await session1.shouldHaveReply('foo', '打断复读!') }) @@ -47,7 +47,7 @@ test('repeat check', async () => { interruptCheck: false, }) - await session1.shouldHaveNoResponse('foo') + await session1.shouldHaveNoReply('foo') await session1.shouldHaveReply('foo', 'foo') await session2.shouldHaveReply('foo', 'foo') await session2.shouldHaveReply('foo', `[CQ:at,qq=${session2.userId}] 在?为什么重复复读?`) @@ -64,8 +64,8 @@ test('interrupt check', async () => { interruptCheck: (_, times) => times >= 2, }) - await session1.shouldHaveNoResponse('foo') - await session1.shouldHaveNoResponse('bar') + await session1.shouldHaveNoReply('foo') + await session1.shouldHaveNoReply('bar') await session1.shouldHaveReply('bar', 'bar') await session1.shouldHaveReply('foo', `[CQ:at,qq=${session1.userId}] 在?为什么打断复读?`) }) diff --git a/packages/plugin-common/tests/respondent.spec.ts b/packages/plugin-common/tests/respondent.spec.ts index dc6536263c..d848cd2a96 100644 --- a/packages/plugin-common/tests/respondent.spec.ts +++ b/packages/plugin-common/tests/respondent.spec.ts @@ -17,5 +17,5 @@ app.plugin(respondent, [{ test('basic support', async () => { await session.shouldHaveReply('挖坑一时爽', '填坑火葬场') await session.shouldHaveReply('填坑一时爽', '一直填坑一直爽') - await session.shouldHaveNoResponse('填坑一直爽') + await session.shouldHaveNoReply('填坑一直爽') }) diff --git a/packages/test-utils/src/session.ts b/packages/test-utils/src/session.ts index e4f421da03..07356be22e 100644 --- a/packages/test-utils/src/session.ts +++ b/packages/test-utils/src/session.ts @@ -35,7 +35,7 @@ export class Session { } } - shouldHaveNoReplies (message: string) { + shouldHaveNoReply (message: string) { return expect(this.send(message)).resolves.toHaveLength(0) }