如何在Mocha Reporter中获取文件的文件名
-
21-12-2019 - |
题
有没有办法获得Mocha Reporter的当前测试的文件名?
我在基地和例子中找不到任何东西。
解决方案
实际上,从这个拉请求。它刚刚摩卡最常见的是作为业力插件(即, Karma-Mocha 插件),并谈谈12月14日,此插件不会进一步通过文件名信息。
要使这个答案自我一致,这里是套房在摩卡(它是TDD实现,而且它类似于BDD):
context.suite = function(title, fn){
var suite = Suite.create(suites[0], title);
suite.file = file;
suites.unshift(suite);
fn.call(suite);
suites.shift();
return suite;
};
.
以及以下是如何在Karma-Mocha / lib / Adapter.js中形成的套装:
runner.on('test end', function(test) {
var skipped = test.pending === true;
var result = {
id: '',
description: test.title,
suite: [],
success: test.state === 'passed',
skipped: skipped,
time: skipped ? 0 : test.duration,
log: test.$errors || []
};
var pointer = test.parent;
while (!pointer.root) {
result.suite.unshift(pointer.title);
pointer = pointer.parent;
}
tc.result(result);
});
.
但是你知道什么,我猜这是在商业摩卡项目中作为一个特征要求发行的好事。
不隶属于 StackOverflow