Skip to content

Commit

Permalink
fix: support grep for dry-run (#3673)
Browse files Browse the repository at this point in the history
* fix: support grep for dry-run

* fix: support grep for dry-run
  • Loading branch information
kobenguyent committed Jun 4, 2023
1 parent d8e1fb2 commit 208d427
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 27 deletions.
13 changes: 8 additions & 5 deletions lib/command/dryRun.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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)} -- ${output.styles.log(suite.file || '')} -- ${suite.tests.length} tests`);
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}`);
}
}
}

Expand Down
29 changes: 7 additions & 22 deletions test/runner/dry_run_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -25,25 +25,20 @@ 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();
});
});

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();
Expand Down Expand Up @@ -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');
Expand All @@ -132,27 +127,17 @@ 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();
});
});

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();
});
Expand Down

0 comments on commit 208d427

Please sign in to comment.