asyncHelpers tests: Address code review feedback

This commit is contained in:
Cam Tenny 2023-02-10 12:25:20 -08:00 committed by Philip Chimento
parent e0d5b780e7
commit eb44f67274
18 changed files with 50 additions and 58 deletions

View File

@ -4,7 +4,7 @@
/*--- /*---
description: > description: >
Functions that throw instances of the realm specified constructor function Functions that throw instances of the realm specified constructor function
satisfy the assertion, without cross realms collisions. do not satisfy the assertion with cross realms collisions.
---*/ ---*/
var intrinsicTypeError = TypeError; var intrinsicTypeError = TypeError;

View File

@ -6,11 +6,13 @@ description: |
includes: [asyncHelpers.js] includes: [asyncHelpers.js]
---*/ ---*/
var called = false; var called = false;
var msg = "Should not be rethrown";
function $DONE(error) { function $DONE(error) {
called = true; called = true;
assert(error instanceof Test262Error); assert(error instanceof Test262Error);
assert.sameValue(error.message, msg, "Should report correct error");
} }
asyncTest(function () { asyncTest(function () {
throw new Test262Error("Should not be rethrown"); throw new Test262Error(msg);
}); });
assert(called, "asyncTest called $DONE with a synchronously thrown error"); assert(called, "asyncTest called $DONE with a synchronously thrown error");

View File

@ -8,6 +8,7 @@ includes: [asyncHelpers.js, compareArray.js]
const doneValues = []; const doneValues = [];
function $DONE(error) { function $DONE(error) {
// Will be a TypeError from trying to invoke .then() on non-thenable
doneValues.push(error instanceof TypeError); doneValues.push(error instanceof TypeError);
} }
asyncTest(function () { asyncTest(function () {

View File

@ -2,7 +2,7 @@
// This code is governed by the BSD license found in the LICENSE file. // This code is governed by the BSD license found in the LICENSE file.
/*--- /*---
description: | description: |
The 'asyncTest' helper when called with async flag always returns to undefined. The 'asyncTest' helper when called with async flag always returns undefined.
flags: [async] flags: [async]
includes: [asyncHelpers.js] includes: [asyncHelpers.js]
---*/ ---*/

View File

@ -8,7 +8,8 @@ includes: [asyncHelpers.js]
function makePromise() { function makePromise() {
return { return {
then(res, rej) { then(res, rej) {
throw new Test262Error("Should not be evaluated"); // Throw a different error than Test262Error to avoid confusion about what is rejecting
throw new Error("Should not be evaluated");
}, },
}; };
} }

View File

@ -10,7 +10,7 @@ includes: [asyncHelpers.js]
var intrinsicTypeError = TypeError; var intrinsicTypeError = TypeError;
(async function () { asyncTest(async function () {
function TypeError() {} function TypeError() {}
var caught = false; var caught = false;
@ -69,4 +69,4 @@ var intrinsicTypeError = TypeError;
"assert.throwsAsync did not reject a collision of constructor names" "assert.throwsAsync did not reject a collision of constructor names"
); );
} }
})().then($DONE, $DONE); })

View File

@ -10,10 +10,10 @@ includes: [asyncHelpers.js]
function MyError() {} function MyError() {}
(async function () { asyncTest(async function () {
const p = assert.throwsAsync(MyError, function () { const p = assert.throwsAsync(MyError, function () {
return Promise.reject(new MyError()); return Promise.reject(new MyError());
}); });
assert(p instanceof Promise); assert(p instanceof Promise);
await p; await p;
})().then($DONE, $DONE); });

View File

