-
-
Notifications
You must be signed in to change notification settings - Fork 306
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Fix] preserve stack traces for returned Promises (async/await)
- Loading branch information
Showing
4 changed files
with
102 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
'use strict'; | ||
|
||
var test = require('../../'); | ||
|
||
function myCode(arr) { | ||
let sum = 0; | ||
// oops forgot to handle null | ||
for (let i = 0; i < arr.length; i++) { | ||
sum += arr[i]; | ||
} | ||
return sum; | ||
} | ||
|
||
test('async-error', async function myTest(t) { | ||
await sleep(100); | ||
t.ok(true, 'before throw'); | ||
|
||
const sum = myCode([1, 2, 3]); | ||
t.equal(sum, 6); | ||
|
||
const sum2 = myCode(null); | ||
t.equal(sum2, 0); | ||
|
||
t.end(); | ||
}); | ||
|
||
|
||
function sleep(ms) { | ||
return new Promise((resolve) => { | ||
setTimeout(resolve, ms); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters