对所有testing运行ava test.before()一次
我想用test.before()
来引导我的testing。 我试过的设置不起作用:
// bootstrap.js const test = require('ava') test.before(t => { // do this exactly once for all tests }) module.exports = { test } // test1.js const { test } = require('../bootstrap') test(t => { ... {)
AVA将在每个testing文件之前运行before()
函数。 我可以before
通话before
做一个检查,看看是否被调用,但我想找一个更清洁的过程。 我已经尝试使用require
参数:
"ava": { "require": [ "./test/run.js" ] }
附:
// bootstrap,js const test = require('ava') module.exports = { test } // run.js const { test } = require('./bootstrap') test.before(t => { }) // test1.js const { test } = require('../bootstrap') test(t => { ... {)
但是这只是打破了worker.setRunner is not a function
。 不知道它期望什么。
AVA在自己的过程中运行每个testing文件。 应该使用test.before()
来设置被调用的进程使用的灯具。
这听起来像你想要做的设置,在你的testing文件/进程中重用。 理想情况是这样可以避免,因为你最终可能会在执行不同的testing之间创build难以检测的依赖关系。
不过,如果这是你所需要的,那么我build议使用一个pretest
npm脚本,当你做npm test
时它会自动npm test
。