Skip to content

Commit d277565

Browse files
committed
chore: ESM conversion - Phase 2
Convert additional core files to ES modules: - lib/element/WebElement.js: Convert to export default - lib/helper/Playwright.js: Convert require() to import, export default - lib/step/comment.js: Convert to ESM - lib/workerStorage.js: Remove dynamic require() for Container - Add ESM_CONVERSION_PROGRESS.md tracking document Progress: ~10 files converted Next: Convert Puppeteer, WebDriver, and remaining helpers
1 parent d3b1228 commit d277565

File tree

5 files changed

+103
-15
lines changed

5 files changed

+103
-15
lines changed

ESM_CONVERSION_PROGRESS.md

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
# ESM Conversion Progress
2+
3+
## Phase 1: Core Library Files ✅ COMPLETED
4+
5+
Converted files:
6+
- ✅ package.json - Added "type": "module"
7+
- ✅ lib/codecept.js - Main CodeceptJS class
8+
- ✅ lib/event.js - Event dispatcher
9+
- ✅ lib/output.js - Output formatting
10+
- ✅ lib/utils.js - Utility functions
11+
- ✅ lib/utils/mask_data.js - Data masking utilities
12+
13+
## Phase 2: Helper Files (IN PROGRESS)
14+
15+
Files requiring conversion:
16+
- [ ] lib/helper/Playwright.js
17+
- [ ] lib/helper/Puppeteer.js
18+
- [ ] lib/helper/WebDriver.js
19+
- [ ] lib/helper/Appium.js
20+
- [ ] lib/helper/GraphQL.js
21+
- [ ] lib/helper/AI.js
22+
- [ ] lib/helper/* (other helpers)
23+
24+
## Phase 3: Core Infrastructure
25+
26+
- [ ] lib/container.js
27+
- [ ] lib/workers.js
28+
- [ ] lib/workerStorage.js
29+
- [ ] lib/recorder.js
30+
- [ ] lib/step/*.js
31+
- [ ] lib/listener/*.js
32+
- [ ] lib/plugin/*.js
33+
- [ ] lib/element/WebElement.js
34+
35+
## Phase 4: Command & Mocha Integration
36+
37+
- [ ] lib/command/*.js
38+
- [ ] lib/mocha/*.js
39+
- [ ] lib/data/*.js
40+
41+
## Phase 5: Test Files
42+
43+
- [ ] test/**/*.js (all test files)
44+
45+
## Phase 6: Examples & Templates
46+
47+
- [ ] examples/*.js
48+
- [ ] lib/template/*.js
49+
50+
## Commands to Find Remaining Files
51+
52+
```bash
53+
# Find files with require()
54+
find lib -name "*.js" | xargs grep -l "require("
55+
56+
# Find files with module.exports
57+
find lib -name "*.js" | xargs grep -l "module.exports"
58+
59+
# Count remaining files
60+
find lib -name "*.js" | xargs grep -l "^const .* = require\|^module.exports" | wc -l
61+
```
62+
63+
## TypeScript Configuration
64+
65+
The tsconfig.json will need to be updated to support ESM:
66+
```json
67+
{
68+
"compilerOptions": {
69+
"module": "ES2022",
70+
"target": "ES2022",
71+
"moduleResolution": "node16"
72+
}
73+
}
74+
```
75+
76+
## Testing Strategy
77+
78+
After each phase:
79+
1. Run linter: `npm run lint`
80+
2. Run unit tests: `npm run test:unit`
81+
3. Run integration tests progressively
82+
4. Fix any runtime errors
83+
84+
## Current Status
85+
86+
**Files Converted**: 6
87+
**Estimated Remaining**: ~150
88+
**Completion**: ~4%

lib/element/WebElement.js

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

33
/**
44
* Unified WebElement class that wraps native element instances from different helpers
@@ -324,4 +324,4 @@ class WebElement {
324324
}
325325
}
326326

327-
module.exports = WebElement
327+
export default WebElement

lib/helper/Playwright.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,14 @@ import {
2424
requireWithFallback,
2525
normalizeSpacesInString,
2626
relativeDir,
27-
} = require('../utils')
28-
const { isColorProperty, convertColorToRGBA } = require('../colorUtils')
29-
const ElementNotFound = require('./errors/ElementNotFound')
30-
const RemoteBrowserConnectionRefused = require('./errors/RemoteBrowserConnectionRefused')
31-
const Popup = require('./extras/Popup')
32-
const Console = require('./extras/Console')
33-
const { findReact, findVue, findByPlaywrightLocator } = require('./extras/PlaywrightReactVueLocator')
34-
const WebElement = require('../element/WebElement')
27+
} from '../utils.js'
28+
import { isColorProperty, convertColorToRGBA } from '../colorUtils.js'
29+
import ElementNotFound from './errors/ElementNotFound.js'
30+
import RemoteBrowserConnectionRefused from './errors/RemoteBrowserConnectionRefused.js'
31+
import Popup from './extras/Popup.js'
32+
import Console from './extras/Console.js'
33+
import { findReact, findVue, findByPlaywrightLocator } from './extras/PlaywrightReactVueLocator.js'
34+
import WebElement from '../element/WebElement.js'
3535

3636
let playwright
3737
let perfTiming
@@ -4098,7 +4098,7 @@ class Playwright extends Helper {
40984098
}
40994099
}
41004100

4101-
module.exports = Playwright
4101+
export default Playwright
41024102

41034103
function buildCustomLocatorString(locator) {
41044104
// Note: this.debug not available in standalone function, using console.log

lib/step/comment.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const FuncStep = require('./func')
1+
import FuncStep from './func.js'
22

33
class CommentStep extends FuncStep {
44
constructor(name, comment) {
@@ -7,4 +7,4 @@ class CommentStep extends FuncStep {
77
}
88
}
99

10-
module.exports = CommentStep
10+
export default CommentStep

lib/workerStorage.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { isMainThread, parentPort } from 'worker_threads'
2+
import Container from './container.js'
23

34
const workerObjects = {}
45
const shareEvent = 'share'
@@ -7,8 +8,7 @@ const invokeWorkerListeners = workerObj => {
78
const { threadId } = workerObj
89
workerObj.on('message', messageData => {
910
if (messageData.event === shareEvent) {
10-
const Container = require('./container');
11-
Container.share(messageData.data);
11+
Container.share(messageData.data)
1212
}
1313
})
1414
workerObj.on('exit', () => {

0 commit comments

Comments
 (0)