Skip to content

Commit

Permalink
Revert "fix: something"
Browse files Browse the repository at this point in the history
This reverts commit ca534ee.
  • Loading branch information
kobenguyent committed Mar 6, 2024
1 parent ca534ee commit 130d797
Show file tree
Hide file tree
Showing 18 changed files with 48 additions and 68 deletions.
2 changes: 1 addition & 1 deletion bin/codecept.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`);
Expand Down
4 changes: 1 addition & 3 deletions lib/ai.js
Original file line number Diff line number Diff line change
@@ -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 = {
Expand Down
5 changes: 1 addition & 4 deletions lib/codecept.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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;
Expand Down
6 changes: 1 addition & 5 deletions lib/container.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 1 addition & 3 deletions lib/event.js
Original file line number Diff line number Diff line change
@@ -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();
Expand Down
11 changes: 6 additions & 5 deletions lib/helper/Expect.js
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
4 changes: 1 addition & 3 deletions lib/interfaces/gherkin.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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();
Expand Down
4 changes: 1 addition & 3 deletions lib/listener/steps.js
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
4 changes: 1 addition & 3 deletions lib/pause.js
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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
Expand Down
14 changes: 7 additions & 7 deletions lib/plugin/autoLogin.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down Expand Up @@ -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}`);
}
}

Expand All @@ -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;
Expand All @@ -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');
Expand Down
2 changes: 1 addition & 1 deletion lib/plugin/coverage.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 4 additions & 6 deletions lib/plugin/heal.js
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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 = {
Expand Down Expand Up @@ -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) {
Expand All @@ -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();
}
24 changes: 12 additions & 12 deletions lib/plugin/selenoid.js
Original file line number Diff line number Diff line change
Expand Up @@ -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); });
});
});
Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -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);
}

Expand All @@ -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}`));
}

Expand Down
8 changes: 3 additions & 5 deletions lib/plugin/wdio.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import createDebugMessages from 'debug';
import debug from 'debug';

import container from '../container.js';
import mainConfig from '../config.js';
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 = {
Expand Down Expand Up @@ -220,7 +218,7 @@ export default (config) => {
} else {
await launcher.onPrepare(config, config.capabilities);
}
output.output.debug(`Started ${name}`);
output.debug(`Started ${name}`);
});
});
}
Expand All @@ -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}`);
});
});
}
Expand Down
4 changes: 2 additions & 2 deletions lib/recorder.js
Original file line number Diff line number Diff line change
@@ -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;

Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion test/acceptance/gherkin/steps.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { I } = inject();
const I = actor();

Given('I opened website', () => {
// From "gherkin/basic.feature" {"line":8,"column":5}
Expand Down
2 changes: 1 addition & 1 deletion test/acceptance/session_test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const assert = require('assert');
import assert from 'assert';

const { event } = codeceptjs;

Expand Down

0 comments on commit 130d797

Please sign in to comment.