Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft: Migrate to esm #4229

Draft
wants to merge 35 commits into
base: 4.x
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
024ec5b
WIP
kobenguyent Feb 20, 2024
4e28312
fix: more UTs
kobenguyent Feb 20, 2024
0cc967e
fix: more tests
kobenguyent Feb 21, 2024
f535d49
fix: more tests
kobenguyent Feb 21, 2024
33ccd9b
fix: more tests
kobenguyent Feb 22, 2024
41e22d3
fix: unit tests
kobenguyent Feb 22, 2024
2b404b0
fix: unit tests
kobenguyent Feb 22, 2024
462e1de
fix: output module
kobenguyent Feb 23, 2024
e46c79b
fix: runner tests
kobenguyent Feb 23, 2024
82d892b
fix: more runner tests
kobenguyent Feb 23, 2024
1c790ee
fix: more runner tests
kobenguyent Feb 23, 2024
2f1cfe6
Merge branch '3.x' into migrate-to-esm
kobenguyent Mar 6, 2024
8115f4a
fix: MockServer_test.js
kobenguyent Mar 6, 2024
c09919c
fix: more tests and export __dirname
kobenguyent Mar 7, 2024
afd5245
fix: more test/unit
kobenguyent Mar 7, 2024
733de43
fix: tryTo plugin
kobenguyent Mar 7, 2024
5b1f101
fix: tryTo plugin
kobenguyent Mar 7, 2024
9bea75d
fix: tryTo plugin
kobenguyent Mar 7, 2024
d55aaed
fix: tryTo plugin
kobenguyent Mar 7, 2024
f4129b1
fix: fixDefFiles.js
kobenguyent Mar 7, 2024
81c103d
fix: bdd_test
kobenguyent Mar 11, 2024
ac57fea
merged with 3.x branch
kobenguyent Mar 30, 2024
37d4c21
try to fix plugin tests
kobenguyent Mar 30, 2024
35584c4
bump monocart coverage version
kobenguyent Mar 31, 2024
9860591
fix: conflicts
kobenguyent Apr 2, 2024
0601089
fix: failed UTs
kobenguyent Apr 2, 2024
7cb26c7
fix tests
kobenguyent Apr 8, 2024
1c8318f
fix: help_test.js
kobenguyent Apr 19, 2024
fb98821
fix some dry-run tests
kobenguyent Apr 19, 2024
2b62f7b
fix conflict
kobenguyent Sep 23, 2024
79f012b
fix: soft expect helper tests
kobenguyent Sep 23, 2024
a7e5a76
fix: screenshotOnFail tests
kobenguyent Sep 23, 2024
8e2fc37
fix: codepcept-js code and types
kobenguyent Sep 23, 2024
6f5f03b
fix: gherkin_test and scenario stale test
kobenguyent Sep 23, 2024
b5f9f3a
fix: actions, playwright, pw_test, stepbystep report, webapi
kobenguyent Sep 23, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
55 changes: 55 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
{
"extends": "airbnb-base",
"env": {
"node": true
},
"parserOptions": {
"ecmaVersion": 2020
},
"rules": {
"func-names": 0,
"no-use-before-define": 0,
"no-unused-vars": 0,
"no-underscore-dangle": 0,
"no-undef": 0,
"prefer-destructuring": 0,
"no-param-reassign": 0,
"max-len": 0,
"camelcase": 0,
"no-shadow": 0,
"consistent-return": 0,
"no-console": 0,
"global-require": 0,
"class-methods-use-this": 0,
"no-plusplus": 0,
"no-return-assign": 0,
"prefer-rest-params": 0,
"no-useless-escape": 0,
"no-restricted-syntax": 0,
"no-unused-expressions": 0,
"guard-for-in": 0,
"no-multi-assign": 0,
"require-yield": 0,
"prefer-spread": 0,
"import/no-dynamic-require": 0,
"no-continue": 0,
"no-mixed-operators": 0,
"default-case": 0,
"import/no-extraneous-dependencies": 0,
"no-cond-assign": 0,
"import/no-unresolved": 0,
"no-await-in-loop": 0,
"arrow-body-style": 0,
"no-loop-func": 0,
"arrow-parens": 0,
"default-param-last": 0,
"import/extensions": 0,
"no-return-await": "off",
"import/prefer-default-export": 0,
"import/no-named-as-default-member": 0,
"import/no-named-default": 0,
"import/no-cycle": 0,
"prefer-const": "off",
"no-import-assign": 0
}
}
4 changes: 2 additions & 2 deletions .mocharc.js → .mocharc#.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module.exports = {
export default {
"require": "./test/support/setup.js"
}
};
165 changes: 81 additions & 84 deletions bin/codecept.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,26 @@
#!/usr/bin/env node
const program = require('commander')
const Codecept = require('../lib/codecept')
const { print, error } = require('../lib/output')
const { printError } = require('../lib/command/utils')
import { Command } from 'commander';
import { version } from '../lib/codecept.js';
import * as outputLib from '../lib/output.js';
import { printError } from '../lib/command/utils.js';
import * as init from '../lib/command/init.js';
import * as configMigrate from '../lib/command/configMigrate.js';
import * as interactive from '../lib/command/interactive.js';
import * as definitions from '../lib/command/definitions.js';
import * as list from '../lib/command/list.js';
import * as gherkinInit from '../lib/command/gherkin/init.js';
import * as gherkinSteps from '../lib/command/gherkin/steps.js';
import * as gherkinSnippets from '../lib/command/gherkin/snippets.js';
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 { runRerun } from '../lib/command/run-rerun.js';
import * as dryRun from '../lib/command/dryRun.js';
import * as info from '../lib/command/info.js';
import { heal } from "../lib/command/generate.js";

const program = new Command();

const commandFlags = {
ai: {
Expand All @@ -29,120 +47,104 @@ const commandFlags = {
flag: '--steps',
description: 'show step-by-step execution',
},
}

const errorHandler =
(fn) =>
async (...args) => {
try {
await fn(...args)
} catch (e) {
printError(e)
process.exitCode = 1
}
};

const errorHandler = (fn) => async (...args) => {
try {
await fn.default(...args);
} catch (e) {
printError(e);
process.exitCode = 1;
}
};

if (process.versions.node && process.versions.node.split('.') && process.versions.node.split('.')[0] < 12) {
error('NodeJS >= 12 is required to run.')
print()
print('Please upgrade your NodeJS engine')
print(`Current NodeJS version: ${process.version}`)
process.exit(1)
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}`);
process.exit(1);
}

program.usage('<command> [options]')
program.version(Codecept.version())
program.usage('<command> [options]');
program.version(version());

program
.command('init [path]')
program.command('init [path]')
.description('Creates dummy config in current dir or [path]')
.action(errorHandler(require('../lib/command/init')))
.action(errorHandler(init));

program
.command('migrate [path]')
program.command('migrate [path]')
.description('Migrate json config to js config in current dir or [path]')
.action(errorHandler(require('../lib/command/configMigrate')))
.action(errorHandler(configMigrate));

program
.command('shell [path]')
program.command('shell [path]')
.alias('sh')
.description('Interactive shell')
.option(commandFlags.verbose.flag, commandFlags.verbose.description)
.option(commandFlags.profile.flag, commandFlags.profile.description)
.option(commandFlags.ai.flag, commandFlags.ai.description)
.option(commandFlags.config.flag, commandFlags.config.description)
.action(errorHandler(require('../lib/command/interactive')))
.action(errorHandler(interactive));

program
.command('list [path]')
program.command('list [path]')
.alias('l')
.description('List all actions for I.')
.action(errorHandler(require('../lib/command/list')))
.action(errorHandler(list));

program
.command('def [path]')
program.command('def [path]')
.description('Generates TypeScript definitions for all I actions.')
.option(commandFlags.config.flag, commandFlags.config.description)
.option('-o, --output [folder]', 'target folder to paste definitions')
.action(errorHandler(require('../lib/command/definitions')))
.action(errorHandler(definitions));

program
.command('gherkin:init [path]')
program.command('gherkin:init [path]')
.alias('bdd:init')
.description('Prepare CodeceptJS to run feature files.')
.option(commandFlags.config.flag, commandFlags.config.description)
.action(errorHandler(require('../lib/command/gherkin/init')))
.action(errorHandler(gherkinInit));

program
.command('gherkin:steps [path]')
program.command('gherkin:steps [path]')
.alias('bdd:steps')
.description('Prints all defined gherkin steps.')
.option(commandFlags.config.flag, commandFlags.config.description)
.action(errorHandler(require('../lib/command/gherkin/steps')))
.action(errorHandler(gherkinSteps));

program
.command('gherkin:snippets [path]')
program.command('gherkin:snippets [path]')
.alias('bdd:snippets')
.description('Generate step definitions from steps.')
.option('--dry-run', "don't save snippets to file")
.option(commandFlags.config.flag, commandFlags.config.description)
.option('--feature [file]', 'feature files(s) to scan')
.option('--path [file]', 'file in which to place the new snippets')
.action(errorHandler(require('../lib/command/gherkin/snippets')))
.action(errorHandler(gherkinSnippets));

program
.command('generate:test [path]')
program.command('generate:test [path]')
.alias('gt')
.description('Generates an empty test')
.action(errorHandler(require('../lib/command/generate').test))
.action(errorHandler(generate.test));

program
.command('generate:pageobject [path]')
program.command('generate:pageobject [path]')
.alias('gpo')
.description('Generates an empty page object')
.action(errorHandler(require('../lib/command/generate').pageObject))
.action(errorHandler(generate.pageObject));

program
.command('generate:object [path]')
program.command('generate:object [path]')
.alias('go')
.option('--type, -t [kind]', 'type of object to be created')
.description('Generates an empty support object (page/step/fragment)')
.action(errorHandler(require('../lib/command/generate').pageObject))
.action(errorHandler(generate.pageObject));

program
.command('generate:helper [path]')
program.command('generate:helper [path]')
.alias('gh')
.description('Generates a new helper')
.action(errorHandler(require('../lib/command/generate').helper))
.action(errorHandler(generate.helper));

program
.command('generate:heal [path]')
program.command('generate:heal [path]')
.alias('gr')
.description('Generates basic heal recipes')
.action(errorHandler(require('../lib/command/generate').heal))
.action(errorHandler(heal));

program
.command('run [test]')
program.command('run [test]')
.description('Executes tests')

// codecept-only options
Expand Down Expand Up @@ -178,10 +180,9 @@ program
.option('--recursive', 'include sub directories')
.option('--trace', 'trace function calls')
.option('--child <string>', 'option for child processes')
.action(errorHandler(require('../lib/command/run')))
.action(errorHandler(run));

program
.command('run-workers <workers> [selectedRuns...]')
program.command('run-workers <workers> [selectedRuns...]')
.description('Executes tests in workers')
.option(commandFlags.config.flag, commandFlags.config.description)
.option('-g, --grep <pattern>', 'only run tests matching <pattern>')
Expand All @@ -197,10 +198,9 @@ program
.option('-p, --plugins <k=v,k2=v2,...>', 'enable plugins, comma-separated')
.option('-O, --reporter-options <k=v,k2=v2,...>', 'reporter-specific options')
.option('-R, --reporter <name>', 'specify the reporter to use')
.action(errorHandler(require('../lib/command/run-workers')))
.action(errorHandler(runWorkers));

program
.command('run-multiple [suites...]')
program.command('run-multiple [suites...]')
.description('Executes tests multiple')
.option(commandFlags.config.flag, commandFlags.config.description)
.option(commandFlags.profile.flag, commandFlags.profile.description)
Expand All @@ -223,16 +223,14 @@ program
// mocha options
.option('--colors', 'force enabling of colors')

.action(errorHandler(require('../lib/command/run-multiple')))
.action(errorHandler(runMultiple));

program
.command('info [path]')
program.command('info [path]')
.description('Print debugging information concerning the local environment')
.option('-c, --config', 'your config file path')
.action(errorHandler(require('../lib/command/info')))
.action(errorHandler(info));

program
.command('dry-run [test]')
program.command('dry-run [test]')
.description('Prints step-by-step scenario for a test without actually running it')
.option('-p, --plugins <k=v,k2=v2,...>', 'enable plugins, comma-separated')
.option('--bootstrap', 'enable bootstrap & teardown scripts for dry-run')
Expand All @@ -246,10 +244,9 @@ program
.option(commandFlags.steps.flag, commandFlags.steps.description)
.option(commandFlags.verbose.flag, commandFlags.verbose.description)
.option(commandFlags.debug.flag, commandFlags.debug.description)
.action(errorHandler(require('../lib/command/dryRun')))
.action(errorHandler(dryRun));

program
.command('run-rerun [test]')
program.command('run-rerun [test]')
.description('Executes tests in more than one test suite run')

// codecept-only options
Expand Down Expand Up @@ -284,15 +281,15 @@ program
.option('--trace', 'trace function calls')
.option('--child <string>', 'option for child processes')

.action(require('../lib/command/run-rerun'))
.action(runRerun);

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

if (process.argv.length <= 2) {
program.outputHelp()
program.outputHelp();
} else {
program.parse(process.argv)
program.parse(process.argv);
}
Loading
Loading