forked from Binaryify/NeteaseCloudMusicApi
-
Notifications
You must be signed in to change notification settings - Fork 2
/
server.test.js
35 lines (30 loc) · 920 Bytes
/
server.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
const fs = require('fs')
const path = require('path')
const tmpPath = require('os').tmpdir()
/** @type {import("express").Express & serverMod.ExpressExtension} */
let app
if (!fs.existsSync(path.resolve(tmpPath, 'anonymous_token'))) {
fs.writeFileSync(path.resolve(tmpPath, 'anonymous_token'), '', 'utf-8')
}
const serverMod = require('./server')
before(async () => {
app = await serverMod.serveNcmApi({})
if (app.server && app.server.address) {
const addr = app.server.address()
if (addr && typeof addr === 'object' && 'port' in addr) {
global.host = `http://localhost:${addr.port}`
return
}
}
throw new Error('failed to set up host')
})
after((done) => {
if (app.server) {
app.server.close(done)
return
}
throw new Error('failed to set up server')
})
fs.readdirSync(path.join(__dirname, 'test')).forEach((file) => {
require(path.join(__dirname, 'test', file))
})