栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

开始摩卡咖啡并行描述

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

开始摩卡咖啡并行描述

您无法直接使用mocha进行此操作,因为它会创建it()回调的列表并按顺序调用它们。 如果您愿意将自己的描述移到单独的.js文件中,mocha-
parallel-tests
可以执行此操作。为了说服自己,请将其安装在某个地方,然后用–low缓慢调用它,以便每次都报告:

laptop:/tmp/delme$ npm install mocha-parallel-testslaptop:/tmp/delme$ cd node_modules/mocha-parallel-testslaptop:/tmp/delme/node_modules/mocha-parallel-tests$ ./bin/mocha-parallel-tests test/parallel/tests --timeout 10000 --slow 100

您将看到它运行了最长的时间运行了三个(非常简单)的测试套件。

如果您的测试不依赖于早期测试的副作用,则可以使它们全部异步。一种简单的方法是在描述之前启动需要一段时间的东西,然后使用常规的摩卡咖啡设备对其进行评估。在这里,我创建了一堆承诺,需要一段时间才能解决,然后再次遍历测试,并在.then()函数中检查其结果:

var expect = require("chai").expect;var SlowTests = [  { name: "a" , time: 250 },  { name: "b" , time: 500 },  { name: "c" , time: 750 },  { name: "d" , time:1000 },  { name: "e" , time:1250 },  { name: "f" , time:1500 }];SlowTests.forEach(function (test) {  test.promise = takeAWhile(test.time);});describe("SlowTests", function () {  // mocha defaults to 2s timeout. change to 5s with: this.timeout(5000);  SlowTests.forEach(function (test) {    it("should pass '" + test.name + "' in around "+ test.time +" mseconds.",       function (done) {         test.promise.then(function (res) {expect(res).to.be.equal(test.time);done();         }).catch(function (err) {done(err);         });       });  });});function takeAWhile (time) {  return new Promise(function (resolve, reject) {    setTimeout(function () {      resolve(time);    }, time);  });}

(将其另存为

foo.js
并使用调用
mocha foo.js
。)

meta
我不同意测试应该主要是同步的说法。编译前后比较容易,但是很少有一项测试会使所有其余测试无效。所有不鼓励异步测试的做法都是不鼓励对网络任务进行广泛的测试。



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/484855.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号