Closed kitsonk closed 7 years ago
@matt-gadd pointed out that throwing in resolver callbacks does implicitly reject with the error. So all that needs to change is only resolve()
after the assertions, because resolved promises cannot be rejected:
return new Promise((resolve, reject) => {
resolver({ resource: '/test/module.js' }, () => {
assert.isTrue((<any> plugin.resolve).called);
assert.isTrue((<any> plugin.createModules).calledWith([ { context: '/test', request: './module' } ]));
resolve();
});
});
In this particular case, the try/catch
block is still necessary, since without it, the error logged to the console is a timeout error, not the test case error.
This has an outstanding approved PR that resolves this issue. We should focus on merging it.
Bug
I noticed an unhandled promise rejection somewhere in our test suite, which made me look a bit deeper. Several of our test cases are written wrong and one of them is actually failing, but because the way it is written is causing it to look like it is passing.
The unhandled promise occurs in this block of code:
First, once a promise is resolved, no other tracking by Intern occurs. Second, throws in a
Promise
callback do not automatically reject the promise. If we wanted this code to actually fail when the assertions throw, it would need to look like this:While this one appears to be the only one failing, there are several others that are written in a way they won't actually fail irrespective of the assertions succeeding or failing.
This also means that there is either a defect with the test case or the code, because if changed, you get the following error: