Skip to content

Commit a4f44c7

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

File tree

138 files changed

+1166
-858
lines changed

Some content is hidden

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

138 files changed

+1166
-858
lines changed

.mocharc.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
module.exports = {
1+
export default {
22
"require": "./test/support/setup.js"
33
}

bin/codecept.js

Lines changed: 84 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#!/usr/bin/env node
2-
const program = require('commander')
3-
const Codecept = require('../lib/codecept')
4-
const { print, error } = require('../lib/output')
5-
const { printError } = require('../lib/command/utils')
2+
import { program } from 'commander'
3+
import Codecept from '../lib/codecept.js'
4+
import { print, error } from '../lib/output.js'
5+
import { printError } from '../lib/command/utils.js'
66

77
const commandFlags = {
88
ai: {
@@ -56,19 +56,28 @@ program.version(Codecept.version())
5656
program
5757
.command('init [path]')
5858
.description('Creates dummy config in current dir or [path]')
59-
.action(errorHandler(require('../lib/command/init')))
59+
.action(errorHandler(async (...args) => {
60+
const { default: initCmd } = await import('../lib/command/init.js')
61+
return initCmd(...args)
62+
}))
6063

6164
program
6265
.command('check')
6366
.option(commandFlags.config.flag, commandFlags.config.description)
6467
.description('Checks configuration and environment before running tests')
6568
.option('-t, --timeout [ms]', 'timeout for checks in ms, 50000 by default')
66-
.action(errorHandler(require('../lib/command/check')))
69+
.action(errorHandler(async (...args) => {
70+
const { default: checkCmd } = await import('../lib/command/check.js')
71+
return checkCmd(...args)
72+
}))
6773

6874
program
6975
.command('migrate [path]')
7076
.description('Migrate json config to js config in current dir or [path]')
71-
.action(errorHandler(require('../lib/command/configMigrate')))
77+
.action(errorHandler(async (...args) => {
78+
const { default: cmd } = await import('../lib/command/configMigrate.js')
79+
return cmd(...args)
80+
}))
7281

7382
program
7483
.command('shell [path]')
@@ -78,34 +87,49 @@ program
7887
.option(commandFlags.profile.flag, commandFlags.profile.description)
7988
.option(commandFlags.ai.flag, commandFlags.ai.description)
8089
.option(commandFlags.config.flag, commandFlags.config.description)
81-
.action(errorHandler(require('../lib/command/interactive')))
90+
.action(errorHandler(async (...args) => {
91+
const { default: cmd } = await import('../lib/command/interactive.js')
92+
return cmd(...args)
93+
}))
8294

8395
program
8496
.command('list [path]')
8597
.alias('l')
8698
.description('List all actions for I.')
87-
.action(errorHandler(require('../lib/command/list')))
99+
.action(errorHandler(async (...args) => {
100+
const { default: cmd } = await import('../lib/command/list.js')
101+
return cmd(...args)
102+
}))
88103

89104
program
90105
.command('def [path]')
91106
.description('Generates TypeScript definitions for all I actions.')
92107
.option(commandFlags.config.flag, commandFlags.config.description)
93108
.option('-o, --output [folder]', 'target folder to paste definitions')
94-
.action(errorHandler(require('../lib/command/definitions')))
109+
.action(errorHandler(async (...args) => {
110+
const { default: cmd } = await import('../lib/command/definitions.js')
111+
return cmd(...args)
112+
}))
95113

96114
program
97115
.command('gherkin:init [path]')
98116
.alias('bdd:init')
99117
.description('Prepare CodeceptJS to run feature files.')
100118
.option(commandFlags.config.flag, commandFlags.config.description)
101-
.action(errorHandler(require('../lib/command/gherkin/init')))
119+
.action(errorHandler(async (...args) => {
120+
const { default: cmd } = await import('../lib/command/gherkin/init.js')
121+
return cmd(...args)
122+
}))
102123

103124
program
104125
.command('gherkin:steps [path]')
105126
.alias('bdd:steps')
106127
.description('Prints all defined gherkin steps.')
107128
.option(commandFlags.config.flag, commandFlags.config.description)
108-
.action(errorHandler(require('../lib/command/gherkin/steps')))
129+
.action(errorHandler(async (...args) => {
130+
const { default: cmd } = await import('../lib/command/gherkin/steps.js')
131+
return cmd(...args)
132+
}))
109133

110134
program
111135
.command('gherkin:snippets [path]')
@@ -115,38 +139,56 @@ program
115139
.option(commandFlags.config.flag, commandFlags.config.description)
116140
.option('--feature [file]', 'feature files(s) to scan')
117141
.option('--path [file]', 'file in which to place the new snippets')
118-
.action(errorHandler(require('../lib/command/gherkin/snippets')))
142+
.action(errorHandler(async (...args) => {
143+
const { default: cmd } = await import('../lib/command/gherkin/snippets.js')
144+
return cmd(...args)
145+
}))
119146

120147
program
121148
.command('generate:test [path]')
122149
.alias('gt')
123150
.description('Generates an empty test')
124-
.action(errorHandler(require('../lib/command/generate').test))
151+
.action(errorHandler(async (...args) => {
152+
const { test } = await import('../lib/command/generate.js')
153+
return test(...args)
154+
}))
125155

126156
program
127157
.command('generate:pageobject [path]')
128158
.alias('gpo')
129159
.description('Generates an empty page object')
130-
.action(errorHandler(require('../lib/command/generate').pageObject))
160+
.action(errorHandler(async (...args) => {
161+
const { pageObject } = await import('../lib/command/generate.js')
162+
return pageObject(...args)
163+
}))
131164

132165
program
133166
.command('generate:object [path]')
134167
.alias('go')
135168
.option('--type, -t [kind]', 'type of object to be created')
136169
.description('Generates an empty support object (page/step/fragment)')
137-
.action(errorHandler(require('../lib/command/generate').pageObject))
170+
.action(errorHandler(async (...args) => {
171+
const { pageObject } = await import('../lib/command/generate.js')
172+
return pageObject(...args)
173+
}))
138174

139175
program
140176
.command('generate:helper [path]')
141177
.alias('gh')
142178
.description('Generates a new helper')
143-
.action(errorHandler(require('../lib/command/generate').helper))
179+
.action(errorHandler(async (...args) => {
180+
const { helper } = await import('../lib/command/generate.js')
181+
return helper(...args)
182+
}))
144183

145184
program
146185
.command('generate:heal [path]')
147186
.alias('gr')
148187
.description('Generates basic heal recipes')
149-
.action(errorHandler(require('../lib/command/generate').heal))
188+
.action(errorHandler(async (...args) => {
189+
const { heal } = await import('../lib/command/generate.js')
190+
return heal(...args)
191+
}))
150192

151193
program
152194
.command('run [test]')
@@ -186,7 +228,10 @@ program
186228
.option('--recursive', 'include sub directories')
187229
.option('--trace', 'trace function calls')
188230
.option('--child <string>', 'option for child processes')
189-
.action(errorHandler(require('../lib/command/run')))
231+
.action(errorHandler(async (...args) => {
232+
const { default: cmd } = await import('../lib/command/run.js')
233+
return cmd(...args)
234+
}))
190235

191236
program
192237
.command('run-workers <workers> [selectedRuns...]')
@@ -205,7 +250,10 @@ program
205250
.option('-p, --plugins <k=v,k2=v2,...>', 'enable plugins, comma-separated')
206251
.option('-O, --reporter-options <k=v,k2=v2,...>', 'reporter-specific options')
207252
.option('-R, --reporter <name>', 'specify the reporter to use')
208-
.action(errorHandler(require('../lib/command/run-workers')))
253+
.action(errorHandler(async (...args) => {
254+
const { default: cmd } = await import('../lib/command/run-workers.js')
255+
return cmd(...args)
256+
}))
209257

210258
program
211259
.command('run-multiple [suites...]')
@@ -231,13 +279,19 @@ program
231279
// mocha options
232280
.option('--colors', 'force enabling of colors')
233281

234-
.action(errorHandler(require('../lib/command/run-multiple')))
282+
.action(errorHandler(async (...args) => {
283+
const { default: cmd } = await import('../lib/command/run-multiple.js')
284+
return cmd(...args)
285+
}))
235286

236287
program
237288
.command('info [path]')
238289
.description('Print debugging information concerning the local environment')
239290
.option('-c, --config', 'your config file path')
240-
.action(errorHandler(require('../lib/command/info')))
291+
.action(errorHandler(async (...args) => {
292+
const { default: cmd } = await import('../lib/command/info.js')
293+
return cmd(...args)
294+
}))
241295

242296
program
243297
.command('dry-run [test]')
@@ -254,7 +308,10 @@ program
254308
.option(commandFlags.steps.flag, commandFlags.steps.description)
255309
.option(commandFlags.verbose.flag, commandFlags.verbose.description)
256310
.option(commandFlags.debug.flag, commandFlags.debug.description)
257-
.action(errorHandler(require('../lib/command/dryRun')))
311+
.action(errorHandler(async (...args) => {
312+
const { default: cmd } = await import('../lib/command/dryRun.js')
313+
return cmd(...args)
314+
}))
258315

259316
program
260317
.command('run-rerun [test]')
@@ -292,7 +349,10 @@ program
292349
.option('--trace', 'trace function calls')
293350
.option('--child <string>', 'option for child processes')
294351

295-
.action(require('../lib/command/run-rerun'))
352+
.action(errorHandler(async (...args) => {
353+
const { default: cmd } = await import('../lib/command/run-rerun.js')
354+
return cmd(...args)
355+
}))
296356

297357
program.on('command:*', cmd => {
298358
console.log(`\nUnknown command ${cmd}\n`)

lib/actor.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
const Step = require('./step')
2-
const MetaStep = require('./step/meta')
3-
const recordStep = require('./step/record')
4-
const container = require('./container')
5-
const { methodsOfObject } = require('./utils')
6-
const { TIMEOUT_ORDER } = require('./timeout')
7-
const event = require('./event')
8-
const store = require('./store')
9-
const output = require('./output')
1+
import Step from './step.js'
2+
import MetaStep from './step/meta.js'
3+
import recordStep from './step/record.js'
4+
import container from './container.js'
5+
import { methodsOfObject } from './utils.js'
6+
import { TIMEOUT_ORDER } from './timeout.js'
7+
import event from './event.js'
8+
import store from './store.js'
9+
import output from './output.js'
1010

1111
/**
1212
* @interface
@@ -71,7 +71,7 @@ class Actor {
7171
* Wraps helper methods into promises.
7272
* @ignore
7373
*/
74-
module.exports = function (obj = {}) {
74+
export default function (obj = {}) {
7575
const actor = container.actor() || new Actor()
7676

7777
// load all helpers once container initialized

lib/ai.js

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
const debug = require('debug')('codeceptjs:ai')
2-
const output = require('./output')
3-
const event = require('./event')
4-
const { removeNonInteractiveElements, minifyHtml, splitByChunks } = require('./html')
1+
import debug from 'debug';
2+
import output from './output.js'
3+
import event from './event.js'
4+
import { removeNonInteractiveElements, minifyHtml, splitByChunks } from './html.js'
5+
6+
const aiDebug = debug('codeceptjs:ai');
57

68
const defaultHtmlConfig = {
79
maxLength: 50000,
@@ -43,7 +45,7 @@ const defaultPrompts = {
4345
4446
const { I } = inject();
4547
46-
module.exports = {
48+
const aiModule = {
4749
4850
// setting locators
4951
element1: '#selector',
@@ -78,7 +80,7 @@ class AiAssistant {
7880
}
7981

8082
enable(config = {}) {
81-
debug('Enabling AI assistant')
83+
aiDebug('Enabling AI assistant')
8284
this.isEnabled = true
8385

8486
const { html, prompts, ...aiConfig } = config
@@ -87,7 +89,7 @@ class AiAssistant {
8789
this.htmlConfig = Object.assign(defaultHtmlConfig, html)
8890
this.prompts = Object.assign(defaultPrompts, prompts)
8991

90-
debug('Config', this.config)
92+
aiDebug('Config', this.config)
9193
}
9294

9395
reset() {
@@ -120,7 +122,7 @@ class AiAssistant {
120122

121123
checkRequestFn() {
122124
if (!this.isEnabled) {
123-
debug('AI assistant is disabled')
125+
aiDebug('AI assistant is disabled')
124126
return
125127
}
126128

@@ -172,7 +174,7 @@ class AiAssistant {
172174

173175
try {
174176
this.checkRequestFn()
175-
debug('Request', messages)
177+
aiDebug('Request', messages)
176178

177179
this.response = null
178180

@@ -183,12 +185,12 @@ class AiAssistant {
183185
const executionTimeInSeconds = endTime[0] + endTime[1] / 1e9
184186

185187
this.totalTime += Math.round(executionTimeInSeconds)
186-
debug('AI response time', executionTimeInSeconds)
187-
debug('Response', this.response)
188+
aiDebug('AI response time', executionTimeInSeconds)
189+
aiDebug('Response', this.response)
188190
this.stopWhenReachingTokensLimit()
189191
return this.response
190192
} catch (err) {
191-
debug(err.response)
193+
aiDebug(err.response)
192194
output.print('')
193195
output.error(`AI service error: ${err.message}`)
194196
if (err?.response?.data?.error?.code) output.error(err?.response?.data?.error?.code)
@@ -205,7 +207,7 @@ class AiAssistant {
205207
await this.setHtmlContext(failureContext.html)
206208

207209
if (!this.minifiedHtml) {
208-
debug('HTML context is empty after removing non-interactive elements & minification')
210+
aiDebug('HTML context is empty after removing non-interactive elements & minification')
209211
return []
210212
}
211213

@@ -267,7 +269,7 @@ class AiAssistant {
267269
if (!response) return
268270
snippets.push(...this.config.response(response))
269271

270-
debug(snippets[0])
272+
aiDebug(snippets[0])
271273

272274
return snippets[0]
273275
}
@@ -304,4 +306,5 @@ function parseCodeBlocks(response) {
304306
return modifiedSnippets.filter(snippet => !!snippet)
305307
}
306308

307-
module.exports = new AiAssistant()
309+
export default new AiAssistant()
310+
;

lib/assert.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,4 +69,4 @@ class Assertion {
6969
}
7070
}
7171

72-
module.exports = Assertion;
72+
export default Assertion;

0 commit comments

Comments
 (0)