-
Notifications
You must be signed in to change notification settings - Fork 461
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Supporting asynchronous tests #24
Comments
It is certainly the norm for test harnesses to pass a |
ping @anba, who may have an opinion on augmenting runTestCase further... |
Mocha uses a My first idea was to use the /**
* @negative TaskExecuted
*/
var TaskExecuted = new Error("TaskExecuted");
// Function to throw an exception from within "8.4.2 NextTask"
function stopExecution() {
let p = Promise.reject();
p.constructor = function(r) {
r(() => {}, () => { throw TaskExecuted });
};
p.then();
}
try {
Promise.resolve().then(stopExecution);
} catch (e) {
// catch any error here to ensure `throw` from stopExecution()
// is executed after current turn
} Related: |
I'l start sketching the promise tests as if Clarifying: runTestCase(function () {
// looks at the return value
});
runTestCase(function (done) {
// waits for `done` to be called
// If `done` is called with a non-undefined first parameter
// it is considered the same as calling $ERROR
}); |
I'm not sure I would prefer runTestCase over something like /**
* @async
*/
doSomethingAsync().then(function() {
$DONE();
}); Where the harness will wait for $DONE to be called when the @async attribute is present, with some timeout value (implementing timeout without setTimeout is likely difficult but possible I believe). I say this because I think the current guidance is to effectively deprecate runTestCase, so it would be a shame to resurrect it for async if this is true. |
I'd be ok with that too, though I find it a bit weird to be using promises to test promises. It seems like simplicity should win here. Also promises may catch unexpected errors. |
The only harness requirement is $DONE function and support for @async attribute. In the example above, consider it a test for "promise invokes .then handler" or something... IOW I think all the promise machinery is under test. I actually think the two proposed implementations are mostly identical, the only real difference being whether $DONE/done are globally exposed or passed as a param to the runTestCase callback. @juandopazo, is that your understanding as well? |
Oh I got it. My thought was that having |
I suppose the harness could search for $DONE in the test case somewhere to know that it's async... probably a decent idea, but I haven't thought too hard about it :) |
This was fixed by #34 |
I believe this is fixed now, and there is now async test support in:
Comments, @bterlson @juandopazo |
Agreed, closing this. |
In order to test module loaders and promises, test262 needs to support asynchronous tests.
The most straightforward way would be to extend the signature of
runTestCase(fn)
The test case function could get adone
function as a parameter, similar to what Mocha does.I think this would introduce the least increase to the API surface.
An open issue is what to do with tests that time out, because test262 should not know about
setTimeout
.@domenic @kriskowal would you mind commenting on this?
The text was updated successfully, but these errors were encountered: