From 4df82ab964de7be5fd91604b849cb60df6779fa4 Mon Sep 17 00:00:00 2001 From: Mike Pennisi Date: Mon, 27 Mar 2017 11:40:55 -0400 Subject: [PATCH 1/2] Require "thenable" for `promise_test` The `promise_test` function is intended to run an asynchronous test, interpreting its status via a "thenable" object provided via return value. Previously, it would accept functions that did not provide such a value, and this meant that tests could fail silently. Because there is no use case for using `promise_test` in this way, the condition always reflects a programming error. Update the harness to explicitly fail the test whenever this occurs, prompting contributors to correct their usage prior to submitting the test. --- testharness.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/testharness.js b/testharness.js index ee842e4..cd68309 100644 --- a/testharness.js +++ b/testharness.js @@ -532,7 +532,16 @@ policies and contribution forms [3]. }); var promise = test.step(func, test, test); test.step(function() { - assert_not_equals(promise, undefined); + if (promise === undefined || promise === null) { + throw new Error( + "testharness.js: Function provided to `promise_test` did not return a value."); + } + + if (typeof promise.then !== "function") { + throw new Error( + "testharness.js: Function provided to `promise_test` did not return a \"thenable\" value."); + } + }); Promise.resolve(promise).then( function() { From a3cba90e26d86c748d9d074dc8b9961a9d578b97 Mon Sep 17 00:00:00 2001 From: Mike Pennisi Date: Tue, 28 Mar 2017 13:57:30 -0400 Subject: [PATCH 2/2] fixup! Require "thenable" for `promise_test` --- testharness.js | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/testharness.js b/testharness.js index cd68309..f9a68ea 100644 --- a/testharness.js +++ b/testharness.js @@ -532,16 +532,19 @@ policies and contribution forms [3]. }); var promise = test.step(func, test, test); test.step(function() { + var message; + if (promise === undefined || promise === null) { - throw new Error( - "testharness.js: Function provided to `promise_test` did not return a value."); + message = "Function provided to `promise_test` did not return a value."; + } else if (typeof promise.then !== "function") { + message = "Function provided to `promise_test` did not return a \"thenable\" value."; } - if (typeof promise.then !== "function") { - throw new Error( - "testharness.js: Function provided to `promise_test` did not return a \"thenable\" value."); + if (message) { + tests.status.message = message; + tests.status.status = tests.status.ERROR; + throw new Error('testharness.js: ' + message); } - }); Promise.resolve(promise).then( function() {