Skip to content

Commit aa01456

Browse files
committed
feat(esm): Phase 4 - Convert remaining lib infrastructure files to ESM
Converted the last 12 files in lib/ directory to ES modules: - Helpers: AI.js, Appium.js, GraphQL.js, GraphQLDataFactory.js - Listeners: steps.js, retryEnhancer.js, enhancedGlobalRetry.js - Plugins: enhancedRetryFailedStep.js, htmlReporter.js - Support: retryCoordinator.js, test-server.js, clientscripts/PollyWebDriverExt.js All files now use import/export statements instead of require/module.exports. Added __dirname polyfills to test-server.js for CLI usage. All core library files are now fully converted to ESM.
1 parent 934e0fd commit aa01456

File tree

12 files changed

+77
-70
lines changed

12 files changed

+77
-70
lines changed

lib/helper/AI.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
const HelperModule = require('@codeceptjs/helper')
2-
const ora = require('ora-classic')
3-
const fs = require('fs')
4-
const path = require('path')
5-
const ai = require('../ai')
6-
const Container = require('../container')
7-
const { splitByChunks, minifyHtml } = require('../html')
8-
const { beautify } = require('../utils')
9-
const output = require('../output')
10-
const { registerVariable } = require('../pause')
1+
import HelperModule from '@codeceptjs/helper'
2+
import ora from 'ora-classic'
3+
import fs from 'fs'
4+
import path from 'path'
5+
import ai from '../ai.js'
6+
import Container from '../container.js'
7+
import { splitByChunks, minifyHtml } from '../html.js'
8+
import { beautify } from '../utils.js'
9+
import output from '../output.js'
10+
import { registerVariable } from '../pause.js'
1111

1212
const standardActingHelpers = Container.STANDARD_ACTING_HELPERS
1313

@@ -211,4 +211,4 @@ class AI extends Helper {
211211
}
212212
}
213213

214-
module.exports = AI
214+
export default AI

lib/helper/Appium.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
let webdriverio
22

3-
const fs = require('fs')
4-
const axios = require('axios').default
5-
const { v4: uuidv4 } = require('uuid')
3+
import fs from 'fs'
4+
import axios from 'axios'
5+
import { v4 as uuidv4 } from 'uuid'
66

7-
const Webdriver = require('./WebDriver')
8-
const AssertionFailedError = require('../assert/error')
9-
const { truth } = require('../assert/truth')
10-
const recorder = require('../recorder')
11-
const Locator = require('../locator')
12-
const ConnectionRefused = require('./errors/ConnectionRefused')
7+
import Webdriver from './WebDriver.js'
8+
import AssertionFailedError from '../assert/error.js'
9+
import { truth } from '../assert/truth.js'
10+
import recorder from '../recorder.js'
11+
import Locator from '../locator.js'
12+
import ConnectionRefused from './errors/ConnectionRefused.js'
1313

1414
const mobileRoot = '//*'
1515
const webRoot = 'body'
@@ -1908,4 +1908,4 @@ function onlyForApps(expectedPlatform) {
19081908
}
19091909
}
19101910

1911-
module.exports = Appium
1911+
export default Appium

lib/helper/GraphQL.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
const axios = require('axios').default
2-
const HelperModule = require('@codeceptjs/helper')
1+
import axios from 'axios'
2+
import HelperModule from '@codeceptjs/helper'
33

