Skip to content

Commit e46c79b

Browse files
committed
fix: runner tests
1 parent 462e1de commit e46c79b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+393
-399
lines changed

bin/codecept.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ const errorHandler = (fn) => async (...args) => {
3131
};
3232

3333
if (process.versions.node && process.versions.node.split('.') && process.versions.node.split('.')[0] < 12) {
34-
outputLib.output.error('NodeJS >= 12 is required to run.');
34+
outputLib.output.output.error('NodeJS >= 12 is required to run.');
3535
outputLib.print();
3636
outputLib.print('Please upgrade your NodeJS engine');
3737
outputLib.print(`Current NodeJS version: ${process.version}`);
@@ -133,7 +133,7 @@ program.command('run [test]')
133133
.option('-R, --reporter <name>', 'specify the reporter to use')
134134
.option('-S, --sort', 'sort test files')
135135
.option('-b, --bail', 'bail after first test failure')
136-
// .option('-d, --debug', "enable node's debugger, synonym for node --debug")
136+
.option('-d, --debug', "enable node's debugger, synonym for node --debug")
137137
.option('-g, --grep <pattern>', 'only run tests matching <pattern>')
138138
.option('-f, --fgrep <string>', 'only run tests containing <string>')
139139
.option('-i, --invert', 'inverts --grep and --fgrep matches')
@@ -231,7 +231,7 @@ program.command('run-rerun [test]')
231231
.option('-R, --reporter <name>', 'specify the reporter to use')
232232
.option('-S, --sort', 'sort test files')
233233
.option('-b, --bail', 'bail after first test failure')
234-
// .option('-d, --debug', "enable node's debugger, synonym for node --debug")
234+
.option('-d, --debug', "enable node's debugger, synonym for node --debug")
235235
.option('-g, --grep <pattern>', 'only run tests matching <pattern>')
236236
.option('-f, --fgrep <string>', 'only run tests containing <string>')
237237
.option('-i, --invert', 'inverts --grep and --fgrep matches')

docs/hooks.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ const output = require('codeceptjs').output;
243243

244244
output.print('This is basic information');
245245
output.debug('This is debug information');
246-
output.log('This is verbose logging information');
246+
output.output.log('This is verbose logging information');
247247
```
248248
249249
### Container

docs/internal-api.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ const output = require('codeceptjs').output;
191191

192192
output.print('This is basic information');
193193
output.debug('This is debug information');
194-
output.log('This is verbose logging information');
194+
output.output.log('This is verbose logging information');
195195
```
196196
197197
#### Test Object

lib/actor.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export class Actor {
4040
if (!store.timeouts) return this;
4141

4242
event.dispatcher.prependOnceListener(event.step.before, (step) => {
43-
output.log(`Timeout to ${step}: ${timeout}s`);
43+
output.output.log(`Timeout to ${step}: ${timeout}s`);
4444
step.setTimeout(timeout * 1000, Step.TIMEOUT_ORDER.codeLimitTime);
4545
});
4646

lib/ai.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,9 @@ class AiAssistant {
9191
} catch (err) {
9292
debug(err.response);
9393
output.print('');
94-
output.error(`OpenAI error: ${err.message}`);
95-
output.error(err?.response?.data?.error?.code);
96-
output.error(err?.response?.data?.error?.message);
94+
output.output.error(`OpenAI error: ${err.message}`);
95+
output.output.error(err?.response?.data?.error?.code);
96+
output.output.error(err?.response?.data?.error?.message);
9797
return '';
9898
}
9999
}

lib/cli.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ class Cli extends Base {
8585
codeceptjsEventDispatchersRegistered = true;
8686

8787
event.dispatcher.on(event.bddStep.started, (step) => {
88-
// output.output.stepShift = 2;
88+
output.output.stepShift = 2;
8989
output.output.step(step);
9090
});
9191

lib/codecept.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import { existsSync, readFileSync } from 'fs';
22
import glob from 'glob';
3-
import fsPath, { resolve } from 'path';
3+
import fsPath, { resolve, dirname } from 'path';
44
import generated from '@codeceptjs/helper';
5+
import { fileURLToPath } from 'url';
6+
import {createRequire} from "node:module";
57
import container from './container.js';
68
import Config from './config.js';
79
import * as event from './event.js';
@@ -41,7 +43,8 @@ import listener01234 from './listener/timeout.js';
4143

4244
import listener012345 from './listener/exit.js';
4345

44-
const __dirname = fsPath.resolve('.');
46+
const __dirname = dirname(fileURLToPath(import.meta.url));
47+
const require = createRequire(import.meta.url);
4548

4649
/**
4750
* CodeceptJS runner
@@ -241,5 +244,5 @@ export default class Codecept {
241244
}
242245

243246
export function version() {
244-
return JSON.parse(readFileSync(`${__dirname}/package.json`, 'utf8')).version;
247+
return JSON.parse(readFileSync(`${__dirname}/../package.json`, 'utf8')).version;
245248
}

lib/command/configMigrate.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export default function (initPath) {
3131

3232
const configFile = path.join(testsPath, 'codecept.conf.js');
3333
if (fileExists(configFile)) {
34-
outputLib.output.error(`Config is already created at ${configFile}`);
34+
outputLib.output.output.error(`Config is already created at ${configFile}`);
3535
return;
3636
}
3737

lib/command/dryRun.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ function printTests(files) {
5050
const figures = require('figures');
5151
const colors = require('chalk');
5252

53-
output.print(output.styles.debug(`Tests from ${global.codecept_dir}:`));
53+
output.print(output.output.styles.debug(`Tests from ${global.codecept_dir}:`));
5454
output.print();
5555

5656
const mocha = Container.mocha();
@@ -68,12 +68,12 @@ function printTests(files) {
6868
}
6969
const displayedSuites = process.env.grep ? filteredSuites : mocha.suite.suites;
7070
for (const suite of displayedSuites) {
71-
output.print(`${colors.white.bold(suite.title)} -- ${output.styles.log(suite.file || '')} -- ${suite.tests.length} tests`);
71+
output.print(`${colors.white.bold(suite.title)} -- ${output.output.styles.log(suite.file || '')} -- ${suite.tests.length} tests`);
7272
numOfSuites++;
7373

7474
for (const test of suite.tests) {
7575
numOfTests++;
76-
output.print(` ${output.styles.scenario(figures.checkboxOff)} ${test.title}`);
76+
output.print(` ${output.output.styles.scenario(figures.checkboxOff)} ${test.title}`);
7777
}
7878
}
7979

lib/command/gherkin/init.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export default function (genPath) {
3131
output.print('--------------------------');
3232

3333
if (config.gherkin && config.gherkin.steps) {
34-
output.error('Gherkin is already initialized in this project. See `gherkin` section in the config');
34+
output.output.error('Gherkin is already initialized in this project. See `gherkin` section in the config');
3535
process.exit(1);
3636
}
3737

lib/command/gherkin/snippets.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,19 @@ export default function (genPath, options) {
2525
codecept.init(testsPath);
2626

2727
if (!config.gherkin) {
28-
output.error('Gherkin is not enabled in config. Run `codecept gherkin:init` to enable it');
28+
output.output.error('Gherkin is not enabled in config. Run `codecept gherkin:init` to enable it');
2929
process.exit(1);
3030
}
3131
if (!config.gherkin.steps || !config.gherkin.steps[0]) {
32-
output.error('No gherkin steps defined in config. Exiting');
32+
output.output.error('No gherkin steps defined in config. Exiting');
3333
process.exit(1);
3434
}
3535
if (!options.feature && !config.gherkin.features) {
36-
output.error('No gherkin features defined in config. Exiting');
36+
output.output.error('No gherkin features defined in config. Exiting');
3737
process.exit(1);
3838
}
3939
if (options.path && !config.gherkin.steps.includes(options.path)) {
40-
output.error(`You must include ${options.path} to the gherkin steps in your config file`);
40+
output.output.error(`You must include ${options.path} to the gherkin steps in your config file`);
4141
process.exit(1);
4242
}
4343

@@ -86,6 +86,7 @@ export default function (genPath, options) {
8686
};
8787

8888
const parseFile = (file) => {
89+
console.log(file)
8990
const ast = parser.parse(fs.readFileSync(file).toString());
9091
for (const child of ast.feature.children) {
9192
if (child.scenario.keyword === 'Scenario Outline') continue; // skip scenario outline
@@ -99,7 +100,7 @@ export default function (genPath, options) {
99100

100101
let stepFile = options.path || config.gherkin.steps[0];
101102
if (!fs.existsSync(stepFile)) {
102-
output.error(`Please enter a valid step file path ${stepFile}`);
103+
output.output.error(`Please enter a valid step file path ${stepFile}`);
103104
process.exit(1);
104105
}
105106

@@ -121,11 +122,11 @@ ${step.type}(${step.regexp ? '/^' : "'"}${step}${step.regexp ? '$/' : "'"}, () =
121122
output.print('No new snippets found');
122123
return;
123124
}
124-
output.success(`Snippets generated: ${snippets.length}`);
125+
output.output.success(`Snippets generated: ${snippets.length}`);
125126
output.print(snippets.join('\n'));
126127

127128
if (!options.dryRun) {
128-
output.success(`Snippets added to ${output.colors.bold(stepFile)}`);
129+
output.output.success(`Snippets added to ${output.output.colors.bold(stepFile)}`);
129130
fs.writeFileSync(stepFile, fs.readFileSync(stepFile).toString() + snippets.join('\n') + '\n'); // eslint-disable-line
130131
}
131132
}

lib/command/gherkin/steps.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ export default function (genPath, options) {
1616
output.print();
1717
const steps = getSteps();
1818
for (const step of Object.keys(steps)) {
19-
output.print(` ${output.colors.bold(step)} ${output.colors.green(steps[step].line || '')}`);
19+
output.print(` ${output.output.colors.bold(step)} ${output.output.colors.green(steps[step].line || '')}`);
2020
}
2121
output.print();
2222
if (!Object.keys(steps).length) {
23-
output.error('No Gherkin steps defined');
23+
output.output.error('No Gherkin steps defined');
2424
}
2525
}

lib/command/interactive.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,6 @@ export default async function (path, options) {
5050
recorder.add(() => event.emit(event.all.result, {}));
5151
recorder.add(() => codecept.teardown());
5252
} catch (err) {
53-
output.error(`Error while running bootstrap file :${err}`);
53+
output.output.error(`Error while running bootstrap file :${err}`);
5454
}
5555
}

lib/command/run-workers.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ export default async function (workerCount, selectedRuns, options) {
3030
const numberOfWorkers = parseInt(workerCount, 10);
3131

3232
const version = Codecept.version();
33-
output.print(`CodeceptJS v${version} ${output.standWithUkraine()}`);
34-
output.print(`Running tests in ${output.styles.bold(numberOfWorkers)} workers...`);
33+
output.print(`CodeceptJS v${version} ${output.output.standWithUkraine()}`);
34+
output.print(`Running tests in ${output.output.styles.bold(numberOfWorkers)} workers...`);
3535
output.print();
3636

3737
const workers = new Workers(numberOfWorkers, config);
@@ -51,17 +51,17 @@ export default async function (workerCount, selectedRuns, options) {
5151

5252
workers.on(event.test.failed, (test) => {
5353
failedTestArr.push(test);
54-
output.test.failed(test);
54+
output.output.test.failed(test);
5555
});
5656

5757
workers.on(event.test.passed, (test) => {
5858
passedTestArr.push(test);
59-
output.test.passed(test);
59+
output.output.test.passed(test);
6060
});
6161

6262
workers.on(event.test.skipped, (test) => {
6363
skippedTestArr.push(test);
64-
output.test.skipped(test);
64+
output.output.test.skipped(test);
6565
});
6666

6767
workers.on(event.all.result, () => {
@@ -107,7 +107,7 @@ export default async function (workerCount, selectedRuns, options) {
107107
await workers.bootstrapAll();
108108
await workers.run();
109109
} catch (err) {
110-
output.error(err);
110+
output.output.error(err);
111111
process.exit(1);
112112
} finally {
113113
await workers.teardownAll();

lib/command/run.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ export default async function (test, options) {
1717
const configFile = options.config;
1818

1919
let config = getConfig(configFile);
20-
console.log(configFile)
2120

2221
if (options.override) {
2322
config = Config.append(JSON.parse(options.override));

lib/container.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import glob from 'glob';
2-
import path from 'path';
2+
import path, {dirname} from 'path';
33
import importSync from 'import-sync';
44
import { MetaStep } from './step.js';
55
import {
@@ -13,6 +13,7 @@ import * as WorkerStorage from './workerStorage.js';
1313
import { store } from './store.js';
1414

1515
import { actor } from './actor.js';
16+
import {fileURLToPath} from "url";
1617

1718
let container = {
1819
helpers: {},
@@ -173,7 +174,8 @@ function createHelpers(config) {
173174
let HelperClass;
174175
// check if the helper is the built-in, use the require() syntax.
175176
if (moduleName.startsWith('./helper/')) {
176-
HelperClass = importSync(path.resolve('lib', moduleName)).default;
177+
const __dirname = dirname(fileURLToPath(import.meta.url));
178+
HelperClass = importSync(path.resolve(__dirname, moduleName)).default;
177179
} else {
178180
// check if the new syntax export default HelperName is used and loads the Helper, otherwise loads the module that used old syntax export = HelperName.
179181
HelperClass = importSync(path.resolve(moduleName)).default;
@@ -355,7 +357,7 @@ function loadSupportObject(modulePath, supportObjectName) {
355357
modulePath = path.join(global.codecept_dir, modulePath);
356358
}
357359
try {
358-
const obj = importSync(modulePath).default;
360+
const obj = importSync(modulePath).default || importSync(modulePath);
359361

360362
if (typeof obj === 'function') {
361363
const fobj = obj();

lib/event.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ export function emit(event, param) {
166166
if (param && param.toString()) {
167167
msg += ` (${param.toString()})`;
168168
}
169-
debug(msg);
169+
output.output.debug(msg);
170170
try {
171171
dispatcher.emit.apply(dispatcher, arguments);
172172
} catch (err) {

0 commit comments

Comments
 (0)