同步运行mocha测试 [英] Running mocha tests synchronously

查看:23
本文介绍了同步运行mocha测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下用于运行"it"测试的设置:

X is environment variable
if( X == "all" || X == "some value" )
   read directory and run test using it() with callbacks

if( X == "all" || X  == "some other value")
   read directory and run some it() tests with callback

我面临的问题是,当我给出"一些值"或"其他值"时,所有it()测试都运行得很好。但是当环境变量为"all"时,在运行第一个it()测试时,会出现第二个if语句的目录内容。我使用fs.readdirSync(Dir)读取内容,我知道mochat est异步运行它们,因此,第二个目录的内容出现在第一个测试中。是否可以挡路第二个if语句的执行,直到第一个if中的所有it()测试都成功完成?或任何使其同步运行的替代方案。

推荐答案

最好的方法是使用mocha-testdata异步npm模块,并向其传递一个文件数组,该数组修复了上述所有问题,并且所有测试用例运行良好,没有任何问题: 类似于

testData = require('mocha-testdata');
testData.async("array of files").test('#testing' , function(done, file) {
});

另外,请使用mocha Suite()而不是it(),Describe()调用。

suite('test:', function() {
testData.async("files array").test('#testing' , function(done, file) {
    // Code that works on the list of files
    });
});

这篇关于同步运行mocha测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