44
/**
55
* GraphQL helper allows to send additional requests to a GraphQl endpoint during acceptance tests.
@@ -227,4 +227,4 @@ class GraphQL extends Helper {
227227
this.haveRequestHeaders({ Authorization: `Bearer ${accessToken}` })
228228
}
229229
}
230-
module.exports = GraphQL
230+
export default GraphQL

lib/helper/GraphQLDataFactory.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
const path = require('path')
1+
import path from 'path'
22

3-
const HelperModule = require('@codeceptjs/helper')
4-
const GraphQL = require('./GraphQL')
3+
import HelperModule from '@codeceptjs/helper'
4+
import GraphQL from './GraphQL.js'
55

66
/**
77
* Helper for managing remote data using GraphQL queries.
@@ -305,4 +305,4 @@ class GraphQLDataFactory extends Helper {
305305
}
306306
}
307307

308-
module.exports = GraphQLDataFactory
308+
export default GraphQLDataFactory

lib/helper/clientscripts/PollyWebDriverExt.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,4 +108,4 @@ const pollyWebDriver = {
108108
},
109109
};
110110

111-
module.exports = pollyWebDriver;
111+
export default pollyWebDriver;

lib/listener/enhancedGlobalRetry.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
const event = require('../event')
2-
const output = require('../output')
3-
const Config = require('../config')
4-
const { isNotSet } = require('../utils')
1+
import event from '../event.js'
2+
import output from '../output.js'
3+
import Config from '../config.js'
4+
import { isNotSet } from '../utils.js'
55

66
const hooks = ['Before', 'After', 'BeforeSuite', 'AfterSuite']
77

@@ -20,7 +20,7 @@ const RETRY_PRIORITIES = {
2020
/**
2121
* Enhanced global retry mechanism that coordinates with other retry types
2222
*/
23-
module.exports = function () {
23+
export default function () {
2424
event.dispatcher.on(event.suite.before, suite => {
2525
let retryConfig = Config.get('retry')
2626
if (!retryConfig) return
@@ -107,4 +107,4 @@ module.exports = function () {
107107
}
108108

109109
// Export priority constants for use by other retry mechanisms
110-
module.exports.RETRY_PRIORITIES = RETRY_PRIORITIES
110+
export { RETRY_PRIORITIES }

lib/listener/retryEnhancer.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
const event = require('../event')
2-
const { enhanceMochaTest } = require('../mocha/test')
1+
import event from '../event.js'
2+
import { enhanceMochaTest } from '../mocha/test.js'
33

44
/**
55
* Enhance retried tests by copying CodeceptJS-specific properties from the original test
66
* This fixes the issue where Mocha's shallow clone during retries loses CodeceptJS properties
77
*/
8-
module.exports = function () {
8+
export default function () {
99
event.dispatcher.on(event.test.before, test => {
1010
// Check if this test is a retry (has a reference to the original test)
1111
const originalTest = test.retriedTest && test.retriedTest()

lib/listener/steps.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
const debug = require('debug')('codeceptjs:steps')
2-
const event = require('../event')
3-
const store = require('../store')
4-
const output = require('../output')
5-
const { BeforeHook, AfterHook, BeforeSuiteHook, AfterSuiteHook } = require('../mocha/hooks')
6-
const recorder = require('../recorder')
1+
import debugModule from 'debug'
2+
const debug = debugModule('codeceptjs:steps')
3+
import event from '../event.js'
4+
import store from '../store.js'
5+
import output from '../output.js'
6+
import { BeforeHook, AfterHook, BeforeSuiteHook, AfterSuiteHook } from '../mocha/hooks.js'
7+
import recorder from '../recorder.js'
78

89
let currentTest
910
let currentHook

lib/plugin/enhancedRetryFailedStep.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
const event = require('../event')
2-
const recorder = require('../recorder')
3-
const store = require('../store')
4-
const output = require('../output')
5-
const { RETRY_PRIORITIES } = require('../retryCoordinator')
1+
import event from '../event.js'
2+
import recorder from '../recorder.js'
3+
import store from '../store.js'
4+
import output from '../output.js'
5+
import { RETRY_PRIORITIES } from '../retryCoordinator.js'
66

77
const defaultConfig = {
88
retries: 3,
@@ -17,7 +17,7 @@ const defaultConfig = {
1717
* This plugin provides step-level retries and coordinates with global retry settings
1818
* to avoid conflicts and provide predictable behavior.
1919
*/
20-
module.exports = config => {
20+
export default config => {
2121
config = Object.assign({}, defaultConfig, config)
2222
config.ignoredSteps = config.ignoredSteps.concat(config.defaultIgnoredSteps)
2323
const customWhen = config.when

lib/plugin/htmlReporter.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,17 @@
22
// TypeScript: Import Node.js types for process, fs, path, etc.
33
/// <reference types="node" />
44

5-
const fs = require('fs')
6-
const path = require('path')
7-
const mkdirp = require('mkdirp')
8-
const crypto = require('crypto')
9-
const { threadId } = require('worker_threads')
10-
const { template } = require('../utils')
11-
const { getMachineInfo } = require('../command/info')
12-
13-
const event = require('../event')
14-
const output = require('../output')
15-
const Codecept = require('../codecept')
5+
import fs from 'fs'
6+
import path from 'path'
7+
import mkdirp from 'mkdirp'
8+
import crypto from 'crypto'
9+
import { threadId } from 'worker_threads'
10+
import { template } from '../utils.js'
11+
import { getMachineInfo } from '../command/info.js'
12+
13+
import event from '../event.js'
14+
import output from '../output.js'
15+
import Codecept from '../codecept.js'
1616

1717
const defaultConfig = {
1818
output: typeof global !== 'undefined' && global.output_dir ? global.output_dir : './output',
@@ -62,7 +62,7 @@ const defaultConfig = {
6262
* }
6363
* ```
6464
*/
65-
module.exports = function (config) {
65+
export default function (config) {
6666
const options = { ...defaultConfig, ...config }
6767
/**
6868
* TypeScript: Explicitly type reportData arrays as any[] to avoid 'never' errors

0 commit comments

Comments
 (0)