Skip to content

Commit 7fe9d36

Browse files
committed
fix: 单元测试问题修复
1 parent 2e933b3 commit 7fe9d36

File tree

3 files changed

+11
-9
lines changed

3 files changed

+11
-9
lines changed

public/qrlogin-nocookie.html

+3-3
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
let timer
3434
let timestamp = Date.now()
3535
const cookie = localStorage.getItem('cookie')
36-
this.getLoginStatus(cookie)
36+
getLoginStatus(cookie)
3737
const res = await axios({
3838
url: `/login/qr/key?timestamp=${Date.now()}`,
3939
})
@@ -44,7 +44,7 @@
4444
document.querySelector('#qrImg').src = res2.data.data.qrimg
4545

4646
timer = setInterval(async () => {
47-
const statusRes = await this.checkStatus(key)
47+
const statusRes = await checkStatus(key)
4848
if (statusRes.code === 800) {
4949
alert('二维码已过期,请重新获取')
5050
clearInterval(timer)
@@ -53,7 +53,7 @@
5353
// 这一步会返回cookie
5454
clearInterval(timer)
5555
alert('授权登录成功')
56-
await this.getLoginStatus(statusRes.cookie)
56+
await getLoginStatus(statusRes.cookie)
5757
localStorage.setItem('cookie', statusRes.cookie)
5858
}
5959
}, 3000)

public/qrlogin.html

+3-3
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
let timer
3434
let timestamp = Date.now()
3535
const cookie = localStorage.getItem('cookie')
36-
this.getLoginStatus(cookie)
36+
getLoginStatus(cookie)
3737
const res = await axios({
3838
url: `/login/qr/key?timestamp=${Date.now()}`,
3939
})
@@ -44,7 +44,7 @@
4444
document.querySelector('#qrImg').src = res2.data.data.qrimg
4545

4646
timer = setInterval(async () => {
47-
const statusRes = await this.checkStatus(key)
47+
const statusRes = await checkStatus(key)
4848
if (statusRes.code === 800) {
4949
alert('二维码已过期,请重新获取')
5050
clearInterval(timer)
@@ -53,7 +53,7 @@
5353
// 这一步会返回cookie
5454
clearInterval(timer)
5555
alert('授权登录成功')
56-
await this.getLoginStatus(statusRes.cookie)
56+
await getLoginStatus(statusRes.cookie)
5757
localStorage.setItem('cookie', statusRes.cookie)
5858
}
5959
}, 3000)

server.test.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
const fs = require('fs')
22
const path = require('path')
3-
const serverMod = require('./server')
4-
3+
const tmpPath = require('os').tmpdir()
54
/** @type {import("express").Express & serverMod.ExpressExtension} */
65
let app
7-
6+
if (!fs.existsSync(path.resolve(tmpPath, 'anonymous_token'))) {
7+
fs.writeFileSync(path.resolve(tmpPath, 'anonymous_token'), '', 'utf-8')
8+
}
9+
const serverMod = require('./server')
810
before(async () => {
911
app = await serverMod.serveNcmApi({})
1012

0 commit comments

Comments
 (0)