Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions lib/sandbox/pmapi-setup-runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,16 @@ module.exports = function (pm, onAssertionComplete) {
}
// if the assertion function does not expect a callback, we synchronously execute the same
else {
try { assert(); }
try {
Promise.resolve(assert())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The vast majority of tests aren't going to be async functions, and we'll likely hit a small performance penalty on running all test functions through Promise resolution. Wondering if we could do something like...

try {
  const maybePromise = assert();
  if (maybePromise instanceof Promise) {
    Promise.resolve(maybePromise)
      .catch(e => markAssertionAsFailure(assertionData, e));
  }
} catch (e) {
  markAssertionAsFailure(assertionData, e);
}

onAssertionComplete(assertionData);

Alternatively, we could also check if the function's constructor name is AsyncFunction and split logic based on that without having to execute the function first.

.catch(e => markAssertionAsFailure(assertionData, e))
.finally(() => onAssertionComplete(assertionData));
}
catch (e) {
markAssertionAsFailure(assertionData, e);
onAssertionComplete(assertionData);
}

onAssertionComplete(assertionData);
}

return pm; // make it chainable
Expand Down