@ -2,14 +2,14 @@
// This code is governed by the BSD license found in the LICENSE file. // This code is governed by the BSD license found in the LICENSE file.
/*--- /*---
description: | description: |
assert.throwsAsync returns a promise that rejects if funcOrThenable or the inner thenable synchronously throws. assert.throwsAsync returns a promise that rejects if func or the inner thenable synchronously throws.
flags: [async] flags: [async]
includes: [asyncHelpers.js] includes: [asyncHelpers.js]
---*/ ---*/
async function checkRejects(funcOrThenable) { async function checkRejects(func) {
var caught = false; var caught = false;
const p = assert.throwsAsync(Test262Error, funcOrThenable); const p = assert.throwsAsync(Test262Error, func);
assert(p instanceof Promise, "assert.throwsAsync should return a promise"); assert(p instanceof Promise, "assert.throwsAsync should return a promise");
try { try {
await p; await p;
@ -18,34 +18,23 @@ async function checkRejects(funcOrThenable) {
assert.sameValue( assert.sameValue(
e.constructor, e.constructor,
Test262Error, Test262Error,
"throwsAsync should reject improper funcOrThenable with a Test262Error" "throwsAsync should reject improper function with a Test262Error"
); );
} finally { } finally {
assert( assert(
caught, caught,
"assert.throwsAsync did not reject improper funcOrThenable " + "assert.throwsAsync did not reject improper function " + func
funcOrThenable
); );
} }
} }
(async function () { asyncTest(async function () {
await checkRejects(function () { await checkRejects(function () {
throw new Error(); throw new Error();
}); });
await checkRejects(function () { await checkRejects(function () {
throw new Test262Error(); throw new Test262Error();
}); });
await checkRejects({
then: function () {
throw new Error();
},
});
await checkRejects({
then: function () {
throw new Test262Error();
},
});
await checkRejects(function () { await checkRejects(function () {
return { return {
then: function () { then: function () {
@ -60,4 +49,4 @@ async function checkRejects(funcOrThenable) {
}, },
}; };
}); });
})().then($DONE, $DONE); });

View File

@ -8,7 +8,7 @@ flags: [async]
includes: [asyncHelpers.js] includes: [asyncHelpers.js]
---*/ ---*/
(async function () { asyncTest(async function () {
var caught = false; var caught = false;
const p = assert.throwsAsync(Error, function () { const p = assert.throwsAsync(Error, function () {
@ -32,4 +32,4 @@ includes: [asyncHelpers.js]
"assert.throwsAsync did not reject when a value with incorrect constructor was thrown" "assert.throwsAsync did not reject when a value with incorrect constructor was thrown"
); );
} }
})().then($DONE, $DONE); });

View File

@ -2,14 +2,14 @@
// This code is governed by the BSD license found in the LICENSE file. // This code is governed by the BSD license found in the LICENSE file.
/*--- /*---
description: | description: |
assert.throwsAsync returns a promise that rejects if funcOrThenable is not a function returning a thenable or a thenable. assert.throwsAsync calls $DONE with a rejecting value if func is not a function returning a thenable.
flags: [async] flags: [async]
includes: [asyncHelpers.js] includes: [asyncHelpers.js]
---*/ ---*/
async function checkRejects(funcOrThenable) { async function checkRejects(func) {
var caught = false; var caught = false;
const p = assert.throwsAsync(Test262Error, funcOrThenable); const p = assert.throwsAsync(Test262Error, func);
assert(p instanceof Promise, "assert.throwsAsync should return a promise"); assert(p instanceof Promise, "assert.throwsAsync should return a promise");
try { try {
await p; await p;
@ -18,28 +18,27 @@ async function checkRejects(funcOrThenable) {
assert.sameValue( assert.sameValue(
e.constructor, e.constructor,
Test262Error, Test262Error,
"throwsAsync should reject improper funcOrThenable with a Test262Error" "throwsAsync should reject improper function with a Test262Error"
); );
} finally { } finally {
assert( assert(
caught, caught,
"assert.throwsAsync did not reject improper funcOrThenable " + "assert.throwsAsync did not reject improper function " + func
funcOrThenable
); );
} }
} }
(async function () { asyncTest(async function () {
await checkRejects(null); await checkRejects(null);
await checkRejects({}); await checkRejects({});
await checkRejects("string"); await checkRejects("string");
await checkRejects(10); await checkRejects(10);
await checkRejects(); await checkRejects();
await checkRejects({ then: null }); await checkRejects({
await checkRejects({ then: {} }); then: function (res, rej) {
await checkRejects({ then: "string" }); res(true);
await checkRejects({ then: 10 }); },
await checkRejects({ then: undefined }); });
await checkRejects(function () { await checkRejects(function () {
return null; return null;
}); });
@ -68,4 +67,4 @@ async function checkRejects(funcOrThenable) {
await checkRejects(function () { await checkRejects(function () {
return { then: undefined }; return { then: undefined };
}); });
})().then($DONE, $DONE); });

View File

@ -8,7 +8,7 @@ flags: [async]
includes: [asyncHelpers.js] includes: [asyncHelpers.js]
---*/ ---*/
(async function () { asyncTest(async function () {
var p = assert.throwsAsync(Error, async function () { var p = assert.throwsAsync(Error, async function () {
throw new Error(); throw new Error();
}); });
@ -44,4 +44,4 @@ includes: [asyncHelpers.js]
}); });
assert(p instanceof Promise); assert(p instanceof Promise);
await p; await p;
})().then($DONE, $DONE); });

