Skip to content

Conversation

@GeoffreyBooth
Copy link
Collaborator

@GeoffreyBooth GeoffreyBooth commented Sep 1, 2017

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 an asyncTests array. After the synchronous tests are all run, I do Promise.all asyncTests to wait for all the async tests to resolve. The consumers of the runTests function now expect a Promise to be returned; for non-async runtimes, I return an immediately-resolving Promise that 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 test in Node 6. The diff should shrink once that PR is merged in.)

…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
Copy link
Collaborator

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.length

Then, when handling the results, we can just do:

runTests CoffeeScript
  .catch -> process.exit 1

Copy link
Collaborator Author

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
Copy link
Collaborator

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
  no

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Otherwise this LGTM 👍

@GeoffreyBooth GeoffreyBooth merged commit 9e043bb into jashkenas:2 Sep 1, 2017
@GeoffreyBooth GeoffreyBooth deleted the wait-for-await-tests branch September 1, 2017 19:26
@GeoffreyBooth GeoffreyBooth mentioned this pull request Sep 2, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants