From e64ad36e6d479e6a82a5058a411727b4ee75d135 Mon Sep 17 00:00:00 2001 From: kobenguyent Date: Fri, 20 Oct 2023 15:02:53 +0200 Subject: [PATCH 1/2] fix: customLocator draws error in dry-mode --- lib/command/dryRun.js | 3 ++- test/data/sandbox/codecept.customLocator.js | 23 +++++++++++++++++++++ test/data/sandbox/test.customLocator.js | 6 ++++++ test/runner/dry_run_test.js | 11 ++++++++++ 4 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 test/data/sandbox/codecept.customLocator.js create mode 100644 test/data/sandbox/test.customLocator.js diff --git a/lib/command/dryRun.js b/lib/command/dryRun.js index e5add05c8..cb08cf317 100644 --- a/lib/command/dryRun.js +++ b/lib/command/dryRun.js @@ -20,7 +20,8 @@ module.exports = async function (test, options) { if (config.plugins) { // disable all plugins by default, they can be enabled with -p option for (const plugin in config.plugins) { - config.plugins[plugin].enabled = false; + // this to make sure the custom locator could be parsed when running under dry-mode + config.plugins[plugin].enabled = plugin === 'customLocator'; } } diff --git a/test/data/sandbox/codecept.customLocator.js b/test/data/sandbox/codecept.customLocator.js new file mode 100644 index 000000000..9cdd1b3f7 --- /dev/null +++ b/test/data/sandbox/codecept.customLocator.js @@ -0,0 +1,23 @@ +exports.config = { + tests: './*.customLocator.js', + timeout: 10000, + output: './output', + helpers: { + Playwright: { + url: 'http://localhost', + show: true, + browser: 'chromium', + }, + }, + include: {}, + bootstrap: false, + mocha: {}, + name: 'sandbox', + plugins: { + customLocator: { + enabled: false, + prefix: '$', + attribute: 'data-testid', + }, + }, +}; diff --git a/test/data/sandbox/test.customLocator.js b/test/data/sandbox/test.customLocator.js new file mode 100644 index 000000000..608ba57f0 --- /dev/null +++ b/test/data/sandbox/test.customLocator.js @@ -0,0 +1,6 @@ +const I = actor(); +Feature('Custom Locator'); + +Scenario('no error with dry-mode', () => { + I.seeElement(locate('$COURSE').find('a')); +}); diff --git a/test/runner/dry_run_test.js b/test/runner/dry_run_test.js index 0bac5d353..6de53a35e 100644 --- a/test/runner/dry_run_test.js +++ b/test/runner/dry_run_test.js @@ -174,4 +174,15 @@ describe('dry-run command', () => { done(); }); }); + + it('should enable customLocator plugin in dry-mode', (done) => { + exec(`${codecept_run_config('codecept.customLocator.js')} --verbose`, (err, stdout) => { + expect(stdout).toContain('Plugins: customLocator'); + expect(stdout).toContain('I see element {xpath: .//*[@data-testid=\'COURSE\']//a}'); + expect(stdout).toContain('OK | 1 passed'); + expect(stdout).toContain('--- DRY MODE: No tests were executed ---'); + expect(err).toBeFalsy(); + done(); + }); + }); }); From c12ce80b5bba68093f6a65b96440298411535336 Mon Sep 17 00:00:00 2001 From: kobenguyent Date: Fri, 20 Oct 2023 17:17:03 +0200 Subject: [PATCH 2/2] fix: handle dry-run command better --- docs/commands.md | 12 ++++++++++++ lib/command/dryRun.js | 4 ++-- test/runner/dry_run_test.js | 15 +++++++++++++-- 3 files changed, 27 insertions(+), 4 deletions(-) diff --git a/docs/commands.md b/docs/commands.md index 7d9de41b9..57bfd523e 100644 --- a/docs/commands.md +++ b/docs/commands.md @@ -152,6 +152,18 @@ If a plugin needs to be enabled in `dry-run` mode, pass its name in `-p` option: npx codeceptjs dry-run --steps -p allure ``` +If some plugins need to be enabled in `dry-run` mode, pass its name in `-p` option: + +``` +npx codeceptjs dry-run --steps -p allure,customLocator +``` + +If all plugins need to be enabled in `dry-run` mode, pass its name in `-p` option: + +``` +npx codeceptjs dry-run --steps -p all +``` + To enable bootstrap script in dry-run mode, pass in `--bootstrap` option when running with `--steps` or `--debug` ``` diff --git a/lib/command/dryRun.js b/lib/command/dryRun.js index cb08cf317..426d20e07 100644 --- a/lib/command/dryRun.js +++ b/lib/command/dryRun.js @@ -20,8 +20,8 @@ module.exports = async function (test, options) { if (config.plugins) { // disable all plugins by default, they can be enabled with -p option for (const plugin in config.plugins) { - // this to make sure the custom locator could be parsed when running under dry-mode - config.plugins[plugin].enabled = plugin === 'customLocator'; + // if `-p all` is passed, then enabling all plugins, otherwise plugins could be enabled by `-p customLocator,commentStep,tryTo` + config.plugins[plugin].enabled = options.plugins === 'all'; } } diff --git a/test/runner/dry_run_test.js b/test/runner/dry_run_test.js index 6de53a35e..1881f7706 100644 --- a/test/runner/dry_run_test.js +++ b/test/runner/dry_run_test.js @@ -175,8 +175,19 @@ describe('dry-run command', () => { }); }); - it('should enable customLocator plugin in dry-mode', (done) => { - exec(`${codecept_run_config('codecept.customLocator.js')} --verbose`, (err, stdout) => { + it('should enable all plugins in dry-mode when passing -p all', (done) => { + exec(`${codecept_run_config('codecept.customLocator.js')} --verbose -p all`, (err, stdout) => { + expect(stdout).toContain('Plugins: screenshotOnFail, customLocator'); + expect(stdout).toContain('I see element {xpath: .//*[@data-testid=\'COURSE\']//a}'); + expect(stdout).toContain('OK | 1 passed'); + expect(stdout).toContain('--- DRY MODE: No tests were executed ---'); + expect(err).toBeFalsy(); + done(); + }); + }); + + it('should enable a particular plugin in dry-mode when passing it to -p', (done) => { + exec(`${codecept_run_config('codecept.customLocator.js')} --verbose -p customLocator`, (err, stdout) => { expect(stdout).toContain('Plugins: customLocator'); expect(stdout).toContain('I see element {xpath: .//*[@data-testid=\'COURSE\']//a}'); expect(stdout).toContain('OK | 1 passed');