diff --git a/bin/codecept.js b/bin/codecept.js index 77407faeb..77886cf31 100755 --- a/bin/codecept.js +++ b/bin/codecept.js @@ -31,7 +31,7 @@ const errorHandler = (fn) => async (...args) => { }; if (process.versions.node && process.versions.node.split('.') && process.versions.node.split('.')[0] < 12) { - outputLib.output.error('NodeJS >= 12 is required to run.'); + outputLib.output.output.error('NodeJS >= 12 is required to run.'); outputLib.print(); outputLib.print('Please upgrade your NodeJS engine'); outputLib.print(`Current NodeJS version: ${process.version}`); diff --git a/lib/ai.js b/lib/ai.js index 8d1c24480..900c4eb26 100644 --- a/lib/ai.js +++ b/lib/ai.js @@ -1,11 +1,9 @@ import { Configuration, OpenAIApi } from 'openai'; -import createDebugMessages from 'debug'; +import debug from 'debug'; import config from './config.js'; import * as output from './output.js'; import { removeNonInteractiveElements, minifyHtml, splitByChunks } from './html.js'; -const debug = createDebugMessages('codeceptjs'); - debug('codeceptjs:ai'); const defaultConfig = { diff --git a/lib/codecept.js b/lib/codecept.js index 03479f364..556d57b25 100644 --- a/lib/codecept.js +++ b/lib/codecept.js @@ -43,9 +43,6 @@ import listener01234 from './listener/timeout.js'; import listener012345 from './listener/exit.js'; -import 'chai/register-assert.js'; -import 'chai/register-expect.js'; - const __dirname = dirname(fileURLToPath(import.meta.url)); const require = createRequire(import.meta.url); @@ -121,7 +118,7 @@ export default class Codecept { global.inject = container.support; global.share = container.share; global.secret = secret; - global.codecept_debug = output.output.debug; + global.codecept_debug = output.debug; global.codeceptjs = index; // load all objects global.Given = stepDefinitions.Given; global.When = stepDefinitions.When; diff --git a/lib/container.js b/lib/container.js index 403d54ac3..eb3231374 100644 --- a/lib/container.js +++ b/lib/container.js @@ -175,11 +175,7 @@ function createHelpers(config) { // check if the helper is the built-in, use the require() syntax. if (moduleName.startsWith('./helper/')) { const __dirname = dirname(fileURLToPath(import.meta.url)); - try { - HelperClass = importSync(path.resolve(__dirname, moduleName)).default; - } catch (e) { - HelperClass = importSync(path.resolve(__dirname, moduleName)); - } + HelperClass = importSync(path.resolve(__dirname, moduleName)).default; } else { // check if the new syntax export default HelperName is used and loads the Helper, otherwise loads the module that used old syntax export = HelperName. HelperClass = importSync(path.resolve(moduleName)).default; diff --git a/lib/event.js b/lib/event.js index ef71551da..5e4c5e364 100644 --- a/lib/event.js +++ b/lib/event.js @@ -1,10 +1,8 @@ -import createDebugMessages from 'debug'; +import debug from 'debug'; import events from 'events'; import * as output from './output.js'; -const debug = createDebugMessages('codeceptjs'); - debug('codeceptjs:event'); const dispatcher = new events.EventEmitter(); diff --git a/lib/helper/Expect.js b/lib/helper/Expect.js index 3778a666e..a7025f0b5 100644 --- a/lib/helper/Expect.js +++ b/lib/helper/Expect.js @@ -1,15 +1,16 @@ +import { expect } from 'chai'; +import * as chai from 'chai'; import chai_json_schema from 'chai-json-schema'; import chai_match_pattern from 'chai-match-pattern'; import chai_exclude from 'chai-exclude'; import chai_string from 'chai-string'; -import { expect, use } from 'chai'; import * as output from '../output.js'; -use(chai_string); +chai.use(chai_string); // @ts-ignore -use(chai_exclude); -use(chai_match_pattern); -use(chai_json_schema); +chai.use(chai_exclude); +chai.use(chai_match_pattern); +chai.use(chai_json_schema); /** * This helper allows performing assertions based on Chai. diff --git a/lib/interfaces/gherkin.js b/lib/interfaces/gherkin.js index 72f995c45..a61c154b0 100644 --- a/lib/interfaces/gherkin.js +++ b/lib/interfaces/gherkin.js @@ -2,7 +2,7 @@ import * as Gherkin from '@cucumber/gherkin'; import * as Messages from '@cucumber/messages'; import { Context, Suite, Test } from 'mocha'; -import createDebugMessages from 'debug'; +import debug from 'debug'; import { matchStep } from './bdd.js'; import * as event from '../event.js'; @@ -13,8 +13,6 @@ import transform from '../transform.js'; import translations0 from '../translation.js'; -const debug = createDebugMessages('codeceptjs'); - debug('codeceptjs:bdd'); const uuidFn = Messages.IdGenerator.uuid(); diff --git a/lib/listener/steps.js b/lib/listener/steps.js index 034b52809..88929c0a2 100644 --- a/lib/listener/steps.js +++ b/lib/listener/steps.js @@ -1,10 +1,8 @@ -import createDebugMessages from 'debug'; +import debug from 'debug'; import * as event from '../event.js'; import { store } from '../store.js'; import * as output from '../output.js'; -const debug = createDebugMessages('codeceptjs'); - debug('codeceptjs:steps'); let currentTest; diff --git a/lib/pause.js b/lib/pause.js index ec0d7b749..0e6591f44 100644 --- a/lib/pause.js +++ b/lib/pause.js @@ -1,7 +1,7 @@ import colors from 'chalk'; import readline from 'readline'; import ora from 'ora-classic'; -import createDebugMessages from 'debug'; +import debug from 'debug'; import container from './container.js'; import history from './history.js'; @@ -12,8 +12,6 @@ import * as event from './event.js'; import * as output from './output.js'; import { methodsOfObject } from './utils.js'; -const debug = createDebugMessages('codeceptjs'); - debug('codeceptjs:pause'); // npm install colors diff --git a/lib/plugin/autoLogin.js b/lib/plugin/autoLogin.js index e18204a6f..b449d31c6 100644 --- a/lib/plugin/autoLogin.js +++ b/lib/plugin/autoLogin.js @@ -4,7 +4,7 @@ import { fileExists, isAsyncFunction } from '../utils.js'; import container from '../container.js'; import { store } from '../store.js'; import recorder from '../recorder.js'; -import * as output from '../output.js'; +import { debug } from '../output.js'; const defaultUser = { fetch: I => I.grabCookie(), @@ -267,7 +267,7 @@ export default function (config) { } catch (err) { throw new Error(`Could not load session from ${fileName}\n${err}`); } - output.output.debug(`Loaded user session for ${name}`); + debug(`Loaded user session for ${name}`); } } @@ -288,11 +288,11 @@ export default function (config) { const cookies = await userSession.fetch(I); if (!cookies) { - output.output.debug('Cannot save user session with empty cookies from auto login\'s fetch method'); + debug('Cannot save user session with empty cookies from auto login\'s fetch method'); return; } if (config.saveToFile) { - output.output.debug(`Saved user session into file for ${name}`); + debug(`Saved user session into file for ${name}`); fs.writeFileSync(path.join(global.output_dir, `${name}_session.json`), JSON.stringify(cookies)); } store[`${name}_session`] = cookies; @@ -309,12 +309,12 @@ export default function (config) { userSession.check(I, cookies); } recorder.session.catch((err) => { - output.output.debug(`Failed auto login for ${name} due to ${err}`); - output.output.debug('Logging in again'); + debug(`Failed auto login for ${name} due to ${err}`); + debug('Logging in again'); recorder.session.start('auto login'); return loginAndSave().then(() => { recorder.add(() => recorder.session.restore('auto login')); - recorder.catch(() => output.output.debug('continue')); + recorder.catch(() => debug('continue')); }).catch((err) => { recorder.session.restore('auto login'); recorder.session.restore('check login'); diff --git a/lib/plugin/coverage.js b/lib/plugin/coverage.js index 9291ee603..6204ac5fb 100644 --- a/lib/plugin/coverage.js +++ b/lib/plugin/coverage.js @@ -79,7 +79,7 @@ export default function (config) { const options = Object.assign(defaultConfig, helper.options, config); event.dispatcher.on(event.all.before, async () => { - output.output.debug('*** Collecting coverage for tests ****'); + output.debug('*** Collecting coverage for tests ****'); }); // Hack! we're going to try to "start" coverage before each step because this is diff --git a/lib/plugin/heal.js b/lib/plugin/heal.js index e979c1012..bc18262cf 100644 --- a/lib/plugin/heal.js +++ b/lib/plugin/heal.js @@ -1,4 +1,4 @@ -import createDebugMessages from 'debug'; +import debug from 'debug'; import colors from 'chalk'; import Container from '../container.js'; import AiAssistant from '../ai'; @@ -7,8 +7,6 @@ import * as event from '../event.js'; import * as output from '../output.js'; import supportedHelpers from './standardActingHelpers.js'; -const debug = createDebugMessages('codeceptjs'); - debug('codeceptjs:heal'); const defaultConfig = { @@ -176,11 +174,11 @@ export default function (config = {}) { }); async function tryToHeal(failedStep, err) { - output.output.debug(`Running OpenAI to heal ${failedStep.toCode()} step`); + output.debug(`Running OpenAI to heal ${failedStep.toCode()} step`); const codeSnippets = await aiAssistant.healFailedStep(failedStep, err, currentTest); - output.output.debug(`Received ${codeSnippets.length} suggestions from OpenAI`); + output.debug(`Received ${codeSnippets.length} suggestions from OpenAI`); const I = Container.support('I'); // eslint-disable-line for (const codeSnippet of codeSnippets) { @@ -207,7 +205,7 @@ export default function (config = {}) { } } - output.output.debug(`Couldn't heal the code for ${failedStep.toCode()}`); + output.debug(`Couldn't heal the code for ${failedStep.toCode()}`); } return recorder.promise(); } diff --git a/lib/plugin/selenoid.js b/lib/plugin/selenoid.js index a2690004f..4c46cc4c5 100644 --- a/lib/plugin/selenoid.js +++ b/lib/plugin/selenoid.js @@ -212,20 +212,20 @@ const selenoid = (config) => { if (autoStart) { event.dispatcher.on(event.all.before, () => { recorder.add('Starting selenoid', () => { - output.output.debug('Staring Selenoid... '); + output.debug('Staring Selenoid... '); return createAndStart(autoCreate) - .then(() => output.output.debug('Selenoid started')) + .then(() => output.debug('Selenoid started')) .catch((err) => { throw new Error(err.stack); }); }); }); event.dispatcher.on(event.all.after, () => { recorder.add('Stopping selenoid', () => { - output.output.debug('Stopping Selenoid...'); + output.debug('Stopping Selenoid...'); return wait(SELENOID_STOP_TIMEOUT) .then(() => deletePassedTests(passedTests)) .then(stopSelenoid) - .then(() => output.output.debug('Selenoid stopped')) + .then(() => output.debug('Selenoid stopped')) .catch((err) => { throw new Error(err.stack); }); }); }); @@ -263,7 +263,7 @@ export default selenoid; function videoSaved(test) { const fileName = `${clearString(test.title)}.mp4`; const videoFile = path.join(global.output_dir, 'video', fileName); - output.output.debug(`Video has been saved to file://${videoFile}`); + output.debug(`Video has been saved to file://${videoFile}`); const allureReporter = container.plugins('allure'); if (allureReporter) { allureReporter.addAttachment('Video', fs.readFileSync(videoFile), 'video/mp4'); @@ -305,21 +305,21 @@ const pullImage = async () => { console.time('Pulled containers'); if (!stdout.includes('selenoid/video-recorder')) { - output.output.debug('Pulling selenoid/video-recorder...'); + output.debug('Pulling selenoid/video-recorder...'); resultPromise = exec('docker pull selenoid/video-recorder:latest-release') - .then(() => output.output.debug('Pulled in selenoid/video-recorder')); + .then(() => output.debug('Pulled in selenoid/video-recorder')); pulls.push(resultPromise); } if (!stdout.includes('selenoid/chrome')) { - output.output.debug('Pulling selenoid/chrome...'); + output.debug('Pulling selenoid/chrome...'); resultPromise = exec('docker pull selenoid/chrome:latest') - .then(() => output.output.debug('Pulled in selenoid/video-recorder')); + .then(() => output.debug('Pulled in selenoid/video-recorder')); pulls.push(resultPromise); } if (!stdout.includes('selenoid/firefox')) { - output.output.debug('Pulling selenoid/firefox...'); + output.debug('Pulling selenoid/firefox...'); resultPromise = exec('docker pull selenoid/firefox:latest') - .then(() => output.output.debug('Pulled in selenoid/chrome')); + .then(() => output.debug('Pulled in selenoid/chrome')); pulls.push(resultPromise); } @@ -338,7 +338,7 @@ function deletePassedTests(passedTests) { const deleteLogPromiseList = passedTests.map(clearString).map(test => axios.delete(`${seleniumUrl}/logs/${test}.log`)); return Promise.all(deleteVideoPromiseList.concat(deleteLogPromiseList)) - .then(() => output.output.debug('Deleted videos and logs for all passed tests')) + .then(() => output.debug('Deleted videos and logs for all passed tests')) .catch(err => output.output.error(`Error while deleting video and log files ${err.stack}`)); } diff --git a/lib/plugin/wdio.js b/lib/plugin/wdio.js index 77699cfe8..8ce278fc3 100644 --- a/lib/plugin/wdio.js +++ b/lib/plugin/wdio.js @@ -1,4 +1,4 @@ -import createDebugMessages from 'debug'; +import debug from 'debug'; import container from '../container.js'; import mainConfig from '../config.js'; @@ -6,8 +6,6 @@ import recorder from '../recorder.js'; import * as event from '../event.js'; import * as output from '../output.js'; -const debug = createDebugMessages('codeceptjs'); - debug('codeceptjs:plugin:wdio'); const defaultConfig = { @@ -220,7 +218,7 @@ export default (config) => { } else { await launcher.onPrepare(config, config.capabilities); } - output.output.debug(`Started ${name}`); + output.debug(`Started ${name}`); }); }); } @@ -229,7 +227,7 @@ export default (config) => { event.dispatcher.on(event.all.after, () => { recorder.add(`launcher ${name} start`, async () => { await launcher.onComplete(process.exitCode, config, config.capabilities); - output.output.debug(`Stopped ${name}`); + output.debug(`Stopped ${name}`); }); }); } diff --git a/lib/recorder.js b/lib/recorder.js index 91ef5570a..b225207b2 100644 --- a/lib/recorder.js +++ b/lib/recorder.js @@ -1,9 +1,9 @@ +import debug from 'debug'; import promiseRetry from 'promise-retry'; -import createDebugMessages from 'debug'; import { printObjectProperties } from './utils.js'; import * as output from './output.js'; -const debug = createDebugMessages('codeceptjs:recorder'); +debug('codeceptjs:recorder'); const MAX_TASKS = 100; diff --git a/package.json b/package.json index 229fc152a..1d1a3bb96 100644 --- a/package.json +++ b/package.json @@ -69,8 +69,9 @@ }, "dependencies": { "@babel/core": "7.23.9", - "@codeceptjs/configure": "1.0.1", + "@codeceptjs/configure": "0.10.0", "@codeceptjs/helper": "2.0.3", + "@codeceptjs/configure": "1.0.1", "@cucumber/cucumber-expressions": "17", "@cucumber/gherkin": "26", "@cucumber/messages": "24.0.1", @@ -79,7 +80,7 @@ "arrify": "2.0.1", "axios": "1.6.7", "babel-register-esm": "^1.2.5", - "chai": "4.4.1", + "chai": "5.1.0", "chai-deep-match": "1.2.1", "chai-exclude": "2.1.0", "chai-json-schema": "1.5.1", @@ -91,7 +92,6 @@ "cross-spawn": "7.0.3", "css-to-xpath": "0.1.0", "csstoxpath": "1.6.0", - "debug": "^4.3.4", "devtools": "8.29.1", "envinfo": "7.11.0", "escape-string-regexp": "4.0.0", diff --git a/test/acceptance/gherkin/steps.js b/test/acceptance/gherkin/steps.js index 323e58ac6..2b59abeab 100644 --- a/test/acceptance/gherkin/steps.js +++ b/test/acceptance/gherkin/steps.js @@ -1,4 +1,4 @@ -const { I } = inject(); +const I = actor(); Given('I opened website', () => { // From "gherkin/basic.feature" {"line":8,"column":5} diff --git a/test/acceptance/session_test.js b/test/acceptance/session_test.js index 16a6cc0a4..2b5d5f598 100644 --- a/test/acceptance/session_test.js +++ b/test/acceptance/session_test.js @@ -1,4 +1,4 @@ -const assert = require('assert'); +import assert from 'assert'; const { event } = codeceptjs;