View File

@ -7,7 +7,7 @@ flags: [async]
includes: [asyncHelpers.js] includes: [asyncHelpers.js]
---*/ ---*/
(async function () { asyncTest(async function () {
var caught = false; var caught = false;
const p = assert.throwsAsync(); const p = assert.throwsAsync();
@ -29,4 +29,4 @@ includes: [asyncHelpers.js]
"assert.throwsAsync did not reject when invoked without arguments" "assert.throwsAsync did not reject when invoked without arguments"
); );
} }
})().then($DONE, $DONE); });

View File

@ -7,7 +7,7 @@ flags: [async]
includes: [asyncHelpers.js] includes: [asyncHelpers.js]
---*/ ---*/
(async function () { asyncTest(async function () {
var caught = false; var caught = false;
const p = assert.throwsAsync(Error, async function () {}); const p = assert.throwsAsync(Error, async function () {});
@ -29,4 +29,4 @@ includes: [asyncHelpers.js]
"assert.throwsAsync did not reject when the thenable did not reject" "assert.throwsAsync did not reject when the thenable did not reject"
); );
} }
})().then($DONE, $DONE); });

View File

@ -7,7 +7,7 @@ flags: [async]
includes: [asyncHelpers.js] includes: [asyncHelpers.js]
---*/ ---*/
(async function () { asyncTest(async function () {
var caught = false; var caught = false;
const p = assert.throwsAsync(Error, async function () { const p = assert.throwsAsync(Error, async function () {
@ -31,4 +31,4 @@ includes: [asyncHelpers.js]
"assert.throwsAsync did not reject when null was thrown" "assert.throwsAsync did not reject when null was thrown"
); );
} }
})().then($DONE, $DONE); });

View File

@ -7,7 +7,7 @@ flags: [async]
includes: [asyncHelpers.js] includes: [asyncHelpers.js]
---*/ ---*/
(async function () { asyncTest(async function () {
var caught = false; var caught = false;
const p = assert.throwsAsync(Error, async function () { const p = assert.throwsAsync(Error, async function () {
@ -31,4 +31,4 @@ includes: [asyncHelpers.js]
"assert.throwsAsync did not reject when a primitive was thrown" "assert.throwsAsync did not reject when a primitive was thrown"
); );
} }
})().then($DONE, $DONE); });

View File

@ -7,7 +7,7 @@ flags: [async]
includes: [asyncHelpers.js] includes: [asyncHelpers.js]
---*/ ---*/
(async function () { asyncTest(async function () {
var caught = false; var caught = false;
const p = assert.throwsAsync( const p = assert.throwsAsync(
@ -32,4 +32,4 @@ includes: [asyncHelpers.js]
"assert.throwsAsync did not reject when the thenable resolved with an error" "assert.throwsAsync did not reject when the thenable resolved with an error"
); );
} }
})().then($DONE, $DONE); });

View File

@ -3,12 +3,12 @@
/*--- /*---
description: | description: |
Thenables that reject with instances of the realm specified constructor function Thenables that reject with instances of the realm specified constructor function
satisfy the assertion, without cross realms collisions. do not satisfy the assertion with cross realms collisions.
flags: [async] flags: [async]
includes: [asyncHelpers.js] includes: [asyncHelpers.js]
---*/ ---*/
(async function () { asyncTest(async function () {
var intrinsicTypeError = TypeError; var intrinsicTypeError = TypeError;
var caught = false; var caught = false;
var realmGlobal = $262.createRealm().global; var realmGlobal = $262.createRealm().global;
@ -34,4 +34,4 @@ includes: [asyncHelpers.js]
"assert.throwsAsync did not reject when a different realm's error was thrown" "assert.throwsAsync did not reject when a different realm's error was thrown"
); );
} }
})().then($DONE, $DONE); });

View File

@ -7,7 +7,7 @@ flags: [async]
includes: [asyncHelpers.js] includes: [asyncHelpers.js]
---*/ ---*/
(async function () { asyncTest(async function () {
var caught = false; var caught = false;
const p = assert.throwsAsync(function () {}); const p = assert.throwsAsync(function () {});
assert(p instanceof Promise); assert(p instanceof Promise);
@ -28,4 +28,4 @@ includes: [asyncHelpers.js]
"assert.throwsAsync did not reject when invoked with a single argumemnt" "assert.throwsAsync did not reject when invoked with a single argumemnt"
); );
} }
})().then($DONE, $DONE); });