-
Notifications
You must be signed in to change notification settings - Fork 1.4k
t.throws() causes Node syntax error if first argument is function call with await arguments #987
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
Comments
Let's see how test files look between different AVA versions:
|
Thanks for the response, here you have: |
Could you paste them without diff (as separate files/gists)? |
@nesukun Sorry for the delay. Are you having the same issues in 0.16? |
Hi @sotojuan, |
Sorry, didn't see the 0.16.x! I'll investigate. |
This is the failing line: t.throws(checkAgainst('4p455w0rd', await hash('4n0th3rp455w0rd'))); It's transpiled into: t.throws(_avaThrowsHelper(function () {
return (0, _crypto.checkAgainst)('4p455w0rd', (yield (0, _crypto.hash)('4n0th3rp455w0rd')));
}, {
line: 21,
column: 11,
source: 'checkAgainst(\'4p455w0rd\', await hash(\'4n0th3rp455w0rd\'))',
filename: '/private/var/folders/_6/p8qxp_3n62zg9081tvb0lcc80000gn/T/tmp.dkCnTDjWip/mawpedia/test/server/core/crypto.js'
})); The function wrapper was introduced in #742. It breaks the @nesukun the workaround would be to compute the hash outside the const targetHash = await hash('4n0th3rp455w0rd');
t.throws(checkAgainst('4p455w0rd', targetHash)); @jamestalmage this is a gnarly bug. I suppose the workaround would be to hoist any |
@nesukun another potential workaround: const p = checkAgainst('4p455w0rd', await hash('4n0th3rp455w0rd'));
t.throws(p); |
Thanks for the investigation and response. I've stumbled with this issue in a few different proyects. Will surely follow your workaround recommendation until a more suitable solution is found. Have a great day! |
The helper wraps the original argument with a new function. This is a problem if the argument contains yield or await expressions, since the function they now run is is not a generator or marked as asynchronous. Instead hoist these expressions so they're resolved outside of the helper. Fixes avajs/ava#987.
I've tried to improve our throws helper but got stuck on another edge case. If anybody's interested in taking this on, the PR is at avajs/babel-plugin-throws-helper#6. |
The helper wraps the original argument with a new function. This is a problem if the argument contains yield or await expressions, since the function they now run is is not a generator or marked as asynchronous. Instead hoist these expressions so they're resolved outside of the helper. Fixes avajs/ava#987.
Fixed in d924045. |
Description
I have a test that breaks after updating ava to version ~0.15.2 that works when using [email protected]. This has been tested on node 6.3.1 and 4.2.4 amongst others. and seems related to a missing "use strict" after transpiling ES6 modules (wild guess there). I've looked at the commits between the two versions but haven't been able to identify what might cause the problem, but I haven't tested individual commits due to lack of time.
Test Source, error message, and configuration
You can see the relevant files and error message here: https://gist.github.com/nesukun/f8cb2eef133548224d21bfd8a3ae5aa4
As a side note, using AVA's default babel config does not solve or alter the result. Hope you don't mind having everything in a gist, as I prepared that for the gitter channel before opening the issue.
Environment
Tested mainly using the versions of node specified above under macOS 10.11.5 and inside the docker default node image
The text was updated successfully, but these errors were encountered: