* Create an asynchronous test * * @param {TestFunction|string} funcOrName - Initial step function * to call immediately with the test name as an argument (if any), * or name of the test. * @param {String} name - Test name (if a test function was * provided). This must b
(func, name, properties)
| 664 | * @returns {Test} An object representing the ongoing test. |
| 665 | */ |
| 666 | function async_test(func, name, properties) |
| 667 | { |
| 668 | if (tests.promise_setup_called) { |
| 669 | tests.status.status = tests.status.ERROR; |
| 670 | tests.status.message = '`async_test` invoked after `promise_setup`'; |
| 671 | tests.complete(); |
| 672 | } |
| 673 | if (typeof func !== "function") { |
| 674 | properties = name; |
| 675 | name = func; |
| 676 | func = null; |
| 677 | } |
| 678 | var test_name = get_test_name(func, name); |
| 679 | var test_obj = new Test(test_name, properties); |
| 680 | if (func) { |
| 681 | var value = test_obj.step(func, test_obj, test_obj); |
| 682 | |
| 683 | // Test authors sometimes return values to async_test, expecting us |
| 684 | // to handle the value somehow. Make doing so a harness error to be |
| 685 | // clear this is invalid, and point authors to promise_test if it |
| 686 | // may be appropriate. |
| 687 | // |
| 688 | // Note that we only perform this check on the initial function |
| 689 | // passed to async_test, not on any later steps - we haven't seen a |
| 690 | // consistent problem with those (and it's harder to check). |
| 691 | if (value !== undefined) { |
| 692 | var msg = 'Test named "' + test_name + |
| 693 | '" passed a function to `async_test` that returned a value.'; |
| 694 | |
| 695 | try { |
| 696 | if (value && typeof value.then === 'function') { |
| 697 | msg += ' Consider using `promise_test` instead when ' + |
| 698 | 'using Promises or async/await.'; |
| 699 | } |
| 700 | } catch (err) {} |
| 701 | |
| 702 | tests.set_status(tests.status.ERROR, msg); |
| 703 | tests.complete(); |
| 704 | } |
| 705 | } |
| 706 | return test_obj; |
| 707 | } |
| 708 | |
| 709 | /** |
| 710 | * Create a promise test. |
no test coverage detected