You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Not completely sure this is an issue of this repo, could be a jest's one. I'm reporting it here because it could be a configuration problem.
Description
Running npm test fails when using async/await.
Expected behavior
The test runs
Actual behavior
I receive an error:
● Test suite failed to run
/src/merchants.js: Expected type "Expression" with option {}
at Object.t.(anonymous function) [as assertExpression] (node_modules/babel-types/lib/index.js:362:13)
at Array.forEach (native)
Environment
Run these commands in the project folder and fill in their results:
npm ls react-scripts: v0.8.1
node -v: v6.9.1
npm -v: v3.10.8
Operating system: Fedora 24
Browser and version: --
Reproducible Demo
Just a new "cra" project, with an async/await function tested.
I have a demonstration here, just git clone, npm install and npm test.
// ...constplugins=[// ...// Polyfills the runtime needed for async/await and generators[require.resolve('babel-plugin-transform-runtime'),{helpers: false,polyfill: false,regenerator: true,// Resolve the Babel runtime relative to the config.moduleName: path.dirname(require.resolve('babel-runtime/package'))}],// The following two plugins are currently necessary to get// babel-preset-env to work with rest/spread. More info here:// https://github.com/babel/babel-preset-env#caveats// https://github.com/babel/babel/issues/4074// const { a, ...z } = obj;require.resolve('babel-plugin-transform-es2015-destructuring'),// const fn = ({ a, ...otherProps }) => otherProps;require.resolve('babel-plugin-transform-es2015-parameters')];// ...if(env==='test'){module.exports={presets: [// ES features necessary for user's Node version[require('babel-preset-env').default,{targets: {node: 'current',},}],// ...
no, unfortunately it doesn't work (I always double-check it by reintroducing babel-preset-latest at the end)
I won't be able to cut a release today anyway so might as well wait for more details (or investigate myself tomorrow if I get there first). Once we know more we'll decide and cut a release.
Activity
EnoahNetzach commentedon Dec 5, 2016
The problem seems to be caused by some interaction between the return value of an
awaitedfunction and destructuring it.E.g.:
works, while
or
don't work.
EnoahNetzach commentedon Dec 5, 2016
In facts, tapping into
node_modules/babel-generator/lib/buffer.jsand casting the argumentstrto aString, I get an error that looks like:gaearon commentedon Dec 5, 2016
Did it work before?
EnoahNetzach commentedon Dec 5, 2016
Yes, we're migrating a project from v0.6.1 to the latest
EnoahNetzach commentedon Dec 5, 2016
I'm getting a lot of "strange" errors.
Another one, for example, is that while using
immutable, this won't work anymore:while it worked before (and works now, same version).
and the error is:
EnoahNetzach commentedon Dec 5, 2016
I was able to fix all the errors by reintroducing
babel-preset-latestin thetestenv, so it might be some misconfiguration ofbabel-preset-env?EnoahNetzach commentedon Dec 5, 2016
Also removing
{ targets: { node: 'current' } }, without reintroducingbabel-preset-latestseems to make the deed.gaearon commentedon Dec 5, 2016
Can you try:
-envusage like in master?
EnoahNetzach commentedon Dec 5, 2016
If you mean like this:
no, unfortunately it doesn't work (I always double-check it by reintroducing
babel-preset-latestat the end)gaearon commentedon Dec 5, 2016
@hzoo Any ideas?
EnoahNetzach commentedon Dec 5, 2016
The result I get from
babel-preset-envis that I need:I'll try to reintroduce them one by one..
gaearon commentedon Dec 5, 2016
Thanks for your help debugging this.
EnoahNetzach commentedon Dec 5, 2016
No worries ^_^
Apparently what I need are:
so yeah, the two you were saying before, plus
() => {}.Although we use es6+ a lot, and we have approx 230 unit tests, I have to say that these could be only our needs, and others might need more plugins..
gaearon commentedon Dec 5, 2016
So these are likely Babel bugs about hidden plugin dependencies? Can you reduce each to an isolated Babel bug report?
EnoahNetzach commentedon Dec 5, 2016
Either that, or some bug in
babel-plugin-env, I'm going to investigate further tomorrow.In either case should I make a PR reverting to using
babel-plugin-latestfor the moment?gaearon commentedon Dec 6, 2016
I won't be able to cut a release today anyway so might as well wait for more details (or investigate myself tomorrow if I get there first). Once we know more we'll decide and cut a release.
EnoahNetzach commentedon Dec 6, 2016
Seems reasonable
existentialism commentedon Dec 6, 2016
@EnoahNetzach I'll try and take a look at this later tonight as well
EnoahNetzach commentedon Dec 6, 2016
It seems that
babel-plugin-transform-regeneratortries to assert that anObjectPatternis of typeExpression.I think that definitely we should ask help from @kittens?
EnoahNetzach commentedon Dec 6, 2016
btw, this seems to be already issued on babel, maybe I'll continue the conversation there.
gaearon commentedon Dec 6, 2016
Is this issue underlying for all the problems listed here?
EnoahNetzach commentedon Dec 6, 2016
Not entirely sure, I checked only
transform-es2015-destructuringfor nowEnoahNetzach commentedon Dec 6, 2016
I'm closing this issue in favor to #1156