Skip to content

Commit

Permalink
fix: something
Browse files Browse the repository at this point in the history
  • Loading branch information
kobenguyent committed Mar 5, 2024
1 parent d7e1996 commit ca534ee
Show file tree
Hide file tree
Showing 18 changed files with 68 additions and 48 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.output.error('NodeJS >= 12 is required to run.');
outputLib.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: 3 additions & 1 deletion lib/ai.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { Configuration, OpenAIApi } from 'openai';
import debug from 'debug';
import createDebugMessages 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: 4 additions & 1 deletion lib/codecept.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ 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 @@ -118,7 +121,7 @@ export default class Codecept {
global.inject = container.support;
global.share = container.share;
global.secret = secret;
global.codecept_debug = output.debug;
global.codecept_debug = output.output.debug;
global.codeceptjs = index; // load all objects
global.Given = stepDefinitions.Given;
global.When = stepDefinitions.When;
Expand Down
6 changes: 5 additions & 1 deletion lib/container.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,11 @@ 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));
HelperClass = importSync(path.resolve(__dirname, moduleName)).default;
try {
HelperClass = importSync(path.resolve(__dirname, moduleName)).default;
} catch (e) {
HelperClass = importSync(path.resolve(__dirname, moduleName));
}
} 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: 3 additions & 1 deletion lib/event.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import debug from 'debug';
import createDebugMessages 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: 5 additions & 6 deletions lib/helper/Expect.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
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';

chai.use(chai_string);
use(chai_string);
// @ts-ignore
chai.use(chai_exclude);
chai.use(chai_match_pattern);
chai.use(chai_json_schema);
use(chai_exclude);
use(chai_match_pattern);
use(chai_json_schema);

