webdriverio / codemod

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

Add initial code for sync to async conversion #53

Closed WillBrock closed 2 years ago

WillBrock commented 2 years ago

Expanding off of this pull request

This looks to do the sync to async conversion on most things.

This should convert:

Add to constants arrays for custom items unique to a codebase

In async/constants.js

AWAIT_CUSTOM_GETTERS - Add getters here that will need to be awaited. e.g. things like $$

get foo() { $$(`.foobar`); }

EXCLUDE_METHODS - Add class methods here that don't need to be async / await

linux-foundation-easycla[bot] commented 2 years ago

CLA Signed

The committers are authorized under a signed CLA.

WillBrock commented 2 years ago

For the forEach parts I think it might be easiest to do the following with jscodeshift but I'm not sure how to do it.

From:

[1,2,3].forEach(num => {
     browser.pause(5000);
})

To:

await Promise.all([1,2,3].map(async num => {
    await browser.pause(5000);
});

Any suggestions would be helpful.

christian-bromann commented 2 years ago

@WillBrock thanks for the work! Have you tried https://astexplorer.net/? It is really great to understand how one piece of code needs to be replaced with the other. Also would you mind extending the test cases so we are sure to not introduce any bugs down the line?

WillBrock commented 2 years ago

Fixed a few things and added converting forEach to regular for loops. Still a work in progress.

Will add some tests as well.

WillBrock commented 2 years ago

I think I've got the majority of things covered. I added tests for it but the tsx parser ones are failing because it doesn't add async to method definitions. I'm not sure why those are failing so something I'll need to read up more on.

WillBrock commented 2 years ago

Still some more edge cases I need to do that are coming up.

christian-bromann commented 2 years ago

@WillBrock great work! Let me know when this is ready to review and I am happy to take a look.

kailin0512 commented 2 years ago

@WillBrock Great work! is it ready to use or you need some help on that?

WillBrock commented 2 years ago

@kailin0512 It's just about ready. I've just got a few things to clean up and I'll try to push the changes tomorrow.

WillBrock commented 2 years ago

I think this is basically ready. I'm still going through some of our codebase at work (about 3k files) but most things are working.

If anyone wants to try it out feel free and let me know what issues you run into.

WillBrock commented 2 years ago

@christian-bromann This is ready.

christian-bromann commented 2 years ago

Awesome work @WillBrock , let me review it asap.

owens-ben commented 2 years ago

@christian-bromann any update on approving this?

owens-ben commented 2 years ago

and @WillBrock how can I try this out before it's published? I'm happy to help test it.

jameskip commented 2 years ago

Thank you @WillBrock for your work on this!