storage-upload/test/helper.server.mjs

81 lines
1.4 KiB
JavaScript
Raw Normal View History

import { stub } from 'eltro'
2022-08-13 21:52:45 +00:00
import { ServiceCore } from 'service-core'
import Client from './helper.client.mjs'
import defaults from '../api/defaults.mjs'
2022-08-13 21:52:45 +00:00
import * as index from '../index.mjs'
2022-08-13 21:52:45 +00:00
export const port = 5030
export const log = {
log: stub(),
warn: stub(),
info: stub(),
error: stub(),
child: stub(),
2022-08-13 21:52:45 +00:00
event: {
warn: stub(),
info: stub(),
error: stub(),
}
}
2022-08-13 21:52:45 +00:00
log.child.returns(log)
let serverRunning = false
export function startServer() {
if (serverRunning) return Promise.resolve()
serverRunning = true
2022-08-13 21:52:45 +00:00
var core = new ServiceCore('storage-upload', import.meta.url, port, '')
core.setConfig({
"port": port,
"sites": {
"development": {
"keys": {
"default@HS256": "asdf1234"
}
},
"existing": {
"public": true,
"keys": {
"default@HS256": "asdf1234"
}
}
},
})
core.log = log
return core.init(index).then(function() {
return core.run()
})
}
2017-12-09 21:51:18 +00:00
export function createClient() {
2022-08-13 21:52:45 +00:00
return new Client(port)
}
2017-12-10 09:45:38 +00:00
export function resetLog() {
2022-08-13 21:52:45 +00:00
log.log.reset()
log.info.reset()
log.warn.reset()
log.error.reset()
}
2017-12-10 09:45:38 +00:00
export function createContext(opts) {
return defaults(opts, {
query: new Map(),
params: { },
2017-12-10 09:45:38 +00:00
req: { },
res: { },
state: {},
log: {
log: stub(),
warn: stub(),
info: stub(),
error: stub(),
},
2017-12-10 09:45:38 +00:00
})
}