-
Notifications
You must be signed in to change notification settings - Fork 2k
[CS2] Fix async tests #4680
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
[CS2] Fix async tests #4680
Conversation
…t’ wrapper in the REPL to use a Promise instead of the ‘await’ keyword; add tests for REPL ‘await’ wrapper, including test to skip async tests if the runtime doesn’t support them
…` function is), we add it to an array of async test functions and wait for them all to resolve before finishing the test run, so that if any async tests fail we see those failures in the output
Cakefile
Outdated
| failures.push {filename, error} | ||
| return !failures.length | ||
|
|
||
| Promise.all asyncTests |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd suggest trying to get a 'final' pass/fail from this method if possible, e.g. something like:
Promise.all(asyncTests).then ->
Promise.reject() if failures.lengthThen, when handling the results, we can just do:
runTests CoffeeScript
.catch -> process.exit 1There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good call!
Cakefile
Outdated
| catch err | ||
| onFail description, fn, err | ||
|
|
||
| global.supportsAsync = if global.testingBrowser |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I made this comment in another PR - but could we not just have the try feature-test only? It seems neater to me to have just the one:
global.supportsAsync = try
new Function 'async () => {}'
yes
catch
noThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Otherwise this LGTM 👍
Not sure when this started happening, but our current test runs complete before waiting for the async tests to resolve, either passing or failing, so if an async test were to start failing we would never know. To remedy this, I check if a test function is an
instanceof Promise, as all async functions are, and if it is, I save it to anasyncTestsarray. After the synchronous tests are all run, I doPromise.all asyncTeststo wait for all the async tests to resolve. The consumers of therunTestsfunction now expect aPromiseto be returned; for non-async runtimes, I return an immediately-resolvingPromisethat resolves to whether or not all the tests passed. (I wanted to preserve the ability for the tests to run in Node 6 and non-async-capable runtimes, since it isn’t so much extra effort at least for now. Node 6 supports promises.)To test this, break one of the tests (async and/or non-async) and make sure the failure appears when you run
cake test. Do the same when running in Node 6.(This branches off of #4679, so that it’s possible to run
cake testin Node 6. The diff should shrink once that PR is merged in.)