[WV-2254] Convert WebDriverIO configs to ESM for v8 compatibility#4700
Conversation
There was a problem hiding this comment.
Pull request overview
This PR converts WebDriverIO configuration files and test specs from CommonJS to ESM (ES Module) syntax to ensure compatibility with WebDriverIO v8. The conversion updates module imports/exports, JSON imports with type assertions, and adds ESM equivalents for CommonJS globals like __dirname.
Changes:
- Converted all config files (wdio.config.js, wdio.config.local.js, wdio.config.productdemo.js, wdio.local.config.js) from
require/module.exportstoimport/export - Updated spec files (WhosRunningForOfficeMobileBrowser, PrivacyPageMobileBrowser, DiscussPage, DownloadVideo) to use ESM import syntax
- Updated buildMobileCapabilities.js to use ESM syntax
- Added JSON import assertions using
with { type: 'json' }syntax - Added ESM
__dirnameequivalent in wdio.config.js usingfileURLToPathanddirname
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/browserstack_automation/specs/WhosRunningForOfficeMobileBrowser.browser.js | Removed CommonJS require statements for assert and mocha, added ESM import for node:assert |
| tests/browserstack_automation/specs/PrivacyPageMobileBrowser.browser.js | Removed CommonJS require statements for assert and mocha, added ESM import for node:assert |
| tests/browserstack_automation/specs/DownloadVideo.browser.js | Converted all CommonJS requires to ESM imports including fs, path, axios, readline, googleapis, and browserstack config |
| tests/browserstack_automation/specs/DiscussPage.browser.js | Removed unused CommonJS mocha require statement |
| tests/browserstack_automation/config/wdio.local.config.js | Converted config import/export to ESM syntax |
| tests/browserstack_automation/config/wdio.config.productdemo.js | Converted all imports to ESM, added resolve import from path, updated JSON imports with assertions, changed config export to named export |
| tests/browserstack_automation/config/wdio.config.local.js | Converted all imports to ESM, added JSON import assertion, changed config export to named export |
| tests/browserstack_automation/config/wdio.config.js | Added ESM __dirname equivalent using fileURLToPath and dirname, converted to ESM imports |
| tests/browserstack_automation/buildMobileCapabilities.js | Converted all imports from CommonJS to ESM including axios, fs, and browserstack config |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
|
||
| const assert = require('assert'); | ||
| const { describe, it } = require('mocha'); | ||
| import assert from 'node:assert'; |
There was a problem hiding this comment.
The mocha imports (describe, it) were removed but these functions are still being used in the file on lines 13 and 16. While WebDriverIO may provide these globally at runtime, this is inconsistent with other spec files in the codebase like SignInPage.browser.js and TopNavigation.browser.js which explicitly import describe and it from mocha. For consistency and clarity, you should add: import { describe, it } from 'mocha';
| import assert from 'node:assert'; | |
| import assert from 'node:assert'; | |
| import { describe, it } from 'mocha'; |
|
|
||
| const assert = require('assert'); | ||
| const { describe, it } = require('mocha'); | ||
| import assert from 'node:assert'; |
There was a problem hiding this comment.
The mocha imports (describe, it) were removed but these functions are still being used in the file on line 8. While WebDriverIO may provide these globally at runtime, this is inconsistent with other spec files in the codebase like SignInPage.browser.js and TopNavigation.browser.js which explicitly import describe and it from mocha. For consistency and clarity, you should add: import { describe, it } from 'mocha';
| import assert from 'node:assert'; | |
| import assert from 'node:assert'; | |
| import { describe, it } from 'mocha'; |
| @@ -2,8 +2,6 @@ | |||
| import { browser, driver, expect } from '@wdio/globals'; | |||
| import DiscussPage from '../page_objects/discuss.browser'; | |||
There was a problem hiding this comment.
The mocha imports (describe, it) were removed but these functions are still being used in the file on line 16. While WebDriverIO may provide these globally at runtime, this is inconsistent with other spec files in the codebase like SignInPage.browser.js and TopNavigation.browser.js which explicitly import describe and it from mocha. For consistency and clarity, you should add: import { describe, it } from 'mocha'; after line 3.
| import DiscussPage from '../page_objects/discuss.browser'; | |
| import DiscussPage from '../page_objects/discuss.browser'; | |
| import { describe, it } from 'mocha'; |
| import { browserStackConfig } from '../config/browserstack.config.js'; | ||
|
|
There was a problem hiding this comment.
In ESM modules, the global __dirname variable is not available. This file uses __dirname on lines 11, 12, and 70, but it hasn't been defined. You need to add the ESM equivalent at the beginning of the file after the imports, similar to what was done in wdio.config.js. Add these lines after line 6:
import { fileURLToPath } from 'url';
import { dirname } from 'path';
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);| import { browserStackConfig } from '../config/browserstack.config.js'; | |
| import { browserStackConfig } from '../config/browserstack.config.js'; | |
| import { fileURLToPath } from 'url'; | |
| import { dirname } from 'path'; | |
| const __filename = fileURLToPath(import.meta.url); | |
| const __dirname = dirname(__filename); |
|
Thanks! |
Summary
Converted WebDriverIO configuration files from CommonJS to ESM syntax for WebDriverIO 8 compatibility.
Changes Made
https://automate.browserstack.com/projects/Default+Project/builds/Tarun+Ramireddy:/3?tab=tests&status=failed&testListView=spec&match=%7B%22status%22%3A%22OR%22%7D