Wrap tests in domain instead of try/catch
- 主要语言
- JavaScript
- 星标
- 1.9k
- 派生
- 359
- PR 合并指标
- 30 天内没有已合并 PR
描述
In several cases, async errors with nodeunit and streams2 only result in the test giving a "test not run or test.done not called". without any sign of the error. What I ended up doing is something like this
``` javascript
Function.prototype.withDomain = function(withStack) {
var fn = this;
return function(test) {
var d = domain.create();
d.on('error', function(e) {
test.fail('test failed with ' + e.message);
if(withStack) {
console.error(e.stack)
}
test.done();
});
d.run(fn.bind(this, test));
}
}
exports['my test'] = function (test) {
setTimeout(function() {
throw new Error('Throwing an error asynchronously');
test.done()
});
}.withDomain()
```
I just thought this was useful enough to be the default.
贡献指南
这个仓库没有索引到贡献指南
调研方向
The issue provides a Function.prototype.withDomain example and identifies nodeunit tests with streams2 as the affected area. Start by reading nodeunit's asynchronous test execution and error-handling path, then run the existing test suite with an asynchronous stream error. Done means those errors fail the relevant test with a useful message instead of reporting only that test.done was not called.
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- javascript, node.js
- 领域
- testing
- Issue 类型
- 功能
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 28/100