Skip to content
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

Support for async await? #31

Closed
semmel opened this issue May 24, 2017 · 4 comments
Closed

Support for async await? #31

semmel opened this issue May 24, 2017 · 4 comments

Comments

@semmel
Copy link

semmel commented May 24, 2017

@jmatsushita How can I test ES7 async (i.e. Promise returning) functions?

/**
 * @example
 *   resolvesAPromise();
 *   // ~> 11
 */
async function resolvesAPromise() {
	return 11;
}

Under Node v.7.6.0 using the iilab's jsdoctest project fork I get

0 passing

Although async await is supported in Node I tried requiring these babel plugins, but no luck: syntax-async-functions and transform-regenerator.

Best regards
Semmel

@jmatsushita
Copy link

jmatsushita commented May 25, 2017 via email

@yamadapc
Copy link
Owner

async => should work on a mocha --require babel-register --require jsdoctest I'd love a failing test otherwise. We've tests testing bash scripts.

@semmel
Copy link
Author

semmel commented May 26, 2017

The error is caused by tj/dox v. 0.8 not supporting async functions. Fortunately @cjy37 has created a fork of dox v. 0.9 with a patch for async functions.

So I upgraded dox to v. 0.9 and "merged" @cjy37 patch by overwriting dox.js. Now everything works fine without requiring any Babel packages on the command line:

 mocha --include test/helpers/helper-promises.js --timeout 3000 --require .  test/files/returns-complex-es7-promise.js 

test/files/returns-complex-es7-promise
resolvesAPromise()
✓ resolvesAPromise() (2006ms)

This being my ES7 source file:

/**
 * @example
 *   resolvesAPromise();
 *   // ~> 10
 */
async function resolvesAPromise() {
	await new Promise( resolve => setTimeout(resolve, 2000) );
	return 10;
}

Hopefully both @jmatsushita's and @cjy37 forks will sometime eventually be merged back with their parent projects so that I can upgrade my tooling better in the future.

@yamadapc
Copy link
Owner

Hm... I see... The recommended way would be to use babel, maybe even to preserve your code base compatible with versions of Node that don't yet support async/await.

RE dox fork; if there's some PR it'll likely be merged soon, otherwise I wouldn't mind depending on a patched version temporarily.

I'll add tests to async syntax with babel soon. Closing as invalid though.

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

No branches or pull requests

3 participants