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 as generateTest } from './generate.js'
14+ const isLocal = installedLocally ( )
1515
1616const defaultConfig = {
1717 tests : './*_test.js' ,
@@ -21,10 +21,14 @@ const defaultConfig = {
2121}
2222
2323const helpers = [ 'Playwright' , 'WebDriver' , 'Puppeteer' , 'REST' , 'GraphQL' , 'Appium' , 'TestCafe' ]
24- const translations = Object . keys ( require ( '../../translations' ) )
2524
26- const noTranslation = 'English (no localization)'
27- translations . unshift ( noTranslation )
25+ async function getTranslations ( ) {
26+ const translationsModule = await import ( '../../translations/index.js' )
27+ const translations = Object . keys ( translationsModule . default || translationsModule )
28+ const noTranslation = 'English (no localization)'
29+ translations . unshift ( noTranslation )
30+ return translations
31+ }
2832
2933const packages = [ ]
3034let isTypeScript = false
@@ -67,8 +71,9 @@ export = function() {
6771}
6872`
6973
70- module . exports = function ( initPath ) {
74+ export default async function ( initPath ) {
7175 const testsPath = getTestRoot ( initPath )
76+ const translations = await getTranslations ( )
7277
7378 print ( )
7479 print ( ` Welcome to ${ colors . magenta . bold ( 'CodeceptJS' ) } initialization tool` )
@@ -207,9 +212,9 @@ module.exports = function (initPath) {
207212 fs . writeFileSync ( path . join ( testsPath , stepFile ) , extension === 'ts' ? defaultActorTs : defaultActor )
208213
209214 if ( isTypeScript ) {
210- config . include = _actorTranslation ( './steps_file' , config . translation )
215+ config . include = await _actorTranslation ( './steps_file' , config . translation , translations )
211216 } else {
212- config . include = _actorTranslation ( stepFile , config . translation )
217+ config . include = await _actorTranslation ( stepFile , config . translation , translations )
213218 }
214219
215220 print ( `Steps file created at ${ stepFile } ` )
@@ -390,7 +395,7 @@ function install(dependencies) {
390395 return true
391396}
392397
393- function _actorTranslation ( stepFile , translationSelected ) {
398+ async function _actorTranslation ( stepFile , translationSelected , translations ) {
394399 let actor
395400
396401 for ( const translationAvailable of translations ) {
@@ -399,7 +404,8 @@ function _actorTranslation(stepFile, translationSelected) {
399404 }
400405
401406 if ( translationSelected === translationAvailable ) {
402- const nameOfActor = require ( '../../translations' ) [ translationAvailable ] . I
407+ const translationsModule = await import ( '../../translations/index.js' )
408+ const nameOfActor = ( translationsModule . default || translationsModule ) [ translationAvailable ] . I
403409
404410 actor = {
405411 [ nameOfActor ] : stepFile ,
0 commit comments