MCPcopy Index your code
hub / github.com/nodejs/node / promise_test

Function promise_test

test/fixtures/wpt/resources/testharness.js:722–772  ·  view source on GitHub ↗

* Create a promise test. * * Promise tests are tests which are represented by a promise * object. If the promise is fulfilled the test passes, if it's * rejected the test fails, otherwise the test passes. * * @param {TestFunction} func - Test function. This must return

(func, name, properties)

Source from the content-addressed store, hash-verified

720 * given file and must be invariant between runs.
721 */
722 function promise_test(func, name, properties) {
723 if (typeof func !== "function") {
724 properties = name;
725 name = func;
726 func = null;
727 }
728 var test_name = get_test_name(func, name);
729 var test = new Test(test_name, properties);
730 test._is_promise_test = true;
731
732 // If there is no promise tests queue make one.
733 if (!tests.promise_tests) {
734 tests.promise_tests = Promise.resolve();
735 }
736 tests.promise_tests = tests.promise_tests.then(function() {
737 return new Promise(function(resolve) {
738 var promise = test.step(func, test, test);
739
740 test.step(function() {
741 assert(!!promise, "promise_test", null,
742 "test body must return a 'thenable' object (received ${value})",
743 {value:promise});
744 assert(typeof promise.then === "function", "promise_test", null,
745 "test body must return a 'thenable' object (received an object with no `then` method)",
746 null);
747 });
748
749 // Test authors may use the `step` method within a
750 // `promise_test` even though this reflects a mixture of
751 // asynchronous control flow paradigms. The "done" callback
752 // should be registered prior to the resolution of the
753 // user-provided Promise to avoid timeouts in cases where the
754 // Promise does not settle but a `step` function has thrown an
755 // error.
756 add_test_done_callback(test, resolve);
757
758 Promise.resolve(promise)
759 .catch(test.step_func(
760 function(value) {
761 if (value instanceof AssertionError) {
762 throw value;
763 }
764 assert(false, "promise_test", null,
765 "Unhandled rejection with value: ${value}", {value:value});
766 }))
767 .then(function() {
768 test.done();
769 });
770 });
771 });
772 }
773
774 /**
775 * Make a copy of a Promise in the current realm.

Calls 6

get_test_nameFunction · 0.85
assertFunction · 0.70
add_test_done_callbackFunction · 0.70
resolveMethod · 0.45
thenMethod · 0.45
doneMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…