Skip to content

Commit

Permalink
Fix vitest browser stack provider typings for vitest 2
Browse files Browse the repository at this point in the history
  • Loading branch information
edoardocavazza committed Jul 9, 2024
1 parent e9812e3 commit ec18f7e
Showing 1 changed file with 37 additions and 1 deletion.
38 changes: 37 additions & 1 deletion packages/vitest-provider-browserstack/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ export default class BrowserStackProvider {
*/
_tunnelPromise = null;

/**
* @inheritdoc
*/
supportsParallelism = false;

/**
* Get supported browsers.
* @returns {string[]}
Expand Down Expand Up @@ -94,7 +99,10 @@ export default class BrowserStackProvider {
this.testName = config.name;

const { browser: browserName } = options;
const browserstackConfig = browser.config.browserstack || {};
const browserstackConfig =
('config' in browser
? /** @type {import('vite').UserConfig} */ (browser.config).browserstack
: browser.vite.config.browserstack) || {};
if (!browserstackConfig.capabilities) {
throw new Error('Missing capabilities in browserstack configuration');
}
Expand Down Expand Up @@ -139,6 +147,32 @@ export default class BrowserStackProvider {
}));
}

/**
* @inheritdoc
*/
async beforeCommand() {
const browser = /** @type {WebdriverIO.Browser} */ (await this._browserPromise);
const iframe = await browser.findElement('css selector', 'iframe[data-vitest]');
await browser.switchToFrame(iframe);
}

/**
* @inheritdoc
*/
async afterCommand() {
const browser = /** @type {WebdriverIO.Browser} */ (await this._browserPromise);
await browser.switchToParentFrame();
}

/**
* @inheritdoc
*/
getCommandsContext() {
return {
browser: this.browser,
};
}

/**
* Open the browser.
* @returns {Promise<WebdriverIO.Browser>}
Expand Down Expand Up @@ -167,6 +201,8 @@ export default class BrowserStackProvider {
key: /** @type {string} */ (this.bsOptions.key),
});

this.browser = browser;

return browser;
}));
}
Expand Down

0 comments on commit ec18f7e

Please sign in to comment.