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

TypeError: array is not iterable #141

Closed
sqal opened this issue Dec 11, 2018 · 13 comments
Closed

TypeError: array is not iterable #141

sqal opened this issue Dec 11, 2018 · 13 comments

Comments

@sqal
Copy link

sqal commented Dec 11, 2018

Hi. I would like to report a bug with latest version (0.18.0) of this package. I just installed jest-codemods on my machine (globally) and no matter what option I choose in the cli, I always get the same error TypeError: array is not iterable

Full log

? Which parser do you want to use? Babel
? Which test library would you like to migrate from? Chai: Should/Expect BDD Syntax
? Are you using the global object for assertions (i.e. without requiring them) Yes, and I'm not afraid of false positive tr
ansformations
? Will you be using Jest on Node.js as your test runner? Yes, use the globals provided by Jest (recommended)

NOTICE: Skipping import detection, you might get false positives
Executing command: jscodeshift -t C:\Users\pc\AppData\Roaming\npm\node_modules\jest-codemods\dist\transformers\chai-should.js tests/*.test.js --ignore-pattern node_modules --parser babel --skipImportDetection=true
Skipping path tests/*.test.js which does not exist.
(node:796) UnhandledPromiseRejectionWarning: TypeError: array is not iterable
    at concatAll (C:\Users\pc\AppData\Roaming\npm\node_modules\jest-codemods\node_modules\jscodeshift\src\Runner.js:72:27)
    at process._tickCallback (internal/process/next_tick.js:68:7)
(node:796) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:796) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

Environment

  • Node/npm version: 10.11.0/6.4.1
  • OS: Windows 10
@skovhus
Copy link
Owner

skovhus commented Dec 12, 2018

The actually problem is hidden in this line:

Skipping path tests/*.test.js which does not exist.

So it didn’t find any files matching the glob.

You might want tests/**/*.test.js instead? Or simple tests. Or maybe globs doesn’t work correctly on windows. I would like to figure out what the reason is...

The misleading error is caused by a problem in jscodeshift. See facebook/jscodeshift#295

@sqal
Copy link
Author

sqal commented Dec 12, 2018

Or simple tests

I can confirm success :) But that's the only pattern which works for me. It doesn't work when i try using any glob pattern:

tests/**/*.test.js
tests/*.test.js
**/*.test.js

gives me the same error

@skovhus
Copy link
Owner

skovhus commented Dec 12, 2018

Thanks.

And how does your folder structure look? Do you have test files in tests/foo/bar/my.test.js?

@sqal
Copy link
Author

sqal commented Dec 12, 2018

All files are directly in the tests folder, no subdirectories

@skovhus
Copy link
Owner

skovhus commented Dec 12, 2018

Seems like the globby.sync is not working on windows.

See https://github.com/skovhus/jest-codemods/blob/master/src/cli/index.js#L251

Here if you don't give any files as command line arguments (jest-codemods tests/*.test.js which will be expanded by most shells), then we expand the glob pattern you give in the interactive CLI.

If you have time, it would be valuable if you can do a console.log(filesExpanded) in C:\Users\pc\AppData\Roaming\npm\node_modules\jest-codemods\dist\cli\index.js.

@sqal
Copy link
Author

sqal commented Dec 12, 2018

@skovhus Sure. I have added console.log in this line and it appears that globby is not even used:

Here are my changes:

console.log('cli.input', cli.input)

var filesExpanded = cli.input.length ? cli.input : _globby.default.sync(files);

console.log('')
console.log('filesExpanded:')
console.log(filesExpanded)
console.log('')

Logs from terminal:


C:\Users\pc\Desktop\jest-codemod-test>jest-codemods tests/*.test.js -f
WARNING: Git directory is not clean. Forcibly continuing.
? Which parser do you want to use? Babel
? Which test library would you like to migrate from? Chai: Should/Expect BDD Syntax
? Are you using the global object for assertions (i.e. without requiring them) Yes, and I'm not afraid of false positive tr
ansformations
? Will you be using Jest on Node.js as your test runner? Yes, use the globals provided by Jest (recommended)
cli.input [ 'tests/*.test.js' ]

filesExpanded:
[ 'tests/*.test.js' ]


NOTICE: Skipping import detection, you might get false positives
Executing command: jscodeshift -t C:\Users\pc\AppData\Roaming\npm\node_modules\jest-codemods\dist\transformers\chai-should.js tests/*.test.js --ignore-pattern node_modules --parser babel --skipImportDetection=true
Skipping path tests/*.test.js which does not exist.
(node:3676) UnhandledPromiseRejectionWarning: TypeError: array is not iterable
    at concatAll (C:\Users\pc\AppData\Roaming\npm\node_modules\jest-codemods\node_modules\jscodeshift\src\Runner.js:72:27)
    at process._tickCallback (internal/process/next_tick.js:68:7)
(node:3676) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:3676) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

Globby itself works fine on Windows, I checked it and this code prints an array with all the files in the tests folder

console.log(globby.sync(['tests/*.test.js']))

@sqal
Copy link
Author

sqal commented Dec 12, 2018

Looks like simple change is required here:

var filesExpanded = _globby.default.sync(cli.input.length ? cli.input : files)

and it works now :)

@skovhus
Copy link
Owner

skovhus commented Dec 12, 2018

Ah, your shell is not expanding the glob! Thank you so much for this. I’ll make a fix.

@skovhus
Copy link
Owner

skovhus commented Dec 15, 2018

@sqal I've deployed your fix as jest-codemods@0.19.0. I would really appreciate if you have time to see if it works for you. Thanks. :)

@sqal
Copy link
Author

sqal commented Dec 16, 2018

@skovhus Hey. I've installed 0.19.0 and yes, can confirm that original issue is gone, but I ran into another issue. After transformation task is completed, node process just hangs on the line Time elapsed: 0.873seconds, there's no additional errors and I can't even terminate the process with shortcut CTRL+C, I have to close terminal's window instead. I managed to find the source of this problem. It's Inquirer.js. This package uses inquirer@3.2.2 which is pretty outdated. I manually updated this dependency to the latest version and it fixes this issue for me. i couldn't find any issue in Inquirer.js repo related to my, so I started to install different versions of inquirer to find out in which one this error has been fixed, and I managed to narrow it down to the version 5.0.0 (SBoudrias/Inquirer.js@v4.0.2...v5.0.0).

@skovhus
Copy link
Owner

skovhus commented Dec 16, 2018

@sqal thank you so for debugging this!!

I'm cutting a new release soon – I'll let you know when this is out. :)

@skovhus
Copy link
Owner

skovhus commented Dec 16, 2018

0.19.1 is out. Can I get you to test it?

Thanks!

@sqal
Copy link
Author

sqal commented Dec 16, 2018

Thank you! Everything works great now :)

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

2 participants