/**
* This helper allows performing assertions based on Chai.
Expand Down
4 changes: 3 additions & 1 deletion 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 debug from 'debug';
import createDebugMessages from 'debug';

import { matchStep } from './bdd.js';
import * as event from '../event.js';
Expand All @@ -13,6 +13,8 @@ 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: 3 additions & 1 deletion lib/listener/steps.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import debug from 'debug';
import createDebugMessages 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: 3 additions & 1 deletion 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 debug from 'debug';
import createDebugMessages from 'debug';

import container from './container.js';
import history from './history.js';
Expand All @@ -12,6 +12,8 @@ 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 { debug } from '../output.js';
import * as output 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}`);
}
debug(`Loaded user session for ${name}`);
output.output.debug(`Loaded user session for ${name}`);
}
}

Expand All @@ -288,11 +288,11 @@ export default function (config) {

const cookies = await userSession.fetch(I);
if (!cookies) {
debug('Cannot save user session with empty cookies from auto login\'s fetch method');
output.output.debug('Cannot save user session with empty cookies from auto login\'s fetch method');
return;
}
if (config.saveToFile) {
debug(`Saved user session into file for ${name}`);
output.output.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) => {
debug(`Failed auto login for ${name} due to ${err}`);
debug('Logging in again');
output.output.debug(`Failed auto login for ${name} due to ${err}`);
output.output.debug('Logging in again');
recorder.session.start('auto login');
return loginAndSave().then(() => {
recorder.add(() => recorder.session.restore('auto login'));
recorder.catch(() => debug('continue'));
recorder.catch(() => output.output.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.debug('*** Collecting coverage for tests ****');
output.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: 6 additions & 4 deletions lib/plugin/heal.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import debug from 'debug';
import createDebugMessages from 'debug';
import colors from 'chalk';
import Container from '../container.js';
import AiAssistant from '../ai';
Expand All @@ -7,6 +7,8 @@ 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 @@ -174,11 +176,11 @@ export default function (config = {}) {
});

async function tryToHeal(failedStep, err) {
output.debug(`Running OpenAI to heal ${failedStep.toCode()} step`);
output.output.debug(`Running OpenAI to heal ${failedStep.toCode()} step`);

const codeSnippets = await aiAssistant.healFailedStep(failedStep, err, currentTest);

output.debug(`Received ${codeSnippets.length} suggestions from OpenAI`);
output.output.debug(`Received ${codeSnippets.length} suggestions from OpenAI`);
const I = Container.support('I'); // eslint-disable-line

for (const codeSnippet of codeSnippets) {
Expand All @@ -205,7 +207,7 @@ export default function (config = {}) {
}
}

output.debug(`Couldn't heal the code for ${failedStep.toCode()}`);
output.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.debug('Staring Selenoid... ');
output.output.debug('Staring Selenoid... ');
return createAndStart(autoCreate)
.then(() => output.debug('Selenoid started'))
.then(() => output.output.debug('Selenoid started'))
.catch((err) => { throw new Error(err.stack); });
});
});

event.dispatcher.on(event.all.after, () => {
recorder.add('Stopping selenoid', () => {
output.debug('Stopping Selenoid...');
output.output.debug('Stopping Selenoid...');
return wait(SELENOID_STOP_TIMEOUT)
.then(() => deletePassedTests(passedTests))
.then(stopSelenoid)
.then(() => output.debug('Selenoid stopped'))
.then(() => output.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.debug(`Video has been saved to file://${videoFile}`);
output.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.debug('Pulling selenoid/video-recorder...');
output.output.debug('Pulling selenoid/video-recorder...');
resultPromise = exec('docker pull selenoid/video-recorder:latest-release')
.then(() => output.debug('Pulled in selenoid/video-recorder'));
.then(() => output.output.debug('Pulled in selenoid/video-recorder'));
pulls.push(resultPromise);
}
if (!stdout.includes('selenoid/chrome')) {
output.debug('Pulling selenoid/chrome...');
output.output.debug('Pulling selenoid/chrome...');
resultPromise = exec('docker pull selenoid/chrome:latest')
.then(() => output.debug('Pulled in selenoid/video-recorder'));
.then(() => output.output.debug('Pulled in selenoid/video-recorder'));
pulls.push(resultPromise);
}
if (!stdout.includes('selenoid/firefox')) {
output.debug('Pulling selenoid/firefox...');
output.output.debug('Pulling selenoid/firefox...');
resultPromise = exec('docker pull selenoid/firefox:latest')
.then(() => output.debug('Pulled in selenoid/chrome'));
.then(() => output.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.debug('Deleted videos and logs for all passed tests'))
.then(() => output.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: 5 additions & 3 deletions lib/plugin/wdio.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import debug from 'debug';
import createDebugMessages 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 @@ -218,7 +220,7 @@ export default (config) => {
} else {
await launcher.onPrepare(config, config.capabilities);
}
output.debug(`Started ${name}`);
output.output.debug(`Started ${name}`);
});
});
}
Expand All @@ -227,7 +229,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.debug(`Stopped ${name}`);
output.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';

debug('codeceptjs:recorder');
const debug = createDebugMessages('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,9 +69,8 @@
},
"dependencies": {
"@babel/core": "7.23.9",
"@codeceptjs/configure": "0.10.0",
"@codeceptjs/helper": "2.0.3",
"@codeceptjs/configure": "1.0.1",
"@codeceptjs/helper": "2.0.3",
"@cucumber/cucumber-expressions": "17",
"@cucumber/gherkin": "26",
"@cucumber/messages": "24.0.1",
Expand All @@ -80,7 +79,7 @@
"arrify": "2.0.1",
"axios": "1.6.7",
"babel-register-esm": "^1.2.5",
"chai": "5.1.0",
"chai": "4.4.1",
"chai-deep-match": "1.2.1",
"chai-exclude": "2.1.0",
"chai-json-schema": "1.5.1",
Expand All @@ -92,6 +91,7 @@
"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 = actor();
const { I } = inject();

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 @@
import assert from 'assert';
const assert = require('assert');

const { event } = codeceptjs;

Expand Down

0 comments on commit ca534ee

Please sign in to comment.