Skip to content

Commit

Permalink
chore: add some adjustments
Browse files Browse the repository at this point in the history
  • Loading branch information
shigma committed Aug 25, 2021
1 parent d604164 commit 59cc7fd
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 53 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ jobs:
- name: Build JS
run: yarn compile
- name: Unit Test
run: yarn test:json
run: yarn test:json --mongo-ports=27017 --mysql-ports=3306,3307,3308
- name: Report Coverage
if: ${{ matrix.node-version == 14 }}
uses: codecov/codecov-action@v1
Expand Down
7 changes: 0 additions & 7 deletions packages/koishi-test-utils/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
import { Logger } from 'koishi-utils'
import { MemoryDatabase } from './memory'

export default MemoryDatabase

const logger = new Logger('test')

process.on('unhandledRejection', (error) => {
logger.warn(error)
})

export function createArray<T>(length: number, create: (index: number) => T) {
return [...new Array(length).keys()].map(create)
}
Expand Down
4 changes: 2 additions & 2 deletions packages/koishi-utils/src/misc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,6 @@ export function renameProperty<O extends object, K extends keyof O, T extends st

export type Get<T extends {}, K> = K extends keyof T ? T[K] : never
export type Extract<S, T, U = S> = S extends T ? U : never
export type MaybeArray<T> = T extends unknown[] ? T : T | T[]
export type Promisify<T> = T extends Promise<unknown> ? T : Promise<T>
export type MaybeArray<T> = [T] extends [unknown[]] ? T : T | T[]
export type Promisify<T> = [T] extends [Promise<unknown>] ? T : Promise<T>
export type Awaitable<T> = [T] extends [Promise<unknown>] ? T : T | Promise<T>
28 changes: 0 additions & 28 deletions packages/plugin-mongo/tests/database.spec.ts

This file was deleted.

18 changes: 18 additions & 0 deletions packages/plugin-mongo/tests/index.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { App, Tests } from 'koishi-test-utils'
import * as mongo from 'koishi-plugin-mongo'
import parse from 'yargs-parser'

const { mongoPorts } = parse(process.argv.slice(2), { string: ['mongo-ports'] })

for (const port of mongoPorts ? mongoPorts.split(',') : []) {
describe(`Mongo Database (${port})`, () => {
const app = new App()

app.plugin(mongo, {
host: 'localhost',
port: port,
})

Tests.database(app)
})
}
Original file line number Diff line number Diff line change
@@ -1,20 +1,10 @@
import { App, Tests } from 'koishi-test-utils'
import * as mysql from 'koishi-plugin-mysql'
import parse from 'yargs-parser'

const getMysqlPorts = () => {
const argv = process.argv.splice(3)
const match = /^--mysql-ports=(.*)/
const ports = []
for (let i = 0; i < argv.length; i++) {
const envMatch = argv[i].match(match)
envMatch && ports.push(...envMatch[1].split(',').map(port => +port))
}
return ports.length === 0 ? undefined : ports
}

const ports = getMysqlPorts() ?? [3306]
const { mysqlPorts } = parse(process.argv.slice(2), { string: ['mysql-ports'] })

for (const port of ports) {
for (const port of mysqlPorts ? mysqlPorts.split(',') : []) {
describe(`MySQL Database (${port})`, () => {
const app = new App()

Expand Down
3 changes: 1 addition & 2 deletions packages/plugin-webui/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,7 @@ export class WebServer extends Adapter {
stats: new Statistics(ctx, config),
}

ctx.all().middleware(async (session, next) => {
if (session.subtype !== 'private') return next()
ctx.all().private().middleware(async (session, next) => {
const state = this.states[session.uid]
if (state && state[0] === session.content) {
const user = await session.observeUser(['id', 'name', 'authority', 'token', 'expire'])
Expand Down

0 comments on commit 59cc7fd

Please sign in to comment.