Skip to content

Commit a08063f

Browse files
Copilotkobenguyent
andcommitted
Changes before error encountered
Co-authored-by: kobenguyent <[email protected]>
1 parent a4f44c7 commit a08063f

File tree

231 files changed

+901
-755
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

231 files changed

+901
-755
lines changed

lib/actor.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,9 @@ class Actor {
5959
*/
6060
retry(opts) {
6161
console.log('I.retry() is deprecated, use step.retry() instead')
62-
const retryStep = require('./step/retry')
63-
retryStep(opts)
62+
import('./step/retry.js').then(retryStep => {
63+
retryStep.default(opts)
64+
})
6465
return this
6566
}
6667
}

lib/ai.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ class AiAssistant {
138138
139139
ai: {
140140
request: async (messages) => {
141-
const OpenAI = require('openai');
141+
import OpenAI from 'openai'
142142
const openai = new OpenAI({ apiKey: process.env['OPENAI_API_KEY'] })
143143
const response = await openai.chat.completions.create({
144144
model: 'gpt-4o-mini',

lib/assert.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const AssertionFailedError = require('./assert/error');
1+
import AssertionFailedError from './assert/error.js'
22

33
/**
44
* Abstract assertion class introduced for more verbose and customizable messages.

lib/assert/empty.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,16 @@ class EmptinessAssertion extends Assertion {
3535
}
3636
}
3737

38+
const EmptyAssertion = EmptinessAssertion
39+
const empty = subject => new EmptinessAssertion({ subject })
40+
3841
const emptyModule = {
3942
Assertion: EmptinessAssertion,
4043
empty: subject => new EmptinessAssertion({ subject }),
4144
}
4245

4346

4447
// Export named functions
45-
export { Assertion, empty }
48+
export { EmptyAssertion as Assertion, empty }
4649

4750
export default emptyModule

lib/codecept.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ class Codecept {
6363
await this.initGlobals(dir)
6464
// initializing listeners
6565
container.create(this.config, this.opts)
66-
this.runHooks()
66+
await this.runHooks()
6767
}
6868

6969
/**
@@ -128,17 +128,17 @@ class Codecept {
128128
/**
129129
* Executes hooks.
130130
*/
131-
runHooks() {
131+
async runHooks() {
132132
// default hooks
133-
runHook(require('./listener/store'))
134-
runHook(require('./listener/steps'))
135-
runHook(require('./listener/config'))
136-
runHook(require('./listener/result'))
137-
runHook(require('./listener/helpers'))
138-
runHook(require('./listener/globalTimeout'))
139-
runHook(require('./listener/globalRetry'))
140-
runHook(require('./listener/exit'))
141-
runHook(require('./listener/emptyRun'))
133+
runHook((await import('./listener/store.js')).default)
134+
runHook((await import('./listener/steps.js')).default)
135+
runHook((await import('./listener/config.js')).default)
136+
runHook((await import('./listener/result.js')).default)
137+
runHook((await import('./listener/helpers.js')).default)
138+
runHook((await import('./listener/globalTimeout.js')).default)
139+
runHook((await import('./listener/globalRetry.js')).default)
140+
runHook((await import('./listener/exit.js')).default)
141+
runHook((await import('./listener/emptyRun.js')).default)
142142

143143
// custom hooks (previous iteration of plugins)
144144
this.config.hooks.forEach(hook => runHook(hook))

lib/command/dryRun.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ export default async function (test, options) {
4747
}
4848

4949
function printTests(files) {
50-
const figures = require('figures')
51-
const colors = require('chalk')
50+
import figures from 'figures'
51+
import colors from 'chalk'
5252

5353
output.print(output.styles.debug(`Tests from ${global.codecept_dir}:`))
5454
output.print()

lib/command/generate.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ module.exports.test = function (genPath) {
5555
if (!fileExists(dir)) mkdirp.sync(dir)
5656
let testContent = testTemplate.replace('{{feature}}', result.feature)
5757

58-
const container = require('../container')
58+
import container from '../container.js'
5959
container.create(config, {})
6060
// translate scenario test
6161
if (container.translation().loaded) {
@@ -103,7 +103,7 @@ class {{name}} {
103103
}
104104
105105
// For inheritance
106-
module.exports = new {{name}}();
106+
export default new {{name}}();
107107
export = {{name}};
108108
`
109109

@@ -157,7 +157,7 @@ module.exports.pageObject = function (genPath, opts) {
157157
// relative path
158158
actorPath = path.relative(dir, path.dirname(path.join(testsPath, actorPath))) + actorPath.substring(1) // get an upper level
159159
}
160-
actor = `require('${actorPath}')`
160+
actor = `(await import('${actorPath}')).default`
161161
}
162162

163163
const name = lcfirst(result.name) + ucfirst(kind)
@@ -199,7 +199,7 @@ module.exports.pageObject = function (genPath, opts) {
199199
})
200200
}
201201

202-
const helperTemplate = `const Helper = require('@codeceptjs/helper');
202+
const helperTemplate = `const Helper = (await import('@codeceptjs/helper')).default;
203203
204204
class {{name}} extends Helper {
205205
@@ -224,7 +224,7 @@ class {{name}} extends Helper {
224224
225225
}
226226
227-
module.exports = {{name}};
227+
export default {{name}};
228228
`
229229

230230
module.exports.helper = function (genPath) {
@@ -284,7 +284,7 @@ module.exports.heal = function (genPath) {
284284
output.print('Require this file in the config file and enable heal plugin:')
285285
output.print('--------------------------')
286286
output.print(`
287-
require('./heal')
287+
(await import('./heal.js')).default
288288
289289
export const config = {
290290
// ...

lib/command/init.js

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
const colors = require('chalk')
2-
const fs = require('fs')
3-
const inquirer = require('inquirer')
4-
const mkdirp = require('mkdirp')
5-
const path = require('path')
6-
const { inspect } = require('util')
7-
const spawn = require('cross-spawn')
8-
9-
const { print, success, error } = require('../output')
10-
const { fileExists, beautify, installedLocally } = require('../utils')
11-
const { getTestRoot } = require('./utils')
12-
const generateDefinitions = require('./definitions')
13-
const { test: generateTest } = require('./generate')
14-
const isLocal = require('../utils').installedLocally()
1+
import colors from 'chalk'
2+
import fs from 'fs'
3+
import inquirer from 'inquirer'
4+
import mkdirp from 'mkdirp'
5+
import path from 'path'
6+
import { inspect } from 'util'
7+
import spawn from 'cross-spawn'
8+
9+
import { print, success, error } from '../output.js'
10+
import { fileExists, beautify, installedLocally } from '../utils.js'
11+
import { getTestRoot } from './utils.js'
12+
import generateDefinitions from './definitions.js'
13+
import { test: generateTest } from './generate.js'
14+
import isLocal from '../utils.js'
1515

1616
const defaultConfig = {
1717
tests: './*_test.js',
@@ -21,7 +21,7 @@ const defaultConfig = {
2121
}
2222

2323
const helpers = ['Playwright', 'WebDriver', 'Puppeteer', 'REST', 'GraphQL', 'Appium', 'TestCafe']
24-
const translations = Object.keys(require('../../translations'))
24+
const translations = Object.keys((await import('../../translations.js')).default)
2525

2626
const noTranslation = 'English (no localization)'
2727
translations.unshift(noTranslation)
@@ -30,7 +30,7 @@ const packages = []
3030
let isTypeScript = false
3131
let extension = 'js'
3232

33-
const requireCodeceptConfigure = "const { setHeadlessWhen, setCommonPlugins } = require('@codeceptjs/configure');"
33+
const requireCodeceptConfigure = "const { setHeadlessWhen, setCommonPlugins } = (await import('@codeceptjs/configure')).default;"
3434
const importCodeceptConfigure = "import { setHeadlessWhen, setCommonPlugins } from '@codeceptjs/configure';"
3535

3636
const configHeader = `
@@ -45,7 +45,7 @@ setCommonPlugins();
4545

4646
const defaultActor = `// in this file you can append custom step methods to 'I' object
4747
48-
module.exports = function() {
48+
export default function() {
4949
return actor({
5050
5151
// Define custom steps here, use 'this' to access default methods of I.
@@ -67,7 +67,7 @@ export = function() {
6767
}
6868
`
6969

70-
module.exports = function (initPath) {
70+
export default function (initPath) {
7171
const testsPath = getTestRoot(initPath)
7272

7373
print()
@@ -332,7 +332,7 @@ module.exports = function (initPath) {
332332
delete helperResult.Playwright_show
333333

334334
helperResult.Playwright_electron = {
335-
executablePath: '// require("electron") or require("electron-forge")',
335+
executablePath: '// (await import('electron')).default or (await import('electron-forge')).default',
336336
args: ['path/to/your/main.js'],
337337
}
338338
}
@@ -399,7 +399,7 @@ function _actorTranslation(stepFile, translationSelected) {
399399
}
400400

401401
if (translationSelected === translationAvailable) {
402-
const nameOfActor = require('../../translations')[translationAvailable].I
402+
import nameOfActor from '../../translations.js'
403403

404404
actor = {
405405
[nameOfActor]: stepFile,

lib/command/interactive.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export default async function (path, options) {
5151
break
5252
}
5353
}
54-
require('../pause')()
54+
(await import('../pause.js')).default()
5555
// recorder.catchWithoutStop((err) => console.log(err.stack));
5656
recorder.add(() => event.emit(event.test.after, {}))
5757
recorder.add(() => event.emit(event.suite.after, {}))

lib/command/run-multiple/collection.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
const { createChunks } = require('./chunk');
2-
const { createRun } = require('./run');
1+
import { createChunks } from './chunk.js'
2+
import { createRun } from './run.js'
33

44
/**
55
* Bootstraps a collection of runs, it combines user defined selection of runs

0 commit comments

Comments
 (0)