mirror of https://github.com/tc39/test262.git
harness/asyncHelpers.js: Refactor asyncTest to always return undefined instead of a Promise
This commit is contained in:
parent
d810c684ae
commit
1d116b48a9
|
@ -10,17 +10,12 @@ function asyncTest(testFunc) {
|
|||
if (!Object.hasOwn(globalThis, "$DONE")) {
|
||||
throw new Test262Error("asyncTest called without async flag");
|
||||
}
|
||||
const resolveThenable = {
|
||||
then(resolve, reject) {
|
||||
resolve();
|
||||
},
|
||||
};
|
||||
if (typeof testFunc !== "function") {
|
||||
$DONE(new Test262Error("asyncTest called with non-function argument"));
|
||||
return resolveThenable;
|
||||
return;
|
||||
}
|
||||
try {
|
||||
return testFunc().then(
|
||||
testFunc().then(
|
||||
function () {
|
||||
$DONE();
|
||||
},
|
||||
|
@ -30,7 +25,6 @@ function asyncTest(testFunc) {
|
|||
);
|
||||
} catch (syncError) {
|
||||
$DONE(syncError);
|
||||
return resolveThenable;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -11,6 +11,6 @@ function $DONE(error) {
|
|||
assert(error instanceof Test262Error);
|
||||
}
|
||||
asyncTest(function () {
|
||||
throw new Test262Error("Should not be evaluated");
|
||||
throw new Test262Error("Should not be rethrown");
|
||||
});
|
||||
assert(called, "asyncTest called $DONE with a synchronously thrown error");
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
description: |
|
||||
The 'asyncTest' helper when called with async flag always returns a promise that resolves to undefined.
|
||||
The 'asyncTest' helper when called with async flag always returns to undefined.
|
||||
flags: [async]
|
||||
includes: [asyncHelpers.js]
|
||||
---*/
|
||||
|
@ -12,34 +12,28 @@ globalThis.$DONE = function () {
|
|||
doneCalls++;
|
||||
};
|
||||
|
||||
async function assertPromiseUndefined(returnedPromise) {
|
||||
assert(
|
||||
returnedPromise instanceof Promise,
|
||||
"returned value should be a Promise"
|
||||
);
|
||||
assert.sameValue(
|
||||
await returnedPromise,
|
||||
undefined,
|
||||
"returned Promise should resolve to undefined"
|
||||
);
|
||||
}
|
||||
|
||||
(async function () {
|
||||
await assertPromiseUndefined(asyncTest({}));
|
||||
await assertPromiseUndefined(
|
||||
assert.sameValue(undefined, asyncTest({}));
|
||||
assert.sameValue(
|
||||
undefined,
|
||||
asyncTest(function () {
|
||||
return "non-thenable";
|
||||
})
|
||||
);
|
||||
await assertPromiseUndefined(
|
||||
assert.sameValue(
|
||||
undefined,
|
||||
asyncTest(function () {
|
||||
return Promise.resolve(true);
|
||||
})
|
||||
);
|
||||
await assertPromiseUndefined(
|
||||
assert.sameValue(
|
||||
undefined,
|
||||
asyncTest(function () {
|
||||
return Promise.reject(new Test262Error("oh no"));
|
||||
})
|
||||
);
|
||||
assert.sameValue(doneCalls, 4, "asyncTest must call $DONE");
|
||||
})().then(realDone, realDone);
|
||||
})()
|
||||
.then(() => {
|
||||
assert.sameValue(doneCalls, 4, "asyncTest must call $DONE");
|
||||
})
|
||||
.then(realDone, realDone);
|
|
@ -14,24 +14,35 @@ globalThis.$DONE = function (mustBeDefined) {
|
|||
const someObject = {};
|
||||
|
||||
(async function () {
|
||||
await asyncTest(function () {
|
||||
asyncTest(function () {
|
||||
return Promise.reject(null);
|
||||
});
|
||||
await asyncTest(function () {
|
||||
return Promise.reject(someObject);
|
||||
});
|
||||
await asyncTest(function () {
|
||||
return Promise.reject("hi");
|
||||
});
|
||||
await asyncTest(function () {
|
||||
return Promise.reject(10);
|
||||
});
|
||||
await asyncTest(function () {
|
||||
return {
|
||||
then(res, rej) {
|
||||
rej(true);
|
||||
},
|
||||
};
|
||||
});
|
||||
assert.compareArray(rejectionValues, [null, someObject, "hi", 10, true]);
|
||||
})().then(realDone, realDone);
|
||||
})()
|
||||
.then(() => {
|
||||
asyncTest(function () {
|
||||
return Promise.reject(someObject);
|
||||
});
|
||||
})
|
||||
.then(() => {
|
||||
asyncTest(function () {
|
||||
return Promise.reject("hi");
|
||||
});
|
||||
})
|
||||
.then(() => {
|
||||
asyncTest(function () {
|
||||
return Promise.reject(10);
|
||||
});
|
||||
})
|
||||
.then(() => {
|
||||
asyncTest(function () {
|
||||
return {
|
||||
then(res, rej) {
|
||||
rej(true);
|
||||
},
|
||||
};
|
||||
});
|
||||
})
|
||||
.then(() => {
|
||||
assert.compareArray(rejectionValues, [null, someObject, "hi", 10, true]);
|
||||
})
|
||||
.then(realDone, realDone);
|
||||
|
|
|
@ -18,28 +18,39 @@ globalThis.$DONE = function (noError) {
|
|||
};
|
||||
|
||||
(async function () {
|
||||
await asyncTest(function () {
|
||||
asyncTest(function () {
|
||||
return Promise.resolve(null);
|
||||
});
|
||||
assert.sameValue(doneCalls, 1, "asyncTest called $DONE with undefined");
|
||||
await asyncTest(function () {
|
||||
return Promise.resolve({});
|
||||
});
|
||||
assert.sameValue(doneCalls, 2, "asyncTest called $DONE with undefined");
|
||||
await asyncTest(function () {
|
||||
return Promise.resolve("hi");
|
||||
});
|
||||
assert.sameValue(doneCalls, 3, "asyncTest called $DONE with undefined");
|
||||
await asyncTest(function () {
|
||||
return Promise.resolve(10);
|
||||
});
|
||||
assert.sameValue(doneCalls, 4, "asyncTest called $DONE with undefined");
|
||||
await asyncTest(function () {
|
||||
return {
|
||||
then(res, rej) {
|
||||
res(true);
|
||||
},
|
||||
};
|
||||
});
|
||||
assert.sameValue(doneCalls, 5, "asyncTest called $DONE with undefined");
|
||||
})().then(realDone, realDone);
|
||||
})()
|
||||
.then(() => {
|
||||
assert.sameValue(doneCalls, 1, "asyncTest called $DONE with undefined");
|
||||
asyncTest(function () {
|
||||
return Promise.resolve({});
|
||||
});
|
||||
})
|
||||
.then(() => {
|
||||
assert.sameValue(doneCalls, 2, "asyncTest called $DONE with undefined");
|
||||
asyncTest(function () {
|
||||
return Promise.resolve("hi");
|
||||
});
|
||||
})
|
||||
.then(() => {
|
||||
assert.sameValue(doneCalls, 3, "asyncTest called $DONE with undefined");
|
||||
asyncTest(function () {
|
||||
return Promise.resolve(10);
|
||||
});
|
||||
})
|
||||
.then(() => {
|
||||
assert.sameValue(doneCalls, 4, "asyncTest called $DONE with undefined");
|
||||
asyncTest(function () {
|
||||
return {
|
||||
then(res, rej) {
|
||||
res(true);
|
||||
},
|
||||
};
|
||||
});
|
||||
})
|
||||
.then(() => {
|
||||
assert.sameValue(doneCalls, 5, "asyncTest called $DONE with undefined");
|
||||
})
|
||||
.then(realDone, realDone);
|
||||
|
|
Loading…
Reference in New Issue