mapado / prettier-plugin-gherkin

This prettier plugin format your gherkin (`.feature` files) documents.
MIT License
18 stars 5 forks source link

Wrong formatting of multiple background steps #25

Closed phoefflin closed 3 months ago

phoefflin commented 4 months ago

According to https://cucumber.io/docs/gherkin/reference/#background the Background can contain more than one Steps combined with the 'And' keyword. The plugin currently (that is v2.4.0) does not seem to handle 'And' correctly and instead reformats steps to only one line.

Example input:

Feature: Example with multiple Background Steps

    Background:
        Given the user is on the homepage
        And the user has the language "en" selected in the user settings

    Scenario: example Scenario
     ...

Output:

Feature: Example with multiple Background steps

    Background:
        Given the user is on the homepageAnd the user has the language "en" selected in the user settings

    Scenario: example Scenario
     ...
bdo commented 4 months ago

It got broken by this commit: 61c733e8b576fe8353774ad6c87e23b5696dfb08

To find out, I used git bisect (with updated tests to include an additional line in the complex_background.feature).

Diff including the extra tests I used:

diff --git a/tests/good/__snapshots__/jsfmt.spec.mjs.snap b/tests/good/__snapshots__/jsfmt.spec.mjs.snap
index b88a206..55d55c8 100644
--- a/tests/good/__snapshots__/jsfmt.spec.mjs.snap
+++ b/tests/good/__snapshots__/jsfmt.spec.mjs.snap
@@ -57,6 +57,7 @@ Feature: Complex background

   Background: a simple background
     Given the minimalism inside a background
+    And another line inside a background

   Scenario: minimalistic
     Given the minimalism
@@ -85,6 +86,7 @@ Feature: Complex background

     Background: a simple background
         Given the minimalism inside a background
+        And another line inside a background

     Scenario: minimalistic
         Given the minimalism
@@ -115,6 +117,7 @@ Feature: Complex background

     Background: a simple background
         Given the minimalism inside a background
+        And another line inside a background

     Scenario: minimalistic
         Given the minimalism
diff --git a/tests/good/complex_background.feature b/tests/good/complex_background.feature
index fde7c94..71ba741 100644
--- a/tests/good/complex_background.feature
+++ b/tests/good/complex_background.feature
@@ -3,6 +3,7 @@ Feature: Complex background

   Background: a simple background
     Given the minimalism inside a background
+    And another line inside a background

   Scenario: minimalistic
     Given the minimalism
jdeniau commented 3 months ago

Sorry guys, I only saw that issue today !

Thanks @bdo for the deep dive.

The fix has been released in 2.4.1

bdo commented 3 months ago

Thank you Julien for producing the fix. We can now upgrade to the last version! 👏🥳