3

we specify different scripts in the scripts section of a package.json file. I would like to run cucumber-js via the scripts and specify tags to execute only a certain set of tests.

This command runs fine in the command line: npx cucumber-js --tags "@taggedTest" However, in the scripts section, I get an error. The scripts section looks like this:

...
 "scripts": {
    "e2e": "npx cucumber-js",
    "e2e_taggedTests": "npx cucumber-js --tags \"@taggedTests\"",
    "unitTests": "jest"
  }
...

So I escaped the quotation marks, but I cannot escape the @ (at) symbol. That is why I get this error:

Unexpected token @ in JSON at position 1097 while parsing near '...cumber-js --tags \"\@taggedTests\"

Is there any way how I can escape the @ (at) symbol in the scripts section to actually use it? It works fine without escaping in other sections like the dependencies section, but I have no idea what to do in the scripts section and have not found anything in the official docs?

Looking forward to your feedback.

CPR
  • 33
  • 2

2 Answers2

0

I don't even know why you are trying to use quotes to mention tags. You can simply use it without quotes. I tried with the repo here and it worked using by just appending --tags @test

Raju
  • 2,299
  • 2
  • 16
  • 19
  • 1
    I was adding the quotes because you can combine tags that way. However, that is not required right now, so I do it as you suggested and it works. Thanks. – CPR Feb 09 '21 at 10:46
0

You don't need to quote the tag expression unless it contains spaces (e.g. a more advanced one like @foo or @bar).

See also: https://cucumber.io/docs/cucumber/api/#tag-expressions

David Goss
  • 71
  • 3