Skip to content

Commit e9adffc

Browse files
committed
add tests for async stack frames: async, Promise.all, Promise.any
1 parent 6d3de7e commit e9adffc

File tree

1 file changed

+39
-5
lines changed

1 file changed

+39
-5
lines changed

test.js

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -461,14 +461,48 @@ it('function constructor', async function() {
461461
]);
462462
});
463463

464-
it('async stack frames', async function() {
464+
it('Verify node does not support Promise.allSettled stack frames. When this test starts breaking, we need to start testing for Promise.allSettled.', async () => {
465+
// results1/driver1 is not strictly necessary to test allSettled; it is here to remind myself how to correctly get Promise.* methods to appear in a stack trace.
466+
let result1;
467+
await driver1().catch(e => result1 = e);
468+
assert.match(result1.stack, /\bPromise\.all\b/);
469+
470+
// Copied from V8 tests: https://github.com/v8/v8/commit/89ed081c176e286f9d65f3821d43f568cd56a035#diff-1a0a032688d7546dcfe5730eaab2854fb1b8dab656d8bb940dffc71b7b975aae
471+
async function fine() { }
472+
async function thrower() {
473+
await fine();
474+
throw new Error();
475+
}
476+
async function driver1() {
477+
return await Promise.all([fine(), fine(), thrower(), thrower()]);
478+
}
479+
async function driver2() {
480+
return await Promise.allSettled([fine(), fine(), thrower(), thrower()]);
481+
}
482+
483+
const results2 = await driver2();
484+
assert.equal(results2[2].status, 'rejected');
485+
assert.doesNotMatch(results2[2].reason.stack, /\bPromise\.allSettled\b/);
486+
});
487+
488+
it('async stack frames: async, Promise.all, Promise.any'/*Promise.allSettled*/, async function() {
465489
await compareStackTrace(createMultiLineSourceMap(), [
466-
'async function foo() { await bar(); }',
467-
'async function bar() { await null; throw new Error("test"); }',
468-
'return foo()'
490+
// Add once node upgrades to v8 10.2, where this was added: https://github.com/v8/v8/commit/89ed081c176e286f9d65f3821d43f568cd56a035
491+
// 'async function foo() { return await bar(); }',
492+
// 'async function bar() { return await Promise.allSettled([baz()]) }',
493+
494+
'async function foo() { return await baz(); }',
495+
'async function baz() { await Promise.all([biff()]) }',
496+
'async function biff() { await Promise.any([larry()]); }',
497+
'async function larry() { await null; throw new Error("test"); }',
498+
'return foo().catch(e => { throw e.errors[0] })'
469499
], [
470500
'Error: test',
471-
re`^ at bar \(${stackFramePathStartsWith()}(?:.*[/\\])?line2.js:1002:102\)$`,
501+
re`^ at larry \(${stackFramePathStartsWith()}(?:.*[/\\])?line4.js:1004:104\)$`,
502+
re`^ at async Promise\.any \(index 0\)$`,
503+
re`^ at async biff \(${stackFramePathStartsWith()}(?:.*[/\\])?line3.js:1003:103\)$`,
504+
re`^ at async Promise\.all \(index 0\)$`,
505+
re`^ at async baz \(${stackFramePathStartsWith()}(?:.*[/\\])?line2.js:1002:102\)$`,
472506
re`^ at async foo \(${stackFramePathStartsWith()}(?:.*[/\\])?line1.js:1001:101\)$`
473507
]);
474508
});

0 commit comments

Comments
 (0)