diff --git a/index.js b/index.js index 534a584..ecb2b2d 100644 --- a/index.js +++ b/index.js @@ -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) { diff --git a/package.json b/package.json index 9af15f1..df431ed 100644 --- a/package.json +++ b/package.json @@ -28,5 +28,8 @@ "eslint-config-gemini-testing": "^2.7.0", "mocha": "^2.4.5", "sinon": "^2.3.8" + }, + "peerDependencies": { + "hermione": ">=4.0.0" } } diff --git a/test/index.js b/test/index.js index fb9bafc..6ab39a6 100644 --- a/test/index.js +++ b/test/index.js @@ -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() }; }; @@ -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']]); }); });