Skip to content

Commit

Permalink
fix: more runner tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kobenguyent committed Feb 23, 2024
1 parent 82d892b commit 1c790ee
Show file tree
Hide file tree
Showing 13 changed files with 72 additions and 64 deletions.
4 changes: 2 additions & 2 deletions bin/codecept.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import * as generate from '../lib/command/generate.js';
import * as run from '../lib/command/run.js';
import * as runWorkers from '../lib/command/run-workers.js';
import * as runMultiple from '../lib/command/run-multiple.js';
import * as rerun from '../lib/command/run-rerun.js';
import { runRerun } from '../lib/command/run-rerun.js';
import * as dryRun from '../lib/command/dryRun.js';
import * as info from '../lib/command/info.js';

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

.action(rerun);
.action(runRerun);

program.on('command:*', (cmd) => {
console.log(`\nUnknown command ${cmd}\n`);
Expand Down
4 changes: 2 additions & 2 deletions lib/command/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export default function (path) {
methodsOfObject(helper).forEach((action) => {
const params = getParamsToString(helper[action]);
actions[action] = 1;
output.print(` ${output.colors.grey(name)} I.${output.colors.bold(action)}(${params})`);
output.print(` ${output.output.colors.grey(name)} I.${output.output.colors.bold(action)}(${params})`);
});
}
for (const name in supportI) {
Expand All @@ -29,7 +29,7 @@ export default function (path) {
}
const actor = supportI[name];
const params = getParamsToString(actor);
output.print(` I.${output.colors.bold(name)}(${params})`);
output.print(` I.${output.output.colors.bold(name)}(${params})`);
}
output.print('PS: Actions are retrieved from enabled helpers. ');
output.print('Implement custom actions in your helper classes.');
Expand Down
1 change: 0 additions & 1 deletion lib/command/run-multiple.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import { getConfig, getTestRoot, fail } from './utils.js';
const __dirname = dirname(fileURLToPath(import.meta.url));

const runner = path.join(__dirname, '../../bin/codecept.js');
console.log(runner)
let config;
const childOpts = {};
const copyOptions = ['override', 'steps', 'reporter', 'verbose', 'config', 'reporter-options', 'grep', 'fgrep', 'invert', 'debug', 'plugins', 'colors'];
Expand Down
2 changes: 1 addition & 1 deletion lib/command/run-rerun.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
import Config from '../config.js';
import Codecept from '../rerun.js';

export default async function (test, options) {
export async function runRerun(test, options) {
// registering options globally to use in config
// Backward compatibility for --profile
process.profile = options.profile;
Expand Down
4 changes: 2 additions & 2 deletions lib/rerun.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class CodeceptRerunner extends BaseCodecept {
container.createMocha();
const mocha = container.mocha();
this.testFiles.forEach((file) => {
delete require.cache[file];
// delete require.cache[file];
});
mocha.files = this.testFiles;
if (test) {
Expand Down Expand Up @@ -53,7 +53,7 @@ class CodeceptRerunner extends BaseCodecept {
try {
await this.runOnce(test);
successCounter++;
output.success(`\nProcess run ${rerunsCounter} of max ${maxReruns}, success runs ${successCounter}/${minSuccess}\n`);
output.output.success(`\nProcess run ${rerunsCounter} of max ${maxReruns}, success runs ${successCounter}/${minSuccess}\n`);
} catch (e) {
output.output.error(`\nFail run ${rerunsCounter} of max ${maxReruns}, success runs ${successCounter}/${minSuccess} \n`);
console.error(e);
Expand Down
19 changes: 10 additions & 9 deletions runok.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
#!/usr/bin/env node
const fs = require('fs');
const path = require('path');
const axios = require('axios');
const documentation = require('documentation');
import fs from 'fs';
import path from 'path';
import axios from 'axios';
import documentation from 'documentation';
import runok0 from 'runok';
import contributors from 'contributor-faces';

const {
stopOnFail, chdir, tasks: {
git, copy, exec, replaceInFile, npmRun, npx, writeToFile,
}, runok,
} = require('runok');
const contributors = require('contributor-faces');

} = runok0;
const helperMarkDownFile = function (name) {
return `docs/helpers/${name}.md`;
};
const documentjsCliArgs = '-f md --shallow --markdown-toc=false --sort-order=alpha';

stopOnFail();

module.exports = {
export default {
async docs() {
// generate all docs (runs all docs:* commands in parallel)
await Promise.all([
Expand Down Expand Up @@ -491,4 +492,4 @@ async function processChangelog() {
});
}

if (require.main === module) runok(module.exports);
//if (require.main === module) runok(module.exports);
4 changes: 3 additions & 1 deletion test/data/sandbox/configs/step_timeout/first_test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
const given = when = then = global.codeceptjs.container.plugins('commentStep');
const Container = require('../../../../../lib/container.js').default;

const given = when = then = Container.plugins('commentStep');
const { I } = inject();

Feature('Steps');
Expand Down
43 changes: 24 additions & 19 deletions test/runner/definitions_test.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
import fs from 'fs';
import assert from 'assert';
import path from 'path';
import path, { dirname } from 'path';
import { exec, execSync } from 'child_process';
import { Project, StructureKind, ts } from 'ts-morph';
import { expect } from 'chai';

import chai_subset from 'chai-subset';
import { fileURLToPath } from 'url';
import { createRequire } from 'node:module';

const __dirname = path.resolve('.');
const runner = path.join(__dirname, 'bin/codecept.js');
const codecept_dir = path.join(__dirname, 'test/data/sandbox/configs/definitions');
const require = createRequire(import.meta.url);

const __dirname = dirname(fileURLToPath(import.meta.url));
const runner = path.join(__dirname, '../../bin/codecept.js');
const codecept_dir = path.join(__dirname, '../../test/data/sandbox/configs/definitions');
const pathToRootOfProject = path.join(__dirname, '../../');
const pathOfStaticDefinitions = path.join(pathToRootOfProject, 'typings/index.d.ts');
const pathOfJSDocDefinitions = path.join(pathToRootOfProject, 'typings/types.d.ts');
Expand Down Expand Up @@ -54,19 +59,19 @@ describe('Definitions', function () {
it('should have internal object that is available as variable codeceptjs', (done) => {
exec(`${runner} def --config ${codecept_dir}/codecept.inject.po.js`, () => {
const types = typesFrom(`${codecept_dir}/steps.d.ts`);
types.should.be.valid;
expect(types).to.be.valid;

const definitionsFile = types.getSourceFileOrThrow(pathOfJSDocDefinitions);
const index = definitionsFile.getModule('CodeceptJS').getModule('index').getStructure();
index.statements.should.containSubset([
expect(index.statements).to.containSubset([
{ declarations: [{ name: 'recorder', type: 'CodeceptJS.recorder' }] },
{ declarations: [{ name: 'event', type: 'typeof CodeceptJS.event' }] },
{ declarations: [{ name: 'output', type: 'typeof CodeceptJS.output' }] },
{ declarations: [{ name: 'config', type: 'typeof CodeceptJS.Config' }] },
{ declarations: [{ name: 'container', type: 'typeof CodeceptJS.Container' }] },
]);
const codeceptjs = types.getSourceFileOrThrow(pathOfStaticDefinitions).getVariableDeclarationOrThrow('codeceptjs').getStructure();
codeceptjs.type.should.equal('typeof CodeceptJS.index');
expect(codeceptjs.type).to.equal('typeof CodeceptJS.index');
done();
});
});
Expand All @@ -76,11 +81,11 @@ describe('Definitions', function () {
exec(`${runner} def ${codecept_dir}`, (err, stdout) => {
expect(stdout).to.include('Definitions were generated in steps.d.ts');
const types = typesFrom(`${codecept_dir}/steps.d.ts`);
types.should.be.valid;
expect(types).to.valid;

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

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

extend.should.include("type CurrentPage = typeof import('./po/custom_steps.js');");
expect(extend).to.include("type CurrentPage = typeof import('./po/custom_steps.js');");
assert(!err);
done();
});
Expand All @@ -115,7 +120,7 @@ describe('Definitions', function () {
exec(`${runner} def --config ${codecept_dir}/../../codecept.ddt.js`, (err, stdout) => {
expect(stdout).to.include('Definitions were generated in steps.d.ts');
const types = typesFrom(`${codecept_dir}/../../steps.d.ts`);
types.should.be.valid;
expect(types).to.valid;
assert(!err);
done();
});
Expand All @@ -124,7 +129,7 @@ describe('Definitions', function () {
it('def should create definition file with support object', (done) => {
exec(`${runner} def --config ${codecept_dir}/codecept.inject.po.js`, () => {
const types = typesFrom(`${codecept_dir}/steps.d.ts`);
types.should.be.valid;
expect(types).to.valid;

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

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

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

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

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

const definitionFile = types.getSourceFileOrThrow(`${codecept_dir}/steps.d.ts`);
const extend = getExtends(definitionFile.getModule('CodeceptJS').getInterfaceOrThrow('I'));
extend.should.containSubset([{
expect(extend).to.containSubset([{
methods: [{
name: 'amInPath',
returnType: 'Promise<any>',
Expand Down
6 changes: 4 additions & 2 deletions test/runner/list_test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import assert from 'assert';
import path, {dirname} from 'path';
import path, { dirname } from 'path';
import { exec } from 'child_process';
import {fileURLToPath} from "url";
import { fileURLToPath } from 'url';
import { expect } from 'chai';

const __dirname = dirname(fileURLToPath(import.meta.url));
const runner = path.join(__dirname, '../../bin/codecept.js');
Expand All @@ -10,6 +11,7 @@ const codecept_dir = path.join(__dirname, '../../test/data/sandbox');
describe('list commands', () => {
it('list should print actions', (done) => {
exec(`${runner} list ${codecept_dir}`, (err, stdout) => {
console.log(stdout, err)
expect(stdout).to.include('FileSystem'); // helper name
expect(stdout).to.include('FileSystem I.amInPath(openPath)'); // action name
expect(stdout).to.include('FileSystem I.seeFile(name)');
Expand Down
12 changes: 6 additions & 6 deletions test/runner/run_multiple_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,20 +180,20 @@ describe('CodeceptJS Multiple Runner', function () {
it('should exit with non-zero code for failures during init process', (done) => {
process.chdir(codecept_dir);
exec(`${runner} run-multiple --config codecept.multiple.initFailure.js default --all`, (err, stdout) => {
expect(err).not.toBeFalsy();
expect(err).not.to.false;
expect(err.code).toBe(1);
expect(stdout).toContain('Failed on FailureHelper');
expect(stdout).contain('Failed on FailureHelper');
done();
});
});

it('should exit code 1 when error in config', (done) => {
process.chdir(codecept_dir);
exec(`${runner} run-multiple --config configs/codecept-invalid.config.js default --all`, (err, stdout, stderr) => {
expect(stdout).not.toContain('UnhandledPromiseRejectionWarning');
expect(stderr).not.toContain('UnhandledPromiseRejectionWarning');
expect(stdout).toContain('badFn is not defined');
expect(err).not.toBe(null);
expect(stdout).not.contain('UnhandledPromiseRejectionWarning');
expect(stderr).not.contain('UnhandledPromiseRejectionWarning');
expect(stdout).contain('badFn is not defined');
expect(err).not.null;
done();
});
});
Expand Down
14 changes: 8 additions & 6 deletions test/runner/run_rerun_test.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
import { expect } from 'expect';
import { describe } from 'mocha';
import path from 'path';
import path, { dirname } from 'path';
import { exec } from 'child_process';
import semver from 'semver';
import { fileURLToPath } from 'url';

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

describe('run-rerun command', () => {
before(() => {
global.codecept_dir = codecept_dir;
process.chdir(codecept_dir);
});

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

// check first run
Expand Down
5 changes: 3 additions & 2 deletions test/runner/session_test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import path, {dirname} from 'path';
import path, { dirname } from 'path';
import { exec } from 'child_process';
import {fileURLToPath} from "url";
import { fileURLToPath } from 'url';
import { grepLines } from '../../lib/utils.js';

const __dirname = dirname(fileURLToPath(import.meta.url));
const runner = path.join(__dirname, '../../bin/codecept.js');
Expand Down
18 changes: 7 additions & 11 deletions test/runner/within_test.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import path, {dirname} from 'path';
import path, { dirname } from 'path';
import { exec } from 'child_process';
import { expect } from 'chai';
import { fileURLToPath } from 'url';
import { grepLines } from '../../lib/utils.js';
import {fileURLToPath} from "url";

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

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

const withoutGeneratorList = grepLines(lines, 'Check within without generator', 'Check within with generator. Yield is first in order');
testStatus = withoutGeneratorList.pop();
expect(testStatus).to.include('OK');
withoutGeneratorList.should.eql([
'I small promise ',
'I small promise was finished ',
'I hey! i am within begin. i get blabla ',
expect(lines.join(' ')).to.include('OK');
expect(lines).to.include.members([
'I small promise',
'I hey! i am within begin. i get blabla',
'Within "blabla" ""',
'I small promise ',
'I small promise was finished ',
'I oh! i am within end( ',
], 'check steps execution order');
done();
Expand Down

0 comments on commit 1c790ee

Please sign in to comment.