From 4e677dac0bfe274c0a153ff28b3172796505e4dd Mon Sep 17 00:00:00 2001 From: Ameterezu Date: Fri, 20 Nov 2020 22:00:46 +0300 Subject: [PATCH 1/6] Add reporting support for run-workers Add reporting support for run-workers. Can be used to generate junit reports. Example command: npx codeceptjs run-workers 2 --reporter mocha-junit-reporter --- bin/codecept.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/bin/codecept.js b/bin/codecept.js index a6c63d5eb..b1e0a3737 100755 --- a/bin/codecept.js +++ b/bin/codecept.js @@ -131,6 +131,8 @@ program.command('run-workers ') .option('--tests', 'run only JS test files and skip features') .option('--profile [value]', 'configuration profile to be used') .option('-p, --plugins ', 'enable plugins, comma-separated') + .option('-O, --reporter-options ', 'reporter-specific options') + .option('-R, --reporter ', 'specify the reporter to use') .action(require('../lib/command/run-workers')); program.command('run-multiple [suites...]') From 7580528f00b44088ffd2c598915490ae928f2ebd Mon Sep 17 00:00:00 2001 From: Ameterezu Date: Mon, 23 Nov 2020 16:15:10 +0300 Subject: [PATCH 2/6] Fix method loop --- lib/plugin/commentStep.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/plugin/commentStep.js b/lib/plugin/commentStep.js index 6a9183f35..14ad5dc20 100644 --- a/lib/plugin/commentStep.js +++ b/lib/plugin/commentStep.js @@ -107,6 +107,9 @@ module.exports = function (config) { event.dispatcher.on(event.step.started, (step) => { if (currentCommentStep) { const metaStep = getRootMetaStep(step); + + if (metaStep === currentCommentStep) return; + metaStep.metaStep = currentCommentStep; } }); From adb46bee4319188b316d2bb2c36e001d7597035a Mon Sep 17 00:00:00 2001 From: Ameterezu Date: Tue, 24 Nov 2020 11:34:39 +0300 Subject: [PATCH 3/6] Change if --- lib/plugin/commentStep.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/plugin/commentStep.js b/lib/plugin/commentStep.js index 14ad5dc20..e1d3f54a0 100644 --- a/lib/plugin/commentStep.js +++ b/lib/plugin/commentStep.js @@ -108,9 +108,9 @@ module.exports = function (config) { if (currentCommentStep) { const metaStep = getRootMetaStep(step); - if (metaStep === currentCommentStep) return; - - metaStep.metaStep = currentCommentStep; + if (metaStep !== currentCommentStep) { + metaStep.metaStep = currentCommentStep; + } } }); From 34d8df80f72fd918a9b18a8cc1abbf43c6a0fbe9 Mon Sep 17 00:00:00 2001 From: Ameterezu Date: Wed, 20 Jan 2021 16:31:03 +0300 Subject: [PATCH 4/6] Add command to get list of tests --- bin/codecept.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/bin/codecept.js b/bin/codecept.js index b1e0a3737..481c7c1b0 100755 --- a/bin/codecept.js +++ b/bin/codecept.js @@ -180,6 +180,14 @@ program.command('dry-run [test]') .option('--debug', 'output additional information') .action(require('../lib/command/dryRun')); +program.command('list-of-tests') + .description('Prints a list of tests in json format') + .option('-g, --grep ', 'select only tests matching ') + .option('-f, --fgrep ', 'select only tests containing ') + .option('-i, --invert', 'invert --grep and --fgrep matches') + .option('--file', 'save information to output directory') + .action(require('../lib/command/listOfTests')); + program.on('command:*', (cmd) => { console.log(`\nUnknown command ${cmd}\n`); program.outputHelp(); From fca3dd351e7d705ce6244a72aa9014964d51e5c1 Mon Sep 17 00:00:00 2001 From: Ameterezu Date: Wed, 20 Jan 2021 16:32:51 +0300 Subject: [PATCH 5/6] Add command to get list of tests --- bin/codecept.js | 12 +++--- docs/commands.md | 14 +++++++ lib/command/listOfTests | 91 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 111 insertions(+), 6 deletions(-) create mode 100644 lib/command/listOfTests diff --git a/bin/codecept.js b/bin/codecept.js index 481c7c1b0..29f9dd40a 100755 --- a/bin/codecept.js +++ b/bin/codecept.js @@ -181,12 +181,12 @@ program.command('dry-run [test]') .action(require('../lib/command/dryRun')); program.command('list-of-tests') - .description('Prints a list of tests in json format') - .option('-g, --grep ', 'select only tests matching ') - .option('-f, --fgrep ', 'select only tests containing ') - .option('-i, --invert', 'invert --grep and --fgrep matches') - .option('--file', 'save information to output directory') - .action(require('../lib/command/listOfTests')); + .description('Prints a list of tests in json format') + .option('-g, --grep ', 'select only tests matching ') + .option('-f, --fgrep ', 'select only tests containing ') + .option('-i, --invert', 'invert --grep and --fgrep matches') + .option('--file', 'save information to output directory') + .action(require('../lib/command/listOfTests')); program.on('command:*', (cmd) => { console.log(`\nUnknown command ${cmd}\n`); diff --git a/docs/commands.md b/docs/commands.md index c1132dd36..3b54a6a3e 100644 --- a/docs/commands.md +++ b/docs/commands.md @@ -236,3 +236,17 @@ Prints debugging information concerning the local environment ```sh npx codeceptjs info ``` + +## List of tests + +Prints a list of tests in json format + +``` +npx codeceptjs list-of-tests +``` + +When passed `--file` option saves a list of tests to output directory. + +``` +npx codeceptjs list-of-tests --file +``` diff --git a/lib/command/listOfTests b/lib/command/listOfTests new file mode 100644 index 000000000..208c4d110 --- /dev/null +++ b/lib/command/listOfTests @@ -0,0 +1,91 @@ +const { getConfig, getTestRoot, createOutputDir } = require('./utils'); +const Codecept = require('../codecept'); +const output = require('../output'); +const Container = require('../container'); + +module.exports = async function (options) { + const config = getConfig(); + const testRoot = getTestRoot(); + const output = config.output || "."; + + try { + const codecept = new Codecept(config, options); + codecept.init(testRoot); + codecept.loadTests(); + + const listOfTests = getListOfTests(codecept.testFiles); + + if (!options.file) { + printTests(listOfTests); + } else { + saveTests(listOfTests, output); + } + + } catch (err) { + console.error(err); + process.exit(1); + } +}; + +function getListOfTests(files) { + const mocha = Container.mocha(); + mocha.files = files; + mocha.loadFiles(); + + const grep = mocha.options.grep || /.*/; + const invert = !!mocha.options.invert; + + let listOfTests = { + suites: [] + }; + + for (const suite of mocha.suite.suites) { + + let suiteNode = { + title: suite.title, + path: suite.file || '', + tests: [] + } + + for (const test of suite.tests) { + let match = grep.test(test.fullTitle()); + + if (invert) { + match = !match; + } + + if (match) { + let testNode = { + title: test.title, + fullTitle: test.fullTitle(), + skipped: !!test.isPending() + }; + + suiteNode.tests.push(testNode); + } + } + + if (suiteNode.tests.length) { + listOfTests.suites.push(suiteNode); + } + } + + return JSON.stringify(listOfTests, null, "\t"); +} + +function printTests(listOfTests) { + output.print(output.styles.debug(`Tests from ${global.codecept_dir}:`)); + output.print(); + + output.print(listOfTests); +} + +function saveTests(listOfTests, path) { + const fs = require('fs'); + + if (!fs.existsSync(path)) { + fs.mkdirSync(path); + } + + fs.writeFileSync(`${path.replace(/\:$/, '')}/list_of_tests.json`, listOfTests); +} From 81d778e99196c21dc41cd318767b28d20dc572ff Mon Sep 17 00:00:00 2001 From: Ameterezu Date: Wed, 20 Jan 2021 18:10:36 +0300 Subject: [PATCH 6/6] Add command to get list of tests --- lib/command/listOfTests | 91 -------------------------------------- lib/command/listOfTests.js | 89 +++++++++++++++++++++++++++++++++++++ 2 files changed, 89 insertions(+), 91 deletions(-) delete mode 100644 lib/command/listOfTests create mode 100644 lib/command/listOfTests.js diff --git a/lib/command/listOfTests b/lib/command/listOfTests deleted file mode 100644 index 208c4d110..000000000 --- a/lib/command/listOfTests +++ /dev/null @@ -1,91 +0,0 @@ -const { getConfig, getTestRoot, createOutputDir } = require('./utils'); -const Codecept = require('../codecept'); -const output = require('../output'); -const Container = require('../container'); - -module.exports = async function (options) { - const config = getConfig(); - const testRoot = getTestRoot(); - const output = config.output || "."; - - try { - const codecept = new Codecept(config, options); - codecept.init(testRoot); - codecept.loadTests(); - - const listOfTests = getListOfTests(codecept.testFiles); - - if (!options.file) { - printTests(listOfTests); - } else { - saveTests(listOfTests, output); - } - - } catch (err) { - console.error(err); - process.exit(1); - } -}; - -function getListOfTests(files) { - const mocha = Container.mocha(); - mocha.files = files; - mocha.loadFiles(); - - const grep = mocha.options.grep || /.*/; - const invert = !!mocha.options.invert; - - let listOfTests = { - suites: [] - }; - - for (const suite of mocha.suite.suites) { - - let suiteNode = { - title: suite.title, - path: suite.file || '', - tests: [] - } - - for (const test of suite.tests) { - let match = grep.test(test.fullTitle()); - - if (invert) { - match = !match; - } - - if (match) { - let testNode = { - title: test.title, - fullTitle: test.fullTitle(), - skipped: !!test.isPending() - }; - - suiteNode.tests.push(testNode); - } - } - - if (suiteNode.tests.length) { - listOfTests.suites.push(suiteNode); - } - } - - return JSON.stringify(listOfTests, null, "\t"); -} - -function printTests(listOfTests) { - output.print(output.styles.debug(`Tests from ${global.codecept_dir}:`)); - output.print(); - - output.print(listOfTests); -} - -function saveTests(listOfTests, path) { - const fs = require('fs'); - - if (!fs.existsSync(path)) { - fs.mkdirSync(path); - } - - fs.writeFileSync(`${path.replace(/\:$/, '')}/list_of_tests.json`, listOfTests); -} diff --git a/lib/command/listOfTests.js b/lib/command/listOfTests.js new file mode 100644 index 000000000..c233fc3e0 --- /dev/null +++ b/lib/command/listOfTests.js @@ -0,0 +1,89 @@ +const { getConfig, getTestRoot } = require('./utils'); +const Codecept = require('../codecept'); +const output = require('../output'); +const Container = require('../container'); + +module.exports = async function (options) { + const config = getConfig(); + const testRoot = getTestRoot(); + const output = config.output || '.'; + + try { + const codecept = new Codecept(config, options); + codecept.init(testRoot); + codecept.loadTests(); + + const listOfTests = getListOfTests(codecept.testFiles); + + if (!options.file) { + printTests(listOfTests); + } else { + saveTests(listOfTests, output); + } + } catch (err) { + console.error(err); + process.exit(1); + } +}; + +function getListOfTests(files) { + const mocha = Container.mocha(); + mocha.files = files; + mocha.loadFiles(); + + const grep = mocha.options.grep || /.*/; + const invert = !!mocha.options.invert; + + const listOfTests = { + suites: [], + }; + + for (const suite of mocha.suite.suites) { + const suiteNode = { + title: suite.title, + path: suite.file || '', + tests: [], + }; + + for (const test of suite.tests) { + let match = grep.test(test.fullTitle()); + + if (invert) { + match = !match; + } + + if (match) { + const testNode = { + title: test.title, + fullTitle: test.fullTitle(), + skipped: !!test.isPending(), + }; + + suiteNode.tests.push(testNode); + } + } + + if (suiteNode.tests.length) { + listOfTests.suites.push(suiteNode); + } + } + + return JSON.stringify(listOfTests, null, '\t'); +} + +function printTests(listOfTests) { + output.print(output.styles.debug(`Tests from ${global.codecept_dir}:`)); + output.print(); + + output.print(listOfTests); +} + +function saveTests(listOfTests, path) { + const fs = require('fs'); + + if (!fs.existsSync(path)) { + fs.mkdirSync(path, { recursive: true }); + } + + fs.writeFileSync(`${path.replace(/\$/, '')}/list_of_tests.json`, listOfTests); +}