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

Transformation error with Ava #58

Closed
spinningarrow opened this issue Jun 9, 2017 · 9 comments
Closed

Transformation error with Ava #58

spinningarrow opened this issue Jun 9, 2017 · 9 comments

Comments

@spinningarrow
Copy link

spinningarrow commented Jun 9, 2017

I'm getting this error with some of my test files (which are written using Ava):

Transformation error
Error: [] does not match field "arguments": [Expression | SpreadElement] of type CallExpression
    at add (~/static/node_modules/ast-types/lib/types.js:580:31)
    at ~/static/node_modules/ast-types/lib/types.js:593:21
    at Array.forEach (native)
    at Function.value [as callExpression] (~/static/node_modules/ast-types/lib/types.js:592:34)
    at NodePath.ast.find.forEach.p (~/static/node_modules/jest-codemods/dist/transformers/ava.js:122:34)
    at __paths.forEach (~/static/node_modules/jscodeshift/dist/Collection.js:76:36)
    at Array.forEach (native)
    at Collection.forEach (~/static/node_modules/jscodeshift/dist/Collection.js:75:18)
    at updateAssertions (~/static/node_modules/jest-codemods/dist/transformers/ava.js:98:12)
    at transforms.forEach.t (~/static/node_modules/jest-codemods/dist/transformers/ava.js:179:29)
All done. 

How do I go about figuring out where the problem lies?

@skovhus
Copy link
Owner

skovhus commented Jun 9, 2017

Thanks for reporting this @spinningarrow .

First thing it to find the file that causes this and narrow down a minimal example of a source code that yields this error. And then either paste it here or make a PR where you add a test that documents this failure (the TDD way).

@skovhus
Copy link
Owner

skovhus commented Jul 18, 2017

@spinningarrow did you have time to come with source code that gave you this error? Would like to fix this. : )

@spinningarrow
Copy link
Author

Hey, thanks for following up. The code I was trying it on isn't open source and I haven't found the time to come up with a minimal example yet. Will try to do it soon!

@skovhus
Copy link
Owner

skovhus commented Aug 14, 2017

@spinningarrow I'll keep this open a bit more... Would really love to get this fixed.

@spinningarrow
Copy link
Author

spinningarrow commented Aug 22, 2017

Hi @skovhus, thanks for your patience. I managed to come up with a minimal example:

import test from 'ava';

const someFunction = _ => 1;

test('minimal test that throws a transformation error', t => {
  const result = someFunction();
  t.is(result);
});

The error is:

ERR test/utilities/MinimalTest.js Transformation error
Error: [] does not match field "arguments": [Expression | SpreadElement] of type CallExpression
    at add (/Users/sahil/dev/something/static/node_modules/jscodeshift/node_modules/ast-types/lib/types.js:580:31)
    at /Users/sahil/dev/something/static/node_modules/jscodeshift/node_modules/ast-types/lib/types.js:593:21
    at Array.forEach (native)
    at Function.value [as callExpression] (/Users/sahil/dev/something/static/node_modules/jscodeshift/node_modules/ast-types/lib/types.js:592:34)
    at NodePath.ast.find.forEach.p (/Users/sahil/dev/something/static/node_modules/jest-codemods/dist/transformers/ava.js:114:34)
    at __paths.forEach (/Users/sahil/dev/something/static/node_modules/jscodeshift/src/Collection.js:76:36)
    at Array.forEach (native)
    at Collection.forEach (/Users/sahil/dev/something/static/node_modules/jscodeshift/src/Collection.js:75:18)
    at updateAssertions (/Users/sahil/dev/something/static/node_modules/jest-codemods/dist/transformers/ava.js:90:12)
    at transforms.forEach.t (/Users/sahil/dev/something/static/node_modules/jest-codemods/dist/transformers/ava.js:171:29)
All done.

Looking at the Ava docs, it looks like the error is actually in the test itself - t.is takes two arguments not one, so this isn't really a bug in jest-codemods. However, the error is pretty hard to debug - is it possible to get some kind of context or line numbering when something like this happens?

@skovhus
Copy link
Owner

skovhus commented Aug 22, 2017

Thanks for digging this up! I'll have a look.

@skovhus
Copy link
Owner

skovhus commented Oct 8, 2017

Thanks @spinningarrow ! Released as 0.13.4.

https://github.com/skovhus/jest-codemods/releases/tag/0.13.4

@skovhus skovhus closed this as completed Oct 8, 2017
@iansinnott
Copy link

Very helpful issue. And thanks for the fix @skovhus.

Just wanted to add for anyone else coming across this that an empty t.snapshot() will also cause the opaque transformation error listed above.

As noted, that error means there's something wrong with the ava test itself. In my case, t.snapshot() needs to be passed an argument 🤦‍♂️ , but since ava doesn't care (it will just create a snapshot containing "undefined") it's quite possible to have these sorts of issues lurking in the codebase without knowing.

@skovhus
Copy link
Owner

skovhus commented Nov 16, 2017

Thanks for sharing. Another good reason for migrating to Jest.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants