Skip to content

Commit 1c790ee

Browse files
committed
fix: more runner tests
1 parent 82d892b commit 1c790ee

File tree

13 files changed

+72
-64
lines changed

13 files changed

+72
-64
lines changed

bin/codecept.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import * as generate from '../lib/command/generate.js';
1515
import * as run from '../lib/command/run.js';
1616
import * as runWorkers from '../lib/command/run-workers.js';
1717
import * as runMultiple from '../lib/command/run-multiple.js';
18-
import * as rerun from '../lib/command/run-rerun.js';
18+
import { runRerun } from '../lib/command/run-rerun.js';
1919
import * as dryRun from '../lib/command/dryRun.js';
2020
import * as info from '../lib/command/info.js';
2121

@@ -244,7 +244,7 @@ program.command('run-rerun [test]')
244244
.option('--trace', 'trace function calls')
245245
.option('--child <string>', 'option for child processes')
246246

247-
.action(rerun);
247+
.action(runRerun);
248248

249249
program.on('command:*', (cmd) => {
250250
console.log(`\nUnknown command ${cmd}\n`);

lib/command/list.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export default function (path) {
2020
methodsOfObject(helper).forEach((action) => {
2121
const params = getParamsToString(helper[action]);
2222
actions[action] = 1;
23-
output.print(` ${output.colors.grey(name)} I.${output.colors.bold(action)}(${params})`);
23+
output.print(` ${output.output.colors.grey(name)} I.${output.output.colors.bold(action)}(${params})`);
2424
});
2525
}
2626
for (const name in supportI) {
@@ -29,7 +29,7 @@ export default function (path) {
2929
}
3030
const actor = supportI[name];
3131
const params = getParamsToString(actor);
32-
output.print(` I.${output.colors.bold(name)}(${params})`);
32+
output.print(` I.${output.output.colors.bold(name)}(${params})`);
3333
}
3434
output.print('PS: Actions are retrieved from enabled helpers. ');
3535
output.print('Implement custom actions in your helper classes.');

lib/command/run-multiple.js

-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import { getConfig, getTestRoot, fail } from './utils.js';
1111
const __dirname = dirname(fileURLToPath(import.meta.url));
1212

1313
const runner = path.join(__dirname, '../../bin/codecept.js');
14-
console.log(runner)
1514
let config;
1615
const childOpts = {};
1716
const copyOptions = ['override', 'steps', 'reporter', 'verbose', 'config', 'reporter-options', 'grep', 'fgrep', 'invert', 'debug', 'plugins', 'colors'];

lib/command/run-rerun.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {
44
import Config from '../config.js';
55
import Codecept from '../rerun.js';
66

7-
export default async function (test, options) {
7+
export async function runRerun(test, options) {
88
// registering options globally to use in config
99
// Backward compatibility for --profile
1010
process.profile = options.profile;

lib/rerun.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class CodeceptRerunner extends BaseCodecept {
1111
container.createMocha();
1212
const mocha = container.mocha();
1313
this.testFiles.forEach((file) => {
14-
delete require.cache[file];
14+
// delete require.cache[file];
1515
});
1616
mocha.files = this.testFiles;
1717
if (test) {
@@ -53,7 +53,7 @@ class CodeceptRerunner extends BaseCodecept {
5353
try {
5454
await this.runOnce(test);
5555
successCounter++;
56-
output.success(`\nProcess run ${rerunsCounter} of max ${maxReruns}, success runs ${successCounter}/${minSuccess}\n`);
56+
output.output.success(`\nProcess run ${rerunsCounter} of max ${maxReruns}, success runs ${successCounter}/${minSuccess}\n`);
5757
} catch (e) {
5858
output.output.error(`\nFail run ${rerunsCounter} of max ${maxReruns}, success runs ${successCounter}/${minSuccess} \n`);
5959
console.error(e);

runok.js

+10-9
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,24 @@
11
#!/usr/bin/env node
2-
const fs = require('fs');
3-
const path = require('path');
4-
const axios = require('axios');
5-
const documentation = require('documentation');
2+
import fs from 'fs';
3+
import path from 'path';
4+
import axios from 'axios';
5+
import documentation from 'documentation';
6+
import runok0 from 'runok';
7+
import contributors from 'contributor-faces';
8+
69
const {
710
stopOnFail, chdir, tasks: {
811
git, copy, exec, replaceInFile, npmRun, npx, writeToFile,
912
}, runok,
10-
} = require('runok');
11-
const contributors = require('contributor-faces');
12-
13+
} = runok0;
1314
const helperMarkDownFile = function (name) {
1415
return `docs/helpers/${name}.md`;
1516
};
1617
const documentjsCliArgs = '-f md --shallow --markdown-toc=false --sort-order=alpha';
1718

1819
stopOnFail();
1920

20-
module.exports = {
21+
export default {
2122
async docs() {
2223
// generate all docs (runs all docs:* commands in parallel)
2324
await Promise.all([
@@ -491,4 +492,4 @@ async function processChangelog() {
491492
});
492493
}
493494

494-
if (require.main === module) runok(module.exports);
495+
//if (require.main === module) runok(module.exports);

test/data/sandbox/configs/step_timeout/first_test.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
const given = when = then = global.codeceptjs.container.plugins('commentStep');
1+
const Container = require('../../../../../lib/container.js').default;
2+
3+
const given = when = then = Container.plugins('commentStep');
24
const { I } = inject();
35

46
Feature('Steps');

test/runner/definitions_test.js

+24-19
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
11
import fs from 'fs';
22
import assert from 'assert';
3-
import path from 'path';
3+
import path, { dirname } from 'path';
44
import { exec, execSync } from 'child_process';
55
import { Project, StructureKind, ts } from 'ts-morph';
6+
import { expect } from 'chai';
67

78
import chai_subset from 'chai-subset';
9+
import { fileURLToPath } from 'url';
10+
import { createRequire } from 'node:module';
811

9-
const __dirname = path.resolve('.');
10-
const runner = path.join(__dirname, 'bin/codecept.js');
11-
const codecept_dir = path.join(__dirname, 'test/data/sandbox/configs/definitions');
12+
const require = createRequire(import.meta.url);
13+
14+
const __dirname = dirname(fileURLToPath(import.meta.url));
15+
const runner = path.join(__dirname, '../../bin/codecept.js');
16+
const codecept_dir = path.join(__dirname, '../../test/data/sandbox/configs/definitions');
1217
const pathToRootOfProject = path.join(__dirname, '../../');
1318
const pathOfStaticDefinitions = path.join(pathToRootOfProject, 'typings/index.d.ts');
1419
const pathOfJSDocDefinitions = path.join(pathToRootOfProject, 'typings/types.d.ts');
@@ -54,19 +59,19 @@ describe('Definitions', function () {
5459
it('should have internal object that is available as variable codeceptjs', (done) => {
5560
exec(`${runner} def --config ${codecept_dir}/codecept.inject.po.js`, () => {
5661
const types = typesFrom(`${codecept_dir}/steps.d.ts`);
57-
types.should.be.valid;
62+
expect(types).to.be.valid;
5863

5964
const definitionsFile = types.getSourceFileOrThrow(pathOfJSDocDefinitions);
6065
const index = definitionsFile.getModule('CodeceptJS').getModule('index').getStructure();
61-
index.statements.should.containSubset([
66+
expect(index.statements).to.containSubset([
6267
{ declarations: [{ name: 'recorder', type: 'CodeceptJS.recorder' }] },
6368
{ declarations: [{ name: 'event', type: 'typeof CodeceptJS.event' }] },
6469
{ declarations: [{ name: 'output', type: 'typeof CodeceptJS.output' }] },
6570
{ declarations: [{ name: 'config', type: 'typeof CodeceptJS.Config' }] },
6671
{ declarations: [{ name: 'container', type: 'typeof CodeceptJS.Container' }] },
6772
]);
6873
const codeceptjs = types.getSourceFileOrThrow(pathOfStaticDefinitions).getVariableDeclarationOrThrow('codeceptjs').getStructure();
69-
codeceptjs.type.should.equal('typeof CodeceptJS.index');
74+
expect(codeceptjs.type).to.equal('typeof CodeceptJS.index');
7075
done();
7176
});
7277
});
@@ -76,11 +81,11 @@ describe('Definitions', function () {
7681
exec(`${runner} def ${codecept_dir}`, (err, stdout) => {
7782
expect(stdout).to.include('Definitions were generated in steps.d.ts');
7883
const types = typesFrom(`${codecept_dir}/steps.d.ts`);
79-
types.should.be.valid;
84+
expect(types).to.valid;
8085

8186
const definitionFile = types.getSourceFileOrThrow(`${codecept_dir}/steps.d.ts`);
8287
const extend = getExtends(definitionFile.getModule('CodeceptJS').getInterfaceOrThrow('I'));
83-
extend.should.containSubset([{
88+
expect(extend).to.containSubset([{
8489
methods: [{
8590
name: 'amInPath',
8691
returnType: 'void',
@@ -100,12 +105,12 @@ describe('Definitions', function () {
100105
exec(`${runner} def --config ${codecept_dir}/codecept.inject.po.js`, (err, stdout) => {
101106
expect(stdout).to.include('Definitions were generated in steps.d.ts');
102107
const types = typesFrom(`${codecept_dir}/steps.d.ts`);
103-
types.should.be.valid;
108+
expect(types).to.valid;
104109

105110
const definitionFile = types.getSourceFileOrThrow(`${codecept_dir}/steps.d.ts`);
106111
const extend = definitionFile.getFullText();
107112

108-
extend.should.include("type CurrentPage = typeof import('./po/custom_steps.js');");
113+
expect(extend).to.include("type CurrentPage = typeof import('./po/custom_steps.js');");
109114
assert(!err);
110115
done();
111116
});
@@ -115,7 +120,7 @@ describe('Definitions', function () {
115120
exec(`${runner} def --config ${codecept_dir}/../../codecept.ddt.js`, (err, stdout) => {
116121
expect(stdout).to.include('Definitions were generated in steps.d.ts');
117122
const types = typesFrom(`${codecept_dir}/../../steps.d.ts`);
118-
types.should.be.valid;
123+
expect(types).to.valid;
119124
assert(!err);
120125
done();
121126
});
@@ -124,7 +129,7 @@ describe('Definitions', function () {
124129
it('def should create definition file with support object', (done) => {
125130
exec(`${runner} def --config ${codecept_dir}/codecept.inject.po.js`, () => {
126131
const types = typesFrom(`${codecept_dir}/steps.d.ts`);
127-
types.should.be.valid;
132+
expect(types).to.valid;
128133

129134
const definitionsFile = types.getSourceFileOrThrow(`${codecept_dir}/steps.d.ts`);
130135
const MyPage = getAliasStructure(definitionsFile.getTypeAliasOrThrow('MyPage'));
@@ -148,7 +153,7 @@ describe('Definitions', function () {
148153
it('def should create definition file with inject which contains support objects', (done) => {
149154
exec(`${runner} def --config ${codecept_dir}/codecept.inject.po.js`, () => {
150155
const types = typesFrom(`${codecept_dir}/steps.d.ts`);
151-
types.should.be.valid;
156+
expect(types).to.valid;
152157

153158
const definitionsFile = types.getSourceFileOrThrow(pathOfStaticDefinitions);
154159
const returned = getReturnStructure(definitionsFile.getFunctionOrThrow('inject'));
@@ -166,7 +171,7 @@ describe('Definitions', function () {
166171
exec(`${runner} def --config ${codecept_dir}/codecept.inject.po.js`, (err) => {
167172
assert(!err);
168173
const types = typesFrom(`${codecept_dir}/steps.d.ts`);
169-
types.should.be.valid;
174+
expect(types).to.valid;
170175

171176
const definitionsFile = types.getSourceFileOrThrow(pathOfStaticDefinitions);
172177
const returned = getReturnStructure(definitionsFile.getFunctionOrThrow('inject'));
@@ -185,7 +190,7 @@ describe('Definitions', function () {
185190
it('def should create definition file with inject which contains I object from helpers', (done) => {
186191
exec(`${runner} def --config ${codecept_dir}/codecept.inject.powi.js`, () => {
187192
const types = typesFrom(`${codecept_dir}/steps.d.ts`);
188-
types.should.be.valid;
193+
expect(types).to.valid;
189194

190195
const definitionsFile = types.getSourceFileOrThrow(pathOfStaticDefinitions);
191196
const returned = getReturnStructure(definitionsFile.getFunctionOrThrow('inject'));
@@ -199,7 +204,7 @@ describe('Definitions', function () {
199204
it('def should create definition file with callback params', (done) => {
200205
exec(`${runner} def --config ${codecept_dir}/codecept.inject.po.js`, () => {
201206
const types = typesFrom(`${codecept_dir}/steps.d.ts`);
202-
types.should.be.valid;
207+
expect(types).to.valid;
203208

204209
const definitionsFile = types.getSourceFileOrThrow(`${codecept_dir}/steps.d.ts`);
205210
const CallbackOrder = definitionsFile.getModule('CodeceptJS').getInterfaceOrThrow('SupportObject').getStructure();
@@ -216,11 +221,11 @@ describe('Definitions', function () {
216221
exec(`${runner} def --config ${codecept_dir}/codecept.promise.based.js`, (err, stdout) => {
217222
expect(stdout).to.include('Definitions were generated in steps.d.ts');
218223
const types = typesFrom(`${codecept_dir}/steps.d.ts`);
219-
types.should.be.valid;
224+
expect(types).to.valid;
220225

221226
const definitionFile = types.getSourceFileOrThrow(`${codecept_dir}/steps.d.ts`);
222227
const extend = getExtends(definitionFile.getModule('CodeceptJS').getInterfaceOrThrow('I'));
223-
extend.should.containSubset([{
228+
expect(extend).to.containSubset([{
224229
methods: [{
225230
name: 'amInPath',
226231
returnType: 'Promise<any>',

test/runner/list_test.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import assert from 'assert';
2-
import path, {dirname} from 'path';
2+
import path, { dirname } from 'path';
33
import { exec } from 'child_process';
4-
import {fileURLToPath} from "url";
4+
import { fileURLToPath } from 'url';
5+
import { expect } from 'chai';
56

67
const __dirname = dirname(fileURLToPath(import.meta.url));
78
const runner = path.join(__dirname, '../../bin/codecept.js');
@@ -10,6 +11,7 @@ const codecept_dir = path.join(__dirname, '../../test/data/sandbox');
1011
describe('list commands', () => {
1112
it('list should print actions', (done) => {
1213
exec(`${runner} list ${codecept_dir}`, (err, stdout) => {
14+
console.log(stdout, err)
1315
expect(stdout).to.include('FileSystem'); // helper name
1416
expect(stdout).to.include('FileSystem I.amInPath(openPath)'); // action name
1517
expect(stdout).to.include('FileSystem I.seeFile(name)');

test/runner/run_multiple_test.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -180,20 +180,20 @@ describe('CodeceptJS Multiple Runner', function () {
180180
it('should exit with non-zero code for failures during init process', (done) => {
181181
process.chdir(codecept_dir);
182182
exec(`${runner} run-multiple --config codecept.multiple.initFailure.js default --all`, (err, stdout) => {
183-
expect(err).not.toBeFalsy();
183+
expect(err).not.to.false;
184184
expect(err.code).toBe(1);
185-
expect(stdout).toContain('Failed on FailureHelper');
185+
expect(stdout).contain('Failed on FailureHelper');
186186
done();
187187
});
188188
});
189189

190190
it('should exit code 1 when error in config', (done) => {
191191
process.chdir(codecept_dir);
192192
exec(`${runner} run-multiple --config configs/codecept-invalid.config.js default --all`, (err, stdout, stderr) => {
193-
expect(stdout).not.toContain('UnhandledPromiseRejectionWarning');
194-
expect(stderr).not.toContain('UnhandledPromiseRejectionWarning');
195-
expect(stdout).toContain('badFn is not defined');
196-
expect(err).not.toBe(null);
193+
expect(stdout).not.contain('UnhandledPromiseRejectionWarning');
194+
expect(stderr).not.contain('UnhandledPromiseRejectionWarning');
195+
expect(stdout).contain('badFn is not defined');
196+
expect(err).not.null;
197197
done();
198198
});
199199
});

test/runner/run_rerun_test.js

+8-6
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,24 @@
11
import { expect } from 'expect';
22
import { describe } from 'mocha';
3-
import path from 'path';
3+
import path, { dirname } from 'path';
44
import { exec } from 'child_process';
5-
import semver from 'semver';
5+
import { fileURLToPath } from 'url';
66

7-
const __dirname = path.resolve('.');
8-
const runner = path.join(__dirname, 'bin/codecept.js');
9-
const codecept_dir = path.join(__dirname, 'test/data/sandbox/configs/run-rerun/');
7+
const __dirname = dirname(fileURLToPath(import.meta.url));
8+
const runner = path.join(__dirname, '../../bin/codecept.js');
9+
const codecept_dir = path.join(__dirname, '../../test/data/sandbox/configs/run-rerun');
1010
const codecept_run = `${runner} run-rerun`;
1111
const codecept_run_config = (config, grep) => `${codecept_run} --config ${codecept_dir}/${config} --grep "${grep || ''}"`;
1212

1313
describe('run-rerun command', () => {
1414
before(() => {
15+
global.codecept_dir = codecept_dir;
1516
process.chdir(codecept_dir);
1617
});
1718

18-
it('should display count of attemps', (done) => {
19+
it('should display count of attempts', (done) => {
1920
exec(`${codecept_run_config('codecept.conf.js')} --debug`, (err, stdout) => {
21+
console.log(err, stdout)
2022
const runs = stdout.split('Run Rerun - Command --');
2123

2224
// check first run

test/runner/session_test.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
import path, {dirname} from 'path';
1+
import path, { dirname } from 'path';
22
import { exec } from 'child_process';
3-
import {fileURLToPath} from "url";
3+
import { fileURLToPath } from 'url';
4+
import { grepLines } from '../../lib/utils.js';
45

56
const __dirname = dirname(fileURLToPath(import.meta.url));
67
const runner = path.join(__dirname, '../../bin/codecept.js');

test/runner/within_test.js

+7-11
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import path, {dirname} from 'path';
1+
import path, { dirname } from 'path';
22
import { exec } from 'child_process';
33
import { expect } from 'chai';
4+
import { fileURLToPath } from 'url';
45
import { grepLines } from '../../lib/utils.js';
5-
import {fileURLToPath} from "url";
66

77
const __dirname = dirname(fileURLToPath(import.meta.url));
88
const runner = path.join(__dirname, '../../bin/codecept.js');
@@ -19,20 +19,16 @@ describe('CodeceptJS within', function () {
1919
});
2020

2121
it('should execute if no generators', (done) => {
22-
exec(`${codecept_run} --verbose`, (_err, stdout) => {
23-
console.log(`${codecept_run} --debug`)
22+
exec(`${codecept_run} --steps`, (_err, stdout) => {
2423
const lines = stdout.match(/\S.+/g);
2524

2625
const withoutGeneratorList = grepLines(lines, 'Check within without generator', 'Check within with generator. Yield is first in order');
27-
testStatus = withoutGeneratorList.pop();
28-
expect(testStatus).to.include('OK');
29-
withoutGeneratorList.should.eql([
30-
'I small promise ',
31-
'I small promise was finished ',
32-
'I hey! i am within begin. i get blabla ',
26+
expect(lines.join(' ')).to.include('OK');
27+
expect(lines).to.include.members([
28+
'I small promise',
29+
'I hey! i am within begin. i get blabla',
3330
'Within "blabla" ""',
3431
'I small promise ',
35-
'I small promise was finished ',
3632
'I oh! i am within end( ',
3733
], 'check steps execution order');
3834
done();

0 commit comments

Comments
 (0)