Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,21 @@ module.exports = {
'no-loop-func': 0,
'arrow-parens': 0,
'default-param-last': 0,
semi: 0,
'operator-linebreak': 0,
'nonblock-statement-body-position': 0,
curly: 0,
'implicit-arrow-linebreak': 0,
indent: 0,
'object-curly-newline': 0,
'semi-style': 0,
'function-paren-newline': 0,
'prefer-template': 0,
'newline-per-chained-call': 0,
'prefer-arrow-callback': 0,
'no-bitwise': 0,
'prefer-const': 0,
'no-extra-semi': 0,
},
ignorePatterns: ['test/data/output', 'lib/css2xpath/*'],
};
2 changes: 1 addition & 1 deletion .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

npm run lint && npm run dtslint
npm run prettier && npm run lint && npm run dtslint
147 changes: 84 additions & 63 deletions bin/codecept.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/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');
const program = require('commander')
const Codecept = require('../lib/codecept')
const { print, error } = require('../lib/output')
const { printError } = require('../lib/command/utils')

const commandFlags = {
ai: {
Expand All @@ -29,104 +29,120 @@ 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(...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);
error('NodeJS >= 12 is required to run.')
print()
print('Please upgrade your NodeJS engine')
print(`Current NodeJS version: ${process.version}`)
process.exit(1)
}

program.usage('<command> [options]');
program.version(Codecept.version());
program.usage('<command> [options]')
program.version(Codecept.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(require('../lib/command/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(require('../lib/command/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(require('../lib/command/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(require('../lib/command/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(require('../lib/command/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(require('../lib/command/gherkin/init')))

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(require('../lib/command/gherkin/steps')))

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(require('../lib/command/gherkin/snippets')))

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(require('../lib/command/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(require('../lib/command/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(require('../lib/command/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(require('../lib/command/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(require('../lib/command/generate').heal))

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

// codecept-only options
Expand Down Expand Up @@ -162,9 +178,10 @@ program.command('run [test]')
.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(require('../lib/command/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 @@ -180,9 +197,10 @@ program.command('run-workers <workers> [selectedRuns...]')
.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(require('../lib/command/run-workers')))

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 @@ -205,14 +223,16 @@ program.command('run-multiple [suites...]')
// mocha options
.option('--colors', 'force enabling of colors')

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

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(require('../lib/command/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 @@ -226,9 +246,10 @@ program.command('dry-run [test]')
.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(require('../lib/command/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 @@ -263,15 +284,15 @@ program.command('run-rerun [test]')
.option('--trace', 'trace function calls')
.option('--child <string>', 'option for child processes')

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

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)
}
38 changes: 19 additions & 19 deletions lib/assert/empty.js
Original file line number Diff line number Diff line change
@@ -1,43 +1,43 @@
const Assertion = require('../assert');
const AssertionFailedError = require('./error');
const { template } = require('../utils');
const output = require('../output');
const Assertion = require('../assert')
const AssertionFailedError = require('./error')
const { template } = require('../utils')
const output = require('../output')

class EmptinessAssertion extends Assertion {
constructor(params) {
super((value) => {
if (Array.isArray(value)) {
return value.length === 0;
return value.length === 0
}
return !value;
}, params);
this.params.type = 'to be empty';
return !value
}, params)
this.params.type = 'to be empty'
}

getException() {
if (Array.isArray(this.params.value)) {
this.params.value = `[${this.params.value.join(', ')}]`;
this.params.value = `[${this.params.value.join(', ')}]`
}

const err = new AssertionFailedError(this.params, "{{customMessage}}expected {{subject}} '{{value}}' {{type}}");
const err = new AssertionFailedError(this.params, "{{customMessage}}expected {{subject}} '{{value}}' {{type}}")

err.cliMessage = () => {
const msg = err.template
.replace('{{value}}', output.colors.bold('{{value}}'))
.replace('{{subject}}', output.colors.bold('{{subject}}'));
return template(msg, this.params);
};
return err;
.replace('{{subject}}', output.colors.bold('{{subject}}'))
return template(msg, this.params)
}
return err
}

addAssertParams() {
this.params.value = this.params.actual = arguments[0];
this.params.expected = [];
this.params.customMessage = arguments[1] ? `${arguments[1]}\n\n` : '';
this.params.value = this.params.actual = arguments[0]
this.params.expected = []
this.params.customMessage = arguments[1] ? `${arguments[1]}\n\n` : ''
}
}

module.exports = {
Assertion: EmptinessAssertion,
empty: subject => new EmptinessAssertion({ subject }),
};
empty: (subject) => new EmptinessAssertion({ subject }),
}
Loading