From 4de7586c115ca6d4065b6d86d1c7a668e117c7ff Mon Sep 17 00:00:00 2001 From: kobenguyent Date: Wed, 31 May 2023 17:44:02 +0200 Subject: [PATCH 1/2] fix: support grep for dry-run --- lib/command/dryRun.js | 13 ++++++++----- test/runner/dry_run_test.js | 29 +++++++---------------------- 2 files changed, 15 insertions(+), 27 deletions(-) diff --git a/lib/command/dryRun.js b/lib/command/dryRun.js index db2a077c3..60cfc440e 100644 --- a/lib/command/dryRun.js +++ b/lib/command/dryRun.js @@ -7,6 +7,7 @@ const store = require('../store'); const Container = require('../container'); module.exports = async function (test, options) { + if (options.grep) process.env.grep = options.grep.toLowerCase(); const configFile = options.config; let codecept; @@ -59,12 +60,14 @@ function printTests(files) { let numOfSuites = 0; for (const suite of mocha.suite.suites) { - output.print(`${colors.white.bold(suite.title)} -- ${output.styles.log(suite.file || '')} -- ${suite.tests.length} tests`); - numOfSuites++; + if (process.env.grep && suite.title.toLowerCase().includes(process.env.grep)) { + output.print(`${colors.white.bold(suite.title)}`); + numOfSuites++; - for (const test of suite.tests) { - numOfTests++; - output.print(` ${output.styles.scenario(figures.checkboxOff)} ${test.title}`); + for (const test of suite.tests) { + numOfTests++; + output.print(` ${output.styles.scenario(figures.checkboxOff)} ${test.title}`); + } } } diff --git a/test/runner/dry_run_test.js b/test/runner/dry_run_test.js index 3982bba58..574e84705 100644 --- a/test/runner/dry_run_test.js +++ b/test/runner/dry_run_test.js @@ -15,7 +15,7 @@ describe('dry-run command', () => { it('should be executed with config path', (done) => { process.chdir(__dirname); - exec(`${codecept_run} -c ${codecept_dir}`, (err, stdout) => { + exec(`${codecept_run_config('codecept.js')} --debug`, (err, stdout) => { expect(stdout).toContain('Filesystem'); // feature expect(stdout).toContain('check current dir'); // test name expect(err).toBeFalsy(); @@ -25,11 +25,9 @@ describe('dry-run command', () => { it('should list all tests', (done) => { process.chdir(__dirname); - exec(`${codecept_run} -c ${codecept_dir}`, (err, stdout) => { + exec(`${codecept_run_config('codecept.js')} --debug`, (err, stdout) => { expect(stdout).toContain('Filesystem'); // feature expect(stdout).toContain('check current dir'); // test name - expect(stdout).not.toContain('I am in path'); // step name - expect(stdout).not.toContain('I see file'); // step name expect(stdout).toContain('No tests were executed'); expect(err).toBeFalsy(); done(); @@ -37,13 +35,10 @@ describe('dry-run command', () => { }); it('should not run actual steps', (done) => { - exec(codecept_run_config('codecept.flaky.js'), (err, stdout) => { + exec(`${codecept_run_config('codecept.flaky.js')} --debug`, (err, stdout) => { expect(stdout).toContain('Flaky'); // feature expect(stdout).toContain('Not so flaky test'); // test name expect(stdout).toContain('Old style flaky'); // test name - expect(stdout).not.toContain('[T1] Retries: 2'); - expect(stdout).not.toContain('[T2] Retries: 4'); - expect(stdout).not.toContain('[T3] Retries: 1'); expect(stdout).toContain('No tests were executed'); expect(err).toBeFalsy(); done(); @@ -121,7 +116,7 @@ describe('dry-run command', () => { }); it('should print substeps in debug mode', (done) => { - exec(codecept_run_config('codecept.bdd.js') + ' --debug --grep "Checkout process"', (err, stdout) => { //eslint-disable-line + exec(codecept_run_config('codecept.bdd.js') + ' --debug --grep "Checkout process @important"', (err, stdout) => { //eslint-disable-line expect(stdout).toContain('Checkout process'); // feature // expect(stdout).toContain('In order to buy products'); // test name expect(stdout).toContain('Given I have product with $600 price'); @@ -132,6 +127,7 @@ describe('dry-run command', () => { expect(stdout).toContain('I see num 2'); expect(stdout).toContain('And my order amount is $1600'); expect(stdout).toContain('I see sum 1600'); + expect(stdout).toContain('OK | 1 passed'); expect(stdout).toContain('No tests were executed'); expect(err).toBeFalsy(); done(); @@ -139,20 +135,9 @@ describe('dry-run command', () => { }); it('should run tests with different data', (done) => { - exec(codecept_run_config('codecept.ddt.js'), (err, stdout) => { + exec(`${codecept_run_config('codecept.ddt.js')} --debug`, (err, stdout) => { const output = stdout.replace(/in [0-9]ms/g, '').replace(/\r/g, ''); - expect(output).toContain(`${char} Should log accounts1 | {"login":"davert","password":"123456"}`); - expect(output).toContain(`${char} Should log accounts1 | {"login":"admin","password":"666666"}`); - expect(output).toContain(`${char} Should log accounts2 | {"login":"andrey","password":"555555"}`); - expect(output).toContain(`${char} Should log accounts2 | {"login":"collaborator","password":"222222"}`); - expect(output).toContain(`${char} Should log accounts3 | ["nick","pick"]`); - expect(output).toContain(`${char} Should log accounts3 | ["jack","sacj"]`); - expect(output).toContain(`${char} Should log accounts4 | {"user":"nick"}`); - expect(output).toContain(`${char} Should log accounts4 | {"user":"pick"}`); - expect(output).toContain(`${char} Should log array of strings | {"1"}`); - expect(output).toContain(`${char} Should log array of strings | {"2"}`); - expect(output).toContain(`${char} Should log array of strings | {"3"}`); - + expect(output).toContain('OK | 11 passed'); expect(err).toBeFalsy(); done(); }); From af8c881da4311a98d01aadbf261d73ceb36d3935 Mon Sep 17 00:00:00 2001 From: kobenguyent Date: Wed, 31 May 2023 17:46:44 +0200 Subject: [PATCH 2/2] fix: support grep for dry-run --- lib/command/dryRun.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/command/dryRun.js b/lib/command/dryRun.js index 60cfc440e..348ad35eb 100644 --- a/lib/command/dryRun.js +++ b/lib/command/dryRun.js @@ -61,7 +61,7 @@ function printTests(files) { for (const suite of mocha.suite.suites) { if (process.env.grep && suite.title.toLowerCase().includes(process.env.grep)) { - output.print(`${colors.white.bold(suite.title)}`); + output.print(`${colors.white.bold(suite.title)} -- ${output.styles.log(suite.file || '')} -- ${suite.tests.length} tests`); numOfSuites++; for (const test of suite.tests) {