TheBrainFamily / cypress-cucumber-example

Example of using Cypress with Cucumber
MIT License
195 stars 120 forks source link

Running cypress-tag command as a script behaves different #15

Closed antonio-zenoo closed 4 years ago

antonio-zenoo commented 4 years ago

Hi, So, I cloned the repo, executed it successfully and tried the commands as mentioned

C:\Development\cypress-cucumber-example-master> ./node_modules/.bin/cypress-tags run -e TAGS='@feature-tag'

This gives me the expected result.

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

  (Run Finished)

       Spec                                              Tests  Passing  Failing  Pending  Skipped  
  ┌────────────────────────────────────────────────────────────────────────────────────────────────┐
  │ √  socialNetworks\Facebook.feature          00:04        2        2        -        -        - │
  ├────────────────────────────────────────────────────────────────────────────────────────────────┤
  │ √  socialNetworks\Twitter.feature           00:05        2        2        -        -        - │
  └────────────────────────────────────────────────────────────────────────────────────────────────┘
    √  All specs passed!                        00:10        4        4        -        -        -  

Now, if I add a script into the package.json such as

"scripts": {
  "test": "cypress run --spec \"**/*.feature\"",
  "test:all": "cypress run --spec \"**/*.features\"",
  "test:tag": "./node_modules/.bin/cypress-tags run -e TAGS='@feature-tag'"
}

and then execute this script, it looks into all the feature files, but doesn't execute any scenario.

PS C:\Development\cypress-cucumber-example-master> npm run test:tag

> cypress-cucumber-example@1.0.0 test:tag C:\Development\cypress-cucumber-example-master
> cypress-tags run -e TAGS='@feature-tag'

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

  (Run Starting)

{...}

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

  (Run Finished)

       Spec                                              Tests  Passing  Failing  Pending  Skipped  
  ┌────────────────────────────────────────────────────────────────────────────────────────────────┐
  │ √  All.features                               3ms        -        -        -        -        - │
  ├────────────────────────────────────────────────────────────────────────────────────────────────┤
  │ √  news\Google.feature                        3ms        -        -        -        -        - │
  ├────────────────────────────────────────────────────────────────────────────────────────────────┤
  │ √  socialNetworks\Facebook.feature            1ms        -        -        -        -        - │
  ├────────────────────────────────────────────────────────────────────────────────────────────────┤
  │ √  socialNetworks\Twitter.feature             1ms        -        -        -        -        - │
  └────────────────────────────────────────────────────────────────────────────────────────────────┘
    √  All specs passed!                          8ms        -        -        -        -        -  

So I wonder if that's the reason there was no a script as part of this repo in the first place, but I don't really understand this different behavior.

I'm pretty new to cypress and nodejs, so my apologies if this is a basic question, but I haven't been able to find an answer so far. If there's any help, I'm on Windows 10.

pravynandas commented 4 years ago

Interesting. First thing I would do is to change the script slightly by removing ./node_modules/.bin/ since all the script already part of node_modules/.bin and npm commands starts in that folder by default.

"scripts": { "test": "cypress run --spec \"/*.feature\"", "test:all": "cypress run --spec \"*/.features\"", "test:tag": "cypress-tags** run -e TAGS='@feature-tag'" }

Otherwise there is nothing suspicious (for a fairly newbie like me)

antonio-zenoo commented 4 years ago

@pravynandas well, yes, having ./node_modules/.bin/ in the script or not, doesn't make a difference, and it's not the expected behavior. And that's the thing, how come if it is different when it's executed directly in command line, that's my question.

pravynandas commented 4 years ago

Quick suggestion @antonio-zenoo, can you try changing the single quote around @tag to escaped double quotes, just like the --spec file. ? Something like below...

"test:tag": "./node_modules/.bin/cypress-tags run -e TAGS=\"@feature-tag\""

antonio-zenoo commented 4 years ago

Thanks!! That worked. Still don't know the reason behind it, but it did the trick.

pravynandas commented 4 years ago

Great to hear it worked !!

diwakarjais commented 2 years ago

Can anyone also help me on how to run cypress-tags run -e TAGS='@feature-tag' in parallel on gitlab pipeline.. I tried using

"e2e:test": "cypress-tags run -e -- TAGS='@feature-tag'",
 "test:e2e": "run-p --race \"e2e:test -- {@}\" --" 

but it didn't work although it is working when i use it with cypress run instead of cypress-tag run,

"e2e:test": "cypress run",
 "test:e2e": "run-p --race \"e2e:test -- {@}\" --" 

Here this work but i can not use tags with cypress run. It will be really grateful if you can help me with any solution.