Skip to content

[WV-2254] Convert WebDriverIO configs to ESM for v8 compatibility#4700

Merged
charanya-QA merged 1 commit intowevote:developfrom
tarunramireddy:esm-webdriverio8-conversion
Feb 25, 2026
Merged

[WV-2254] Convert WebDriverIO configs to ESM for v8 compatibility#4700
charanya-QA merged 1 commit intowevote:developfrom
tarunramireddy:esm-webdriverio8-conversion

Conversation

@tarunramireddy
Copy link
Contributor

@tarunramireddy tarunramireddy commented Feb 24, 2026

Summary

Converted WebDriverIO configuration files from CommonJS to ESM syntax for WebDriverIO 8 compatibility.

Changes Made

  • Updated browserstack.config.js to use export syntax
  • Updated wdio.config.local.js to use import/export
  • Updated wdio.config.productdemo.js to use import/export
  • Updated wdio.local.config.js to use import/export
  • Updated DiscussPage.browser.js to use import/export
  • Updated all spec files to ESM syntax

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

Copilot AI review requested due to automatic review settings February 24, 2026 19:22
@tarunramireddy tarunramireddy changed the title WV-2254 Convert WebDriverIO configs to ESM for v8 compatibility [WV-2254] Convert WebDriverIO configs to ESM for v8 compatibility Feb 24, 2026
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.exports to import/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 __dirname equivalent in wdio.config.js using fileURLToPath and dirname

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';
Copy link

Copilot AI Feb 24, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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';

Suggested change
import assert from 'node:assert';
import assert from 'node:assert';
import { describe, it } from 'mocha';

Copilot uses AI. Check for mistakes.

const assert = require('assert');
const { describe, it } = require('mocha');
import assert from 'node:assert';
Copy link

Copilot AI Feb 24, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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';

Suggested change
import assert from 'node:assert';
import assert from 'node:assert';
import { describe, it } from 'mocha';

Copilot uses AI. Check for mistakes.
@@ -2,8 +2,6 @@
import { browser, driver, expect } from '@wdio/globals';
import DiscussPage from '../page_objects/discuss.browser';
Copy link

Copilot AI Feb 24, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
import DiscussPage from '../page_objects/discuss.browser';
import DiscussPage from '../page_objects/discuss.browser';
import { describe, it } from 'mocha';

Copilot uses AI. Check for mistakes.
Comment on lines +6 to 7
import { browserStackConfig } from '../config/browserstack.config.js';

Copy link

Copilot AI Feb 24, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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);
Suggested change
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);

Copilot uses AI. Check for mistakes.
@charanya-QA charanya-QA merged commit e00c94d into wevote:develop Feb 25, 2026
5 of 6 checks passed
@charanya-QA
Copy link
Contributor

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants