添加单元测试
Some checks failed
continuous-integration/drone/push Build is failing
continuous-integration/drone Build is failing

This commit is contained in:
Qumolama.d
2022-05-05 15:36:10 +08:00
parent bd8b866f07
commit 24342022dd
3 changed files with 298 additions and 24 deletions

View File

@ -5,30 +5,17 @@ import * as Hooks from './hooks.js'
import * as AuthenticateRoutings from './routes/authenticate.js'
import { config } from './config.js'
console.log(`
================================================================
__ _____ ______ __ __ _ __
/ / / ___// __ \\ \\/ /___ _____ _____/ /________ ______(_) /
/ / \\__ \\/ /_/ /\\ / __ \`/ __ \`/ __ / ___/ __ \`/ ___/ / /
/ /______/ / ____/ / / /_/ / /_/ / /_/ / / / /_/ (__ ) / /
/_____/____/_/ /_/\\__, /\\__, /\\__,_/_/ \\__,_/____/_/_/
/____//____/
================================================================\n`)
if(typeof PROGRAM_PRODUCTION === 'undefined') {
console.warn("⚠ 警告: 您运行的不是正式版本,可能会不稳定,仅限开发环境运行!\n")
}
export const server = fastify({
logger: {
prettyPrint: true
prettyPrint: true,
level: 'error'
}
})
//export const logger = server.log
;(async () => {
export const setup = async () => {
const mongooseClient = await mongoose.connect(config.database.url)
const models = registerModels(mongooseClient)
@ -64,14 +51,39 @@ export const server = fastify({
permissions: [{ node: 'login', allowed: true, duration: 0, eternal: true, startDate: Date.now(), highPriority: false }]
}).save()
*/
}
if(!process.env["UNIT_TEST"]) {
await launch(config)
}
})()
const launch = async (config) => {
const launch = async () => {
process.on('SIGINT', () => {
new Promise(shutdown)
})
await server.listen(config.server.port, config.server.url)
server.log.info("老色批世界树 > 基于 fastify 的高性能 HTTP 服务器已启动")
}
}
export const shutdown = async () => {
server.close()
mongoose.disconnect()
}
(async () => {
if(!process.env["UNIT_TEST"]) {
console.log(`
================================================================
__ _____ ______ __ __ _ __
/ / / ___// __ \\ \\/ /___ _____ _____/ /________ ______(_) /
/ / \\__ \\/ /_/ /\\ / __ \`/ __ \`/ __ / ___/ __ \`/ ___/ / /
/ /______/ / ____/ / / /_/ / /_/ / /_/ / / / /_/ (__ ) / /
/_____/____/_/ /_/\\__, /\\__, /\\__,_/_/ \\__,_/____/_/_/
/____//____/
================================================================\n`)
if(typeof PROGRAM_PRODUCTION === 'undefined') {
console.warn("⚠ 警告: 您运行的不是正式版本,可能会不稳定,仅限开发环境运行!\n")
}
await setup()
await launch()
}
})