From a8e7de979f8dc94b6ff7f61987f2f310772aca92 Mon Sep 17 00:00:00 2001 From: kobenguyent Date: Tue, 5 Mar 2024 11:59:24 +0100 Subject: [PATCH] fix: improve codeceptjs bin --- bin/codecept.js | 95 +++++++++++++++++++++++++++++++------------------ 1 file changed, 61 insertions(+), 34 deletions(-) diff --git a/bin/codecept.js b/bin/codecept.js index 5fc36bee0..2751ea452 100755 --- a/bin/codecept.js +++ b/bin/codecept.js @@ -4,6 +4,33 @@ const Codecept = require('../lib/codecept'); const { print, error } = require('../lib/output'); const { printError } = require('../lib/command/utils'); +const commandFlags = { + ai: { + flag: '--ai', + description: 'enable AI assistant', + }, + verbose: { + flag: '--verbose', + description: 'output internal logging information', + }, + debug: { + flag: '--debug', + description: 'output additional information', + }, + config: { + flag: '-c, --config [file]', + description: 'configuration file to be used', + }, + profile: { + flag: '--profile [value]', + description: 'configuration profile to be used', + }, + steps: { + flag: '--steps', + description: 'show step-by-step execution', + }, +}; + const errorHandler = (fn) => async (...args) => { try { await fn(...args); @@ -35,10 +62,10 @@ program.command('migrate [path]') program.command('shell [path]') .alias('sh') .description('Interactive shell') - .option('--verbose', 'output internal logging information') - .option('--profile [value]', 'configuration profile to be used') - .option('--ai', 'enable AI assistant') - .option('-c, --config [file]', 'configuration file to be used') + .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'))); program.command('list [path]') @@ -48,27 +75,27 @@ program.command('list [path]') program.command('def [path]') .description('Generates TypeScript definitions for all I actions.') - .option('-c, --config [file]', 'configuration file to be used') + .option(commandFlags.config.flag, commandFlags.config.description) .option('-o, --output [folder]', 'target folder to paste definitions') .action(errorHandler(require('../lib/command/definitions'))); program.command('gherkin:init [path]') .alias('bdd:init') .description('Prepare CodeceptJS to run feature files.') - .option('-c, --config [file]', 'configuration file to be used') + .option(commandFlags.config.flag, commandFlags.config.description) .action(errorHandler(require('../lib/command/gherkin/init'))); program.command('gherkin:steps [path]') .alias('bdd:steps') .description('Prints all defined gherkin steps.') - .option('-c, --config [file]', 'configuration file to be used') + .option(commandFlags.config.flag, commandFlags.config.description) .action(errorHandler(require('../lib/command/gherkin/steps'))); program.command('gherkin:snippets [path]') .alias('bdd:snippets') .description('Generate step definitions from steps.') .option('--dry-run', "don't save snippets to file") - .option('-c, --config [file]', 'configuration file to be used') + .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'))); @@ -98,13 +125,13 @@ program.command('run [test]') .description('Executes tests') // codecept-only options - .option('--ai', 'enable AI assistant') - .option('--steps', 'show step-by-step execution') - .option('--debug', 'output additional information') - .option('--verbose', 'output internal logging information') + .option(commandFlags.ai.flag, commandFlags.ai.description) + .option(commandFlags.steps.flag, commandFlags.steps.description) + .option(commandFlags.debug.flag, commandFlags.debug.description) + .option(commandFlags.verbose.flag, commandFlags.verbose.description) .option('-o, --override [value]', 'override current config options') - .option('--profile [value]', 'configuration profile to be used') - .option('-c, --config [file]', 'configuration file to be used') + .option(commandFlags.profile.flag, commandFlags.profile.description) + .option(commandFlags.config.flag, commandFlags.config.description) .option('--features', 'run only *.feature files and skip tests') .option('--tests', 'run only JS test files and skip features') .option('--no-timeouts', 'disable all timeouts') @@ -134,17 +161,17 @@ program.command('run [test]') program.command('run-workers [selectedRuns...]') .description('Executes tests in workers') - .option('-c, --config [file]', 'configuration file to be used') + .option(commandFlags.config.flag, commandFlags.config.description) .option('-g, --grep ', 'only run tests matching ') .option('-i, --invert', 'inverts --grep matches') .option('-o, --override [value]', 'override current config options') .option('--suites', 'parallel execution of suites not single tests') - .option('--debug', 'output additional information') - .option('--verbose', 'output internal logging information') + .option(commandFlags.debug.flag, commandFlags.debug.description) + .option(commandFlags.verbose.flag, commandFlags.verbose.description) .option('--features', 'run only *.feature files and skip tests') .option('--tests', 'run only JS test files and skip features') - .option('--profile [value]', 'configuration profile to be used') - .option('--ai', 'enable AI assistant') + .option(commandFlags.profile.flag, commandFlags.profile.description) + .option(commandFlags.ai.flag, commandFlags.ai.description) .option('-p, --plugins ', 'enable plugins, comma-separated') .option('-O, --reporter-options ', 'reporter-specific options') .option('-R, --reporter ', 'specify the reporter to use') @@ -152,18 +179,18 @@ program.command('run-workers [selectedRuns...]') program.command('run-multiple [suites...]') .description('Executes tests multiple') - .option('-c, --config [file]', 'configuration file to be used') - .option('--profile [value]', 'configuration profile to be used') + .option(commandFlags.config.flag, commandFlags.config.description) + .option(commandFlags.profile.flag, commandFlags.profile.description) .option('--all', 'run all suites') .option('--features', 'run only *.feature files and skip tests') .option('--tests', 'run only JS test files and skip features') - .option('--ai', 'enable AI assistant') + .option(commandFlags.ai.flag, commandFlags.ai.description) .option('-g, --grep ', 'only run tests matching ') .option('-f, --fgrep ', 'only run tests containing ') .option('-i, --invert', 'inverts --grep and --fgrep matches') - .option('--steps', 'show step-by-step execution') - .option('--verbose', 'output internal logging information') - .option('--debug', 'output additional information') + .option(commandFlags.steps.flag, commandFlags.steps.description) + .option(commandFlags.verbose.flag, commandFlags.verbose.description) + .option(commandFlags.debug.flag, commandFlags.debug.description) .option('-p, --plugins ', 'enable plugins, comma-separated') .option('-o, --override [value]', 'override current config options') .option('-O, --reporter-options ', 'reporter-specific options') @@ -184,28 +211,28 @@ program.command('dry-run [test]') .description('Prints step-by-step scenario for a test without actually running it') .option('-p, --plugins ', 'enable plugins, comma-separated') .option('--bootstrap', 'enable bootstrap & teardown scripts for dry-run') - .option('-c, --config [file]', 'configuration file to be used') + .option(commandFlags.config.flag, commandFlags.config.description) .option('--all', 'run all suites') .option('--features', 'run only *.feature files and skip tests') .option('--tests', 'run only JS test files and skip features') .option('-g, --grep ', 'only run tests matching ') .option('-f, --fgrep ', 'only run tests containing ') .option('-i, --invert', 'inverts --grep and --fgrep matches') - .option('--steps', 'show step-by-step execution') - .option('--verbose', 'output internal logging information') - .option('--debug', 'output additional information') + .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'))); program.command('run-rerun [test]') .description('Executes tests in more than one test suite run') // codecept-only options - .option('--steps', 'show step-by-step execution') - .option('--debug', 'output additional information') - .option('--verbose', 'output internal logging information') + .option(commandFlags.steps.flag, commandFlags.steps.description) + .option(commandFlags.debug.flag, commandFlags.debug.description) + .option(commandFlags.verbose.flag, commandFlags.verbose.description) .option('-o, --override [value]', 'override current config options') - .option('--profile [value]', 'configuration profile to be used') - .option('-c, --config [file]', 'configuration file to be used') + .option(commandFlags.profile.flag, commandFlags.profile.description) + .option(commandFlags.config.flag, commandFlags.config.description) .option('--features', 'run only *.feature files and skip tests') .option('--tests', 'run only JS test files and skip features') .option('-p, --plugins ', 'enable plugins, comma-separated')