如何在脚本部分的 package.json 中使用 @ (at) 符号(我的案例:运行 cucumber-js 用于标记功能)

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

我们在 package.json 文件的脚本部分指定了不同的脚本。 我想通过脚本 运行 cucumber-js 并指定标签只执行一组特定的测试。

这个命令运行在命令行中没问题:npx cucumber-js --tags "@taggedTest" 但是,在脚本部分,我收到一个错误。 脚本部分如下所示:

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

所以引号我转义了,@(at)符号我转义不了。 这就是我收到此错误的原因:

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

有什么方法可以转义脚本部分中的 @ (at) 符号以实际使用它吗?它在其他部分(如依赖项部分)中无需转义就可以正常工作,但我不知道在脚本部分该做什么并且在官方文档中没有找到任何内容?

期待您的反馈。

我什至不知道你为什么要用引号来提及标签。您可以简单地使用它而不用引号。我尝试使用 repo here 并且只需附加 --tags @test

就可以使用

您不需要引用标签表达式,除非它包含空格(例如更高级的 @foo or @bar)。

另请参阅:https://cucumber.io/docs/cucumber/api/#tag-expressions