Skip to content

Commit

Permalink
feat: update to webdriverio@7
Browse files Browse the repository at this point in the history
BREAKING CHANGE: drop support for hermione < 4
  • Loading branch information
KuznetsovRoman committed Nov 1, 2022
1 parent dce967a commit 61ba354
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 24 deletions.
31 changes: 14 additions & 17 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,20 @@ module.exports = (hermione, opts = {}) => {
return;
}

function closeTabs(browser) {
let tabIds;

return browser
.getTabIds()
.then((ids) => {
tabIds = ids;

return browser.switchTab(tabIds[0]);
})
.then(() => {
return Promise.mapSeries(tabIds, (id, ind) => {
return (ind === tabIds.length - 1)
? browser
: browser.close(tabIds[ind + 1]);
});
});
async function closeTabs(browser) {
const tabIds = await browser.getWindowHandles();

await browser.switchToWindow(tabIds[0]);

return Promise.mapSeries(tabIds, async (id, ind) => {
if (ind === tabIds.length - 1) {
return browser;
}

await browser.closeWindow();

return browser.switchToWindow(tabIds[ind + 1]);
});
}

function shouldClose(browserId) {
Expand Down
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,8 @@
"eslint-config-gemini-testing": "^2.7.0",
"mocha": "^2.4.5",
"sinon": "^2.3.8"
},
"peerDependencies": {
"hermione": ">=4.0.0"
}
}
12 changes: 5 additions & 7 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ describe('hermione tabs closer', () => {

const mkBrowser = () => {
return {
switchTab: sandbox.stub().resolves(),
getTabIds: sandbox.stub().resolves(['tab1', 'tab2', 'tab3']),
close: sandbox.stub().resolves()
switchToWindow: sandbox.stub().resolves(),
getWindowHandles: sandbox.stub().resolves(['tab1', 'tab2', 'tab3']),
closeWindow: sandbox.stub().resolves()
};
};

Expand Down Expand Up @@ -78,9 +78,7 @@ describe('hermione tabs closer', () => {
const beforeEachHook = suite.beforeEach.lastCall.args[0];
await beforeEachHook.call({browser});

assert.calledWith(browser.switchTab, 'tab1');
assert.calledWith(browser.close, 'tab2');
assert.calledWith(browser.close, 'tab3');
assert.neverCalledWith(browser.close, 'tab1');
assert.match(browser.closeWindow.callCount, 2);
assert.match(browser.switchToWindow.args [['tab1'], ['tab2'], ['tab3']]);
});
});

0 comments on commit 61ba354

Please sign in to comment.