webdriverio / codemod

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

Async codemod is inconsistent #89

Open prust opened 1 year ago

prust commented 1 year ago

I recently used the async codemod to convert 2,500 lines of tests and found it to be inconsistent.

It would add await places where it shouldn't, for example, before underscore functions and String.startsWith() / .endsWith().

It would put await in the wrong place, for example before assert.equal() instead of before browser.getUrl():

await assert.equal(browser.getUrl(), base_url + '/#changesets', 'navigateToActiveChangesets');

It doesn't support functions added to the browser object (though perhaps this is discouraged & therefore by design). For example, this function isn't converted to async, and calls to it don't get an await injected:

  browser.getText = function (el) {
    return $(el).getText();
  };

It seems to assume the codebase is on WebDriver v7.9+ and can use a single async on chained calls. For example, it only injected two awaits here:

  async function getDot(dotClass, labelClass) {
    return (await (await $(dotClass + '[style="opacity: 1"]')
      .parent())
      .parent())
      .find(labelClass)
      .html();
  }

Perhaps this is a fair assumption, but it would be nice if it was documented in case others, like me, plan to upgrade to 7.9+ after the async codemod instead of before.

christian-bromann commented 1 year ago

but it would be nice if it was documented in case others

Makes sense, feel free to raise a PR.

christian-bromann commented 1 year ago

It doesn't support functions added to the browser object

Yes, you shouldn't do this.

It would add await places where it shouldn't, for example, before underscore functions and String.startsWith() / .endsWith().

This is a bug and should be fixed. Any contributions would be much appreciated.