--test-name-pattern needing to come before filenames is hostile to npm scripts
还没有人认领这个 Issue。
- 主要语言
- JavaScript
- 星标
- 122k
- 派生
- 37.3k
- 平均合并
- 4 天 2 小时
- 30 天内合并 PR
- 283
描述
What is the problem this feature will solve?
It is common practice to set up npm scripts for testing. E.g.
{
"test": "node --test tests/*.js more-tests/*.js"
}
However, this cannot be combined with --test-name-pattern. Attempting to do so, e.g.
npm test -- --test-name-pattern="my pattern"
will not work, because this gets translated to
node --test tests/*.js more-tests/*.js --test-name-pattern="my pattern"
which, I believe, ends up passing --test-name-pattern="my pattern" as an argument to these test files, instead of passing it as an argument to the test runner. The correct invocation is
node --test-name-pattern="my pattern" --test tests/*.js more-tests/*.js
but this is impossible to do via npm scripts, it seems. (See alternatives considered.)
What is the feature you are proposing to solve the problem?
I don't know what a good solution to this would be. Some possible ideas:
-
Special-case command line processing such that when
--testis present,nodegrabs the--test-name-patternargument for itself instead of passing it to scripts? -
Introduce a new binary, e.g.
node_test, which processes command-line arguments in such a way? I believe this is how most test runners behave. -
Introduce a file-based customization of the test runner, including which tests to run, so that I don't have to pass the test filenames as arguments to the test runner in a way that causes this problem?
-
Improve npm scripts to support a better method of passing arguments in the middle of the script? (See below.)
What alternatives have you considered?
I investigated how to get npm scripts to substitute in arguments you pass to npm run into the script command, so that the translation becomes the correct one. This is a well-studied problem, and the following two Stack Overflow posts have the best answers, as far as I can tell:
None of them seem very satisfactory, unfortunately. In particular, if you want something that works cross-platform, you basically have to write a wrapper script.
As an alternative, I could continue using other test runners, which support npm scripts better.
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
首先,使用 --test-name-pattern 复现 npm test 调用,并将其与可正常工作的命令进行比较,后者将该选项放在 --test 和文件名之前。调查 Node 对 --test 和 --test-name-pattern 的命令行处理;完成此任务需要一种明确的方案来支持这一 npm-script 使用场景,可能还需要包含参数顺序的测试。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- javascript, node.js
- 领域
- cli, testing-qa
- Issue 类型
- 功能
- 难度
- 5/5
- 预计耗时
- 一周以上
- 活跃度
- 停滞
- 描述清晰度
- 需要澄清
- 新手友好度
- 25/100