From a00b51642cb5278c64bf8a70f41e3344af803d04 Mon Sep 17 00:00:00 2001 From: Phil Manser Date: Sat, 8 Nov 2025 10:27:34 -0500 Subject: [PATCH] adding support for the `But` keyword --- lib/step/base.js | 2 +- lib/step/meta.js | 2 +- .../configs/html-reporter-plugin/features/html-reporter.feature | 1 + test/runner/html-reporter-plugin_test.js | 2 +- test/unit/steps_test.js | 2 +- 5 files changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/step/base.js b/lib/step/base.js index 3be7442ef..eb2aaade0 100644 --- a/lib/step/base.js +++ b/lib/step/base.js @@ -225,7 +225,7 @@ class Step { processingStep = this while (processingStep.metaStep) { - if (processingStep.metaStep.actor?.match(/^(Given|When|Then|And)/)) { + if (processingStep.metaStep.actor?.match(/^(Given|When|Then|And|But)/)) { hasBDD = true break } else { diff --git a/lib/step/meta.js b/lib/step/meta.js index c4acd8e80..b04b5af6f 100644 --- a/lib/step/meta.js +++ b/lib/step/meta.js @@ -15,7 +15,7 @@ class MetaStep extends Step { /** @return {boolean} */ isBDD() { - if (this.actor && this.actor.match && this.actor.match(/^(Given|When|Then|And)/)) { + if (this.actor && this.actor.match && this.actor.match(/^(Given|When|Then|And|But)/)) { return true } return false diff --git a/test/data/sandbox/configs/html-reporter-plugin/features/html-reporter.feature b/test/data/sandbox/configs/html-reporter-plugin/features/html-reporter.feature index b275314b3..0af87028d 100644 --- a/test/data/sandbox/configs/html-reporter-plugin/features/html-reporter.feature +++ b/test/data/sandbox/configs/html-reporter-plugin/features/html-reporter.feature @@ -13,6 +13,7 @@ Feature: HTML Reporter BDD Test When I perform an action Then I should see the expected result And everything should work correctly + But I should see the expected result @regression @critical Scenario: Test with data table diff --git a/test/runner/html-reporter-plugin_test.js b/test/runner/html-reporter-plugin_test.js index 525540967..a8218c04c 100644 --- a/test/runner/html-reporter-plugin_test.js +++ b/test/runner/html-reporter-plugin_test.js @@ -181,7 +181,7 @@ describe('CodeceptJS html-reporter-plugin', function () { expect(reportContent).toContain('data-type=') // Should contain scenario steps with proper keywords - expect(reportContent).toMatch(/Given|When|Then|And/) + expect(reportContent).toMatch(/Given|When|Then|And|But/) done() }) diff --git a/test/unit/steps_test.js b/test/unit/steps_test.js index 67eb68544..d8e36db0b 100644 --- a/test/unit/steps_test.js +++ b/test/unit/steps_test.js @@ -92,7 +92,7 @@ describe('Steps', () => { }) describe('#isBDD', () => { - ;['Given', 'When', 'Then', 'And'].forEach(key => { + ;['Given', 'When', 'Then', 'And', 'But'].forEach(key => { it(`[${key}] #isBdd should return true if it BDD style`, () => { const metaStep = new MetaStep(key, 'I need to open Google') expect(metaStep.isBDD()).to.be.true