[英]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 clean
和make install
。 兩者通常都不會創建名為clean
或install
的文件。 有人可能會爭辯說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.