Comments (12)
It is certainly the norm for test harnesses to pass a done(?error)
method and require it to be called by the test only if testFn.length >= 1
. The pattern composes well and addresses the needs of testing promises themselves. For higher layers, it is useful if the scaffold will check whether testFn
returns an object, and if so, treat it as a promise for the completion of the test.
from test262.
ping @anba, who may have an opinion on augmenting runTestCase further...
from test262.
Mocha uses a setTimeout
based solution for its asynchronous tests, so, as already mentioned in #comment 0, this approach will not work for test262. It's kind of difficult to properly test Promise support in ECMAScript implementations, because task queues are a completely new concept in ECMAScript and there are no existing tools to track eventual computations. For example the JavaScriptCore Promise tests rely on comparing console output. And the V8 tests use Object.observe()
and some internal functions.
My first idea was to use the @negative
attribute and hope implementations use the same uncaught exception handling in NextTask as for other uncaught exceptions, that means to stop script execution. Unfortunately the V8 implementation silently ignores exceptions in NextTask 😞.
/**
* @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:
@negative
attribute: https://mail.mozilla.org/pipermail/test262-discuss/2013-September/000242.html- http://wiki.ecmascript.org/doku.php?id=test262:test_case_format#informal_test262_test_case_semantics
- https://bugs.ecmascript.org/show_bug.cgi?id=1716
from test262.
I'l start sketching the promise tests as if runTestCase
took a function argument with a done
optional parameter. I'll probably have them done quite a bit after we figure out how to deal with tasks.
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
});
from test262.
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.
from test262.
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.
from test262.
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?
from test262.
Oh I got it. My thought was that having done
as a parameter would communicate by itself that the test is async without needing the async attribute. But I'm ok either way.
from test262.
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 :)
from test262.
This was fixed by #34
from test262.
I believe this is fixed now, and there is now async test support in:
- python console runner
- node test262-harness console runner
- browser runner
Comments, @bterlson @juandopazo
from test262.
Agreed, closing this.
from test262.
Related Issues (20)
- Remove non-existend "AsyncArrowFunction" constructor
- Please sync the test to intl-duration-format/pull PR181 HOT 1
- Math.sumPrecise testing plan HOT 3
- nanoseconds: Number.MAX_VALUE in precision-exact-mathematical-values HOT 4
- Question: NPM Registry HOT 4
- `new Iterator()` should throw `TypeError`? HOT 2
- Add more tests for `v` flag
- Various ECMA links 404 HOT 2
- Testing plan for JSON-parse-with-source HOT 2
- Create testing plan for the Deferring Module Evaluation proposal. HOT 2
- Create testing plan for the Joint Iteration proposal. HOT 1
- Automatically add a results table for CI runs on pull requests HOT 1
- Create testing plan for the RegExp.escape proposal HOT 1
- Only use `phase: parse` for errors that happens while parsing the test entry point HOT 2
- Add metadata about the ECMAScript edition that each feature was introduced in HOT 9
- Follow-up to Intl.DurationFormat #3912
- assert.throwsAsync incorrectly tolerates a result `then` which returns a non-thenable
- Need test for intl-duration-format/pull/198
- Source phase import tests importing from "<do not resolve>" are broken HOT 1
- Harness tests should run when harness source changes
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from test262.