Skip to content

Commit d43107b

Browse files
author
DavertMik
committed
fixed commands
1 parent 14d5d58 commit d43107b

File tree

8 files changed

+105
-99
lines changed

8 files changed

+105
-99
lines changed

lib/command/definitions.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
const fs = require('fs')
2-
const path = require('path')
1+
import fs from 'fs'
2+
import path from 'path'
33

4-
const { getConfig, getTestRoot } = require('./utils')
5-
const Codecept = require('../codecept')
6-
const container = require('../container')
7-
const output = require('../output')
4+
import { getConfig, getTestRoot } from './utils.js'
5+
import Codecept from '../codecept.js'
6+
import container from '../container.js'
7+
import output from '../output.js'
88
const actingHelpers = [...container.STANDARD_ACTING_HELPERS, 'REST']
99

1010
/**
@@ -86,11 +86,11 @@ const helperNames = []
8686
/** @type {Array<string>} */
8787
const customHelpers = []
8888

89-
module.exports = function (genPath, options) {
89+
export default async function (genPath, options) {
9090
const configFile = options.config || genPath
9191
/** @type {string} */
9292
const testsPath = getTestRoot(configFile)
93-
const config = getConfig(configFile)
93+
const config = await getConfig(configFile)
9494
if (!config) return
9595

9696
/** @type {Object<string, string>} */

lib/command/dryRun.js

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
const { getConfig, getTestRoot } = require('./utils')
2-
const Config = require('../config')
3-
const Codecept = require('../codecept')
4-
const output = require('../output')
5-
const event = require('../event')
6-
const store = require('../store')
7-
const Container = require('../container')
8-
9-
module.exports = async function (test, options) {
1+
import { getConfig, getTestRoot } from './utils.js'
2+
import Config from '../config.js'
3+
import Codecept from '../codecept.js'
4+
import output from '../output.js'
5+
import event from '../event.js'
6+
import store from '../store.js'
7+
import Container from '../container.js'
8+
9+
export default async function (test, options) {
1010
if (options.grep) process.env.grep = options.grep
1111
const configFile = options.config
1212
let codecept
1313

1414
const testRoot = getTestRoot(configFile)
15-
let config = getConfig(configFile)
15+
let config = await getConfig(configFile)
1616
if (options.override) {
1717
config = Config.append(JSON.parse(options.override))
1818
}
@@ -35,7 +35,7 @@ module.exports = async function (test, options) {
3535
store.dryRun = true
3636

3737
if (!options.steps && !options.verbose && !options.debug) {
38-
printTests(codecept.testFiles)
38+
await printTests(codecept.testFiles)
3939
return
4040
}
4141
event.dispatcher.on(event.all.result, printFooter)
@@ -46,9 +46,9 @@ module.exports = async function (test, options) {
4646
}
4747
}
4848

49-
function printTests(files) {
50-
const figures = require('figures')
51-
const colors = require('chalk')
49+
async function printTests(files) {
50+
const { default: figures } = await import('figures')
51+
const { default: colors } = await import('chalk')
5252

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

lib/command/generate.js

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
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 { fileExists, ucfirst, lcfirst, beautify } = require('../utils')
7-
const output = require('../output')
8-
const generateDefinitions = require('./definitions')
9-
const { getConfig, getTestRoot, safeFileWrite, readConfig } = require('./utils')
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 { fileExists, ucfirst, lcfirst, beautify } from '../utils.js'
7+
import output from '../output.js'
8+
import generateDefinitions from './definitions.js'
9+
import { getConfig, getTestRoot, safeFileWrite, readConfig } from './utils.js'
1010

1111
let extension = 'js'
1212

@@ -18,10 +18,10 @@ Scenario('test something', async ({ {{actor}} }) => {
1818
`
1919

2020
// generates empty test
21-
module.exports.test = function (genPath) {
21+
export async function test(genPath) {
2222
const testsPath = getTestRoot(genPath)
2323
global.codecept_dir = testsPath
24-
const config = getConfig(testsPath)
24+
const config = await getConfig(testsPath)
2525
if (!config) return
2626

2727
output.print('Creating a new test...')
@@ -105,9 +105,9 @@ module.exports = new {{name}}();
105105
export = {{name}};
106106
`
107107

108-
module.exports.pageObject = function (genPath, opts) {
108+
export async function pageObject(genPath, opts) {
109109
const testsPath = getTestRoot(genPath)
110-
const config = getConfig(testsPath)
110+
const config = await getConfig(testsPath)
111111
const kind = opts.T || 'page'
112112
if (!config) return
113113

@@ -225,7 +225,7 @@ class {{name}} extends Helper {
225225
module.exports = {{name}};
226226
`
227227

228-
module.exports.helper = function (genPath) {
228+
export async function helper(genPath) {
229229
const testsPath = getTestRoot(genPath)
230230

231231
output.print('Creating a new helper')
@@ -267,7 +267,7 @@ helpers: {
267267

268268
const healTemplate = fs.readFileSync(path.join(__dirname, '../template/heal.js'), 'utf8').toString()
269269

270-
module.exports.heal = function (genPath) {
270+
export async function heal(genPath) {
271271
const testsPath = getTestRoot(genPath)
272272

273273
let configFile = path.join(testsPath, `codecept.conf.${extension}`)

lib/command/info.js

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

3-
const { getConfig, getTestRoot } = require('./utils')
4-
const Codecept = require('../codecept')
5-
const outputModule = require('../output')
3+
import { getConfig, getTestRoot } from './utils.js'
4+
import Codecept from '../codecept.js'
5+
import outputModule from '../output.js'
66
const output = outputModule.default || outputModule
7-
const { execSync } = require('child_process')
7+
import { execSync } from 'child_process'
88

99
async function getPlaywrightBrowsers() {
1010
try {
@@ -41,9 +41,9 @@ async function getOsBrowsers() {
4141
].join(', ')
4242
}
4343

44-
module.exports = async function (path) {
44+
export default async function (path) {
4545
const testsPath = getTestRoot(path)
46-
const config = getConfig(testsPath)
46+
const config = await getConfig(testsPath)
4747
const codecept = new Codecept(config, {})
4848
codecept.init(testsPath)
4949

@@ -74,7 +74,7 @@ module.exports = async function (path) {
7474
output.print('***************************************')
7575
}
7676

77-
module.exports.getMachineInfo = async () => {
77+
export const getMachineInfo = async () => {
7878
const info = {
7979
nodeInfo: await envinfo.helpers.getNodeInfo(),
8080
osInfo: await envinfo.helpers.getOSInfo(),

lib/command/init.js

Lines changed: 28 additions & 22 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 as generateTest } from './generate.js'
14+
const isLocal = installedLocally()
1515

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

2323
const 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

2933
const packages = []
3034
let 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,

lib/command/list.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
const { getConfig, getTestRoot } = require('./utils')
2-
const Codecept = require('../codecept')
3-
const container = require('../container')
4-
const { getParamsToString } = require('../parser')
5-
const { methodsOfObject } = require('../utils')
6-
const output = require('../output')
1+
import { getConfig, getTestRoot } from './utils.js'
2+
import Codecept from '../codecept.js'
3+
import container from '../container.js'
4+
import { getParamsToString } from '../parser.js'
5+
import { methodsOfObject } from '../utils.js'
6+
import output from '../output.js'
77

8-
module.exports = function (path) {
8+
export default async function (path) {
99
const testsPath = getTestRoot(path)
10-
const config = getConfig(testsPath)
10+
const config = await getConfig(testsPath)
1111
const codecept = new Codecept(config, {})
1212
codecept.init(testsPath)
1313

lib/command/run.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
const { getConfig, printError, getTestRoot, createOutputDir } = require('./utils')
2-
const Config = require('../config')
3-
const store = require('../store')
4-
const Codecept = require('../codecept')
1+
import { getConfig, printError, getTestRoot, createOutputDir } from './utils.js'
2+
import Config from '../config.js'
3+
import store from '../store.js'
4+
import Codecept from '../codecept.js'
55

66
module.exports = async function (test, options) {
77
// registering options globally to use in config
@@ -16,7 +16,7 @@ module.exports = async function (test, options) {
1616

1717
const configFile = options.config
1818

19-
let config = getConfig(configFile)
19+
let config = await getConfig(configFile)
2020
if (options.override) {
2121
config = Config.append(JSON.parse(options.override))
2222
}
@@ -32,7 +32,7 @@ module.exports = async function (test, options) {
3232

3333
if (options.verbose) {
3434
global.debugMode = true
35-
const { getMachineInfo } = require('./info')
35+
const { getMachineInfo } = await import('./info.js')
3636
await getMachineInfo()
3737
}
3838

0 commit comments

Comments
 (0)