mocha 如何延迟指定时间后再运行所有用例
mocha 如何延迟指定时间后再运行所有用例
/**
这是一个基于 mocha 的测试脚本,
想实现一个先延迟一定的时候(等待某个用户启动完成之后), 再运行所有用例.
但是只要添加 `await sleep(3000)` 这个功能后就不会运行用例了.
我看 mocha 文档上是支持 async await 的
- [mocha 文档](https://mochajs.cn/)
*/
function sleep(time = 1000) {
return new Promise((res, rej) => setTimeout(res, time))
}
const assert = require('assert')
describe('基本功能', async () => {
console.log(`启动中...`)
await sleep(3000)
console.log(`启动完成...`)
describe('显示版本号', () => {
it(`获取版本号`, () => {
assert.ok(true)
})
})
describe('服务启动', () => {
it(`port`, () => {
assert.ok(true)
})
})
})