badeball / cypress-cucumber-preprocessor

Run cucumber/gherkin-syntaxed specs with Cypress
MIT License
1.32k stars 147 forks source link

[filepath] not including subfolders in resolution #1195

Closed Aryndel closed 3 months ago

Aryndel commented 4 months ago

Current behavior

If I configure custom stepDefinitions, the [filepath] expression is resolving only to the cypress/e2e CAP folder and ignoring any subfolders that the feature file appears in

For example, I have a feature file located at cypress\e2e\smoke\duckduckgo.feature, and a steps file located at cypress\e2e\smoke\duckduckgo.ts

Using the following settings in my package.json (this is the "default" specified in step-definitions.md):

"stepDefinitions": [
  "cypress/e2e/[filepath]/**/*.{js,ts}",
  "cypress/e2e/[filepath].{js,ts}",
  "cypress/support/step_definitions/**/*.{js,ts}"
]

I receive a step resolution error, which seems to be indicating it is resolving [filepath] to cypress\e2e\duckduckgo.{js,ts}, not including the smoke subfolder. Below is the full debug log:

DevTools listening on ws://127.0.0.1:64476/devtools/browser/fc311076-d939-4375-9a84-bf149475a13c
Missing baseUrl in compilerOptions. tsconfig-paths will be skipped

====================================================================================================

  (Run Starting)

  ┌────────────────────────────────────────────────────────────────────────────────────────────────┐
  │ Cypress:        13.11.0                                                                     
   │
  │ Browser:        Electron 118 (headless)                                                     
   │
  │ Node Version:   v18.18.2 (C:\Program Files\nodejs\node.exe)                                 
   │
  │ Specs:          1 found (duckduckgo.feature)                                                
   │
  │ Searched:       **/*.feature                                                                
   │
  └────────────────────────────────────────────────────────────────────────────────────────────────┘

────────────────────────────────────────────────────────────────────────────────────────────────────

  Running:  duckduckgo.feature                                                              (1 of 1)

  duckduckgo.com
    1) visiting the frontpage

  0 passing (252ms)
  1 failing

  1) duckduckgo.com
       visiting the frontpage:
     Error:
Step implementation missing for "I visit duckduckgo.com".

We tried searching for files containing step definitions using the following search pattern templates:

  - cypress/e2e/[filepath]/**/*.{js,ts}
  - cypress/e2e/[filepath].{js,ts}
  - cypress/support/step_definitions/**/*.{js,ts}

These templates resolved to the following search patterns:

  - cypress\e2e\duckduckgo\**\*.{js,ts}
  - cypress\e2e\duckduckgo.{js,ts}
  - cypress\support\step_definitions\**\*.{js,ts}

These patterns matched **no files** containing step definitions. This almost certainly means that you have misconfigured `stepDefinitions`.

You can implement it using the suggestion(s) below.

  When("I visit duckduckgo.com", function () {
    return "pending";
  });

      at Context.eval (https://duckduckgo.com/__cypress/tests?p=cypress\e2e\smoke\duckduckgo.feature:14699:29)

  (Results)

  ┌────────────────────────────────────────────────────────────────────────────────────────────────┐
  │ Tests:        1                                                                             
   │
  │ Passing:      0                                                                             
   │
  │ Failing:      1                                                                             
   │
  │ Pending:      0                                                                             
   │
  │ Skipped:      0                                                                             
   │
  │ Screenshots:  1                                                                             
   │
  │ Video:        false                                                                         
   │
  │ Duration:     0 seconds                                                                     
   │
  │ Spec Ran:     duckduckgo.feature                                                            
   │
  └────────────────────────────────────────────────────────────────────────────────────────────────┘

  (Screenshots)

  -  C:\Projects\TestAutomation\cypress\screenshots\duckduckgo.feature\duckduckgo.com     (1280x720)
      -- visiting the frontpage (failed).png                                                    

====================================================================================================

  (Run Finished)

───┐
  │ ×  duckduckgo.feature                       254ms        1        -        1        -        - │
  └────────────────────────────────────────────────────────────────────────────────────────────────┘
    ×  1 of 1 failed (100%)                     254ms        1        -        1        -        -

This issue does NOT occur if I do not specify custom step definition patterns and leave it at the default (again, even though I started with just configuring the "default" step definition patterns in my package.json). It also does NOT occur if I place the files directly in the e2e folder and not in a subfolder

Desired behavior

[filepath] SHOULD resolve to cypress\e2e\smoke\duckduckgo.{js,ts} for this feature file, including its subfolder

Test code to reproduce

https://github.com/Aryndel/cypress-cucumber-test/tree/main

This is nearly identical to the esbuild-ts example, just with custom stepDefinitions and with the duckduckgo files in a subfolder

Versions

Checklist

badeball commented 3 months ago

Change cypress/e2e to cypress/e2e/smoke in package.json.

[filepath] SHOULD resolve to cypress\e2e\smoke\duckduckgo.{js,ts} for this feature file, including its subfolder

No. You should read the documentation regarding pairing carefully, especially the part about common ancestor path. If you start adding more features outside of the smoke directory, then your original configuration will start working.

Aryndel commented 3 months ago

Thanks. I read that documentation multiple times but that part went over my head. As a temporary solution until more tests are added I just added a dummy feature file in a separate folder.