How to use @ (at) symbol in package.json in the scripts section (my case: run cucumber-js for tagged features)

Viewed 457

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.

2 Answers

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

Related