From 3566725948c1fdb4c27d31338ff43445f95de427 Mon Sep 17 00:00:00 2001 From: nullnyat Date: Sat, 23 Sep 2023 04:05:18 +0900 Subject: [PATCH] =?UTF-8?q?=E4=B8=8D=E8=A6=81=E3=83=95=E3=82=A1=E3=82=A4?= =?UTF-8?q?=E3=83=AB=E5=89=8A=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/__mocks__/account.ts | 7 ---- test/__mocks__/misskey.ts | 67 --------------------------------------- test/__mocks__/ws.ts | 17 ---------- test/__modules__/test.ts | 26 --------------- test/core.ts | 20 ------------ test/tsconfig.json | 15 --------- 6 files changed, 152 deletions(-) delete mode 100644 test/__mocks__/account.ts delete mode 100644 test/__mocks__/misskey.ts delete mode 100644 test/__mocks__/ws.ts delete mode 100644 test/__modules__/test.ts delete mode 100644 test/core.ts delete mode 100644 test/tsconfig.json diff --git a/test/__mocks__/account.ts b/test/__mocks__/account.ts deleted file mode 100644 index 3d53135..0000000 --- a/test/__mocks__/account.ts +++ /dev/null @@ -1,7 +0,0 @@ -export const account = { - id: '0', - name: '藍', - username: 'ai', - host: null, - isBot: true, -}; diff --git a/test/__mocks__/misskey.ts b/test/__mocks__/misskey.ts deleted file mode 100644 index de1212f..0000000 --- a/test/__mocks__/misskey.ts +++ /dev/null @@ -1,67 +0,0 @@ -import * as http from 'http'; -import * as Koa from 'koa'; -import * as websocket from 'websocket'; - -export class Misskey { - private server: http.Server; - private streaming: websocket.connection; - - constructor() { - const app = new Koa(); - - this.server = http.createServer(app.callback()); - - const ws = new websocket.server({ - httpServer: this.server - }); - - ws.on('request', async (request) => { - const q = request.resourceURL.query as ParsedUrlQuery; - - this.streaming = request.accept(); - }); - - this.server.listen(3000); - } - - public waitForStreamingMessage(handler) { - return new Promise((resolve, reject) => { - const onMessage = (data: websocket.IMessage) => { - if (data.utf8Data == null) return; - const message = JSON.parse(data.utf8Data); - const result = handler(message); - if (result) { - this.streaming.off('message', onMessage); - resolve(); - } - }; - this.streaming.on('message', onMessage); - }); - } - - public async waitForMainChannelConnected() { - await this.waitForStreamingMessage(message => { - const { type, body } = message; - if (type === 'connect') { - const { channel, id, params, pong } = body; - - if (channel !== 'main') return; - - if (pong) { - this.sendStreamingMessage('connected', { - id: id - }); - } - - return true; - } - }); - } - - public sendStreamingMessage(type: string, payload: any) { - this.streaming.send(JSON.stringify({ - type: type, - body: payload - })); - } -} diff --git a/test/__mocks__/ws.ts b/test/__mocks__/ws.ts deleted file mode 100644 index 5b31e2c..0000000 --- a/test/__mocks__/ws.ts +++ /dev/null @@ -1,17 +0,0 @@ -import * as websocket from 'websocket'; - -export class StreamingApi { - private ws: WS; - - constructor() { - this.ws = new WS('ws://localhost/streaming'); - } - - public async waitForMainChannelConnected() { - await expect(this.ws).toReceiveMessage("hello"); - } - - public send(message) { - this.ws.send(JSON.stringify(message)); - } -} diff --git a/test/__modules__/test.ts b/test/__modules__/test.ts deleted file mode 100644 index 56ef18e..0000000 --- a/test/__modules__/test.ts +++ /dev/null @@ -1,26 +0,0 @@ -import autobind from 'autobind-decorator'; -import Module from '@/module'; -import Message from '@/message'; - -export default class extends Module { - public readonly name = 'test'; - - @autobind - public install() { - return { - mentionHook: this.mentionHook - }; - } - - @autobind - private async mentionHook(msg: Message) { - if (msg.text && msg.text.includes('ping')) { - msg.reply('PONG!', { - immediate: true - }); - return true; - } else { - return false; - } - } -} diff --git a/test/core.ts b/test/core.ts deleted file mode 100644 index 721c4f3..0000000 --- a/test/core.ts +++ /dev/null @@ -1,20 +0,0 @@ -import 藍 from '@/ai'; -import { account } from '#/__mocks__/account'; -import TestModule from '#/__modules__/test'; -import { StreamingApi } from '#/__mocks__/ws'; - -process.env.NODE_ENV = 'test'; - -let ai: 藍; - -beforeEach(() => { - ai = new 藍(account, [ - new TestModule(), - ]); -}); - -test('mention hook', async () => { - const streaming = new StreamingApi(); - - -}); diff --git a/test/tsconfig.json b/test/tsconfig.json deleted file mode 100644 index 87add8f..0000000 --- a/test/tsconfig.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "extends": "../tsconfig.json", - "compilerOptions": { - "baseUrl": ".", - "rootDir": "../", - "paths": { - "@/*": ["../src/*"], - "#/*": ["./*"] - }, - }, - "compileOnSave": false, - "include": [ - "**/*.ts" - ] -}