繁体   English   中英

Makefile 命令在子文件夹中运行反应测试套件

[英]Makefile command to run react test suite in child folder

我正在尝试创建一个 Makefile 来运行我的反应应用程序的测试套件。 从根文件夹中,react 应用程序位于frontend/

我可以创建什么命令来实现这一点? 我尝试了以下但没有运气:

test-frontend:
    cd ./frontend/
    npm test

test-frontend:
    npm test ./frontend/

test-frontend:
    cd ./frontend/
    npm run-script test

这是我得到的错误:

npm ERR! code ENOENT
npm ERR! syscall open
npm ERR! path /path/to/dir/package.json
npm ERR! errno -2
npm ERR! enoent ENOENT: no such file or directory, open '/path/to/dir/package.json'
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent

npm ERR! A complete log of this run can be found in:
npm ERR!     /$HOME/.npm/_logs/2019-10-24T02_23_23_195Z-debug.log
make: *** [test-frontend] Error 254

评论回答了我的问题。 答案是:

test-frontend:
    cd ./frontend/ && npm run-script test

或者,如果您想使用单独的行来提高可读性:

test-frontend:
    cd ./frontend/ && \
    npm run-script test

您正在尝试做 Makefile 不适合做的事情。 您已经被 Makefile 警告之一咬住了:每个命令行都在它自己的 shell 上运行。

经验法则是:规则的配方应该创建一个命名为规则目标的文件名。

这是一个规则(澄清条款):

target:
  recipe command lines
  should create file named target

这个经验法则有一些例外。 最值得注意的是make cleanmake install 两者通常都不会创建名为cleaninstall的文件。 有人可能会争辩说make test也可以是这一经验法则的一个例外。

您只是偶然发现了更改目录警告。 在编写 makefile 时,这是一个常见的警告。 手册中甚至提到: https://www.gnu.org/software/make/manual/html_node/Execution.html 但请记住,这只是 make 的许多警告之一。

如果这是您(ab)使用 makefile 运行命令的扩展,那么一切可能都很好。 但是,如果您想扩展功能并且开始从一个警告到另一个警告,那么是时候重新考虑您的方法了。 要么将配方提取到它自己的脚本中,要么在你的 makefile 周围编写一个包装脚本。 如果您正在考虑为您的 makefile 添加参数处理,请先阅读以下内容:将 arguments 传递给“make run”

具有讽刺意味的是,您还使用了 npm 的命令执行功能: npm run-script 这当然有它自己的一套警告。 我不知道,因为我没有用过 npm 那么多。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM