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
77const commandFlags = {
88 ai : {
@@ -56,19 +56,28 @@ program.version(Codecept.version())
5656program
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
6164program
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
6874program
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
7382program
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
8395program
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
89104program
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
96114program
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
103124program
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
110134program
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
120147program
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
126156program
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
132165program
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
139175program
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
145184program
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
151193program
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
191236program
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
210258program
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
236287program
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
242296program
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
259316program
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
297357program . on ( 'command:*' , cmd => {
298358 console . log ( `\nUnknown command ${ cmd } \n` )
0 commit comments