Skip to content

Commit

Permalink
transform expected conditions where it was not put into a EC var
Browse files Browse the repository at this point in the history
  • Loading branch information
christian-bromann committed Apr 21, 2021
1 parent a8c0eba commit b839c6a
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 6 deletions.
27 changes: 21 additions & 6 deletions protractor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -670,6 +670,12 @@ module.exports = function transformer(file, api) {
* into
* - const EC = require('wdio-wait-for')
*/
const wdioWaitForImport = j.callExpression(
j.identifier('require'),
[
j.literal('wdio-wait-for')
]
)
root.find(j.VariableDeclaration)
.filter((path) => (
path.value.declarations[0] &&
Expand All @@ -683,16 +689,25 @@ module.exports = function transformer(file, api) {
[
j.variableDeclarator(
path.value.declarations[0].id,
j.callExpression(
j.identifier('require'),
[
j.literal('wdio-wait-for')
]
)
wdioWaitForImport
)
]
))

/**
* transform expected conditions not put into a var
*/
root.find(j.MemberExpression)
.filter((path) => (
path.value.object.object &&
path.value.object.object.name === 'protractor' &&
path.value.object.property.name === 'ExpectedConditions'
))
.replaceWith((path) => j.memberExpression(
wdioWaitForImport,
path.value.property
))

/**
* no support
*/
Expand Down
4 changes: 4 additions & 0 deletions test/__fixtures__/protractor/source/spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,7 @@ var width = 800;
var height = 600;
browser.driver.manage().window().setSize(width, height);
browser.manage().deleteAllCookies();

var titleIsNotFoo = protractor.ExpectedConditions.not(
protractor.ExpectedConditions.titleIs('Foo')
);
4 changes: 4 additions & 0 deletions test/__fixtures__/protractor/transformed/spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,7 @@ var width = 800;
var height = 600;
browser.setWindowRect(0, 0, width, height);
browser.deleteCookies();

var titleIsNotFoo = require("wdio-wait-for").not(
require("wdio-wait-for").titleIs('Foo')
);

0 comments on commit b839c6a

Please sign in to comment.