webdriverio / codemod

A codemod to transform Protractor into WebdriverIO tests
MIT License
25 stars 12 forks source link

env: node\r: No such file or directory #32

Closed mekalag closed 3 years ago

mekalag commented 3 years ago

Hi everyone, I am trying to transform a file called baseSteps.js to webdriverIO file using command

npx jscodeshift ../node_modules/\@wdio/codemod/protractor/ test/steps/baseSteps.js

Before this i have installed : npm install --save-dev @wdio/cli npx wdio config (ran the configuration wizard) I have configured cucumber framework.

After which I ran npx jscodeshift ../node_modules/\@wdio/codemod/protractor/ test/steps/baseSteps.js

In package.json I have all the dependencies

Screenshot 2021-07-03 at 18 52 06

So when I run npx jscodeshift ../node_modules/\@wdio/codemod/protractor/ test/steps/baseSteps.js it throws : env: node\r: No such file or directory

Not sure what I am missing. though baseSteps.js file exists in test/steps folder. Can someone suggest?

Note: I am using mac OS. I was going through help in some other articles and I think this issue is caused by line endings with CRLF, where as its must be LF. For ex: https://github.com/mrmlnc/svg2sprite-cli/issues/4 and many more when we search for env: node\r: No such file or directory hopefully this will give an idea

christian-bromann commented 3 years ago

You were missing a parameter, see our Usage section, I believe it is suppose to be this way:

npx jscodeshift -t ./node_modules/@wdio/codemod/protractor ./test/steps/baseSteps.js

Please let me know if you have further questions.

mekalag commented 3 years ago

Unfortunately, using -t parameter dint help. Its still throws env: node\r: No such file or directory.

erickzhao commented 1 year ago

For reference, I think this is an upstream issue with jscodeshift: https://github.com/facebook/jscodeshift/issues/424

kliph-gladly commented 1 year ago

It would be helpful to update the docs to indicate that the workaround described here https://github.com/facebook/jscodeshift/issues/424#issuecomment-888243971 works.

christian-bromann commented 1 year ago

@kliph-gladly mind raising a PR?

kliph-gladly commented 1 year ago

I've encountered larger issues with the @wdio/codemod/async adding the await keyword to function calls for functions that do not return promises and failing to add async to anonymous inline functions. I anticipate that I won't be using this in the future.

christian-bromann commented 1 year ago

You will only need the codemod package as utility to rewrite your tests.

kliph-gladly commented 1 year ago

Thanks. Yes I'm aware. The larger issue that I mentioned is that the utility produces code with syntax errors.

christian-bromann commented 1 year ago

Can you provide a code example that causes a syntax error when rewriting the code with this codemod?

kliph-gladly commented 1 year ago

Sure:

const foo = function() {
  mySyncFunctionDoesNotReturnAPromiseOrEvenExist();
};

produces

const foo = function() {
  await mySyncFunctionDoesNotReturnAPromiseOrEvenExist();
};

This is syntactically incorrect for two reasons. The outer function context is not async so it doesn't make sense to use await within it. And the function called in the inner scope does not return a promise, so it doesn't make sense to use await.

christian-bromann commented 1 year ago

Yep, this is a bug, mind raising a new issue for it?

kliph-gladly commented 1 year ago

Will do. Thank you.