Mac 上带有 Jenkins 的 Testcafe:node_modules/.bin/testcafe:没有这样的文件或目录

Testcafe with Jenkins on Mac: node_modules/.bin/testcafe: No such file or directory

我正尝试在 Mac 上通过 Jenkins 运行 一个 testcafe 脚本。我按照 https://devexpress.github.io/testcafe/documentation/guides/continuous-integration/jenkins.html.

中的步骤操作

Shell 使用的命令:node_modules/.bin/testcafe chrome tests/**/* -r xunit:res.xml

错误日志:

Cloning the remote Git repository
Cloning repository https://github.com/xxxxx/testcafe-ci-demo.git
 > git init /Users/xxxxx/.jenkins/workspace/tcafe-sample # timeout=10
Fetching upstream changes from https://github.com/xxxxx/testcafe-ci-demo.git
 > git --version # timeout=10
 > git fetch --tags --force --progress -- https://github.com/xxxxx/testcafe-ci-demo.git +refs/heads/*:refs/remotes/origin/* # timeout=10
 > git config remote.origin.url https://github.com/xxxxx/testcafe-ci-demo.git # timeout=10
 > git config --add remote.origin.fetch +refs/heads/*:refs/remotes/origin/* # timeout=10
 > git config remote.origin.url https://github.com/xxxxx/testcafe-ci-demo.git # timeout=10
Fetching upstream changes from https://github.com/xxxxx/testcafe-ci-demo.git
 > git fetch --tags --force --progress -- https://github.com/xxxxx/testcafe-ci-demo.git +refs/heads/*:refs/remotes/origin/* # timeout=10
 > git rev-parse refs/remotes/origin/master^{commit} # timeout=10
 > git rev-parse refs/remotes/origin/origin/master^{commit} # timeout=10
Checking out Revision 7ddcab81ab41bf4f5bc6ed9f8418029534db60e4 (refs/remotes/origin/master)
 > git config core.sparsecheckout # timeout=10
 > git checkout -f 7ddcab81ab41bf4f5bc6ed9f8418029534db60e4 # timeout=10
Commit message: "Add a readme and license"
First time build. Skipping changelog.
[tcafe-sample] $ /bin/sh -xe /var/folders/xc/tb86yjr146zfbtqkxr2t95q00000gn/T/jenkins5861951405271132891.sh
+ npm install testcafe testcafe-reporter-xunit
npm WARN deprecated core-js@1.2.7: core-js@<3 is no longer maintained and not recommended for usage due to the number of issues. Please, upgrade your dependencies to the actual version of core-js@3.
npm WARN saveError ENOENT: no such file or directory, open '/Users/xxxxx/package.json'
npm WARN enoent ENOENT: no such file or directory, open '/Users/xxxxx/package.json'
npm WARN xxxxx No description
npm WARN xxxxx No repository field.
npm WARN xxxxx No README data
npm WARN xxxxx No license field.

+ testcafe-reporter-xunit@2.1.0
+ testcafe@1.8.6
updated 2 packages and audited 1377 packages in 17.358s
5 packages are looking for funding
  run `npm fund` for details

found 73 vulnerabilities (41 low, 10 moderate, 22 high)
  run `npm audit fix` to fix them, or `npm audit` for details
[tcafe-sample] $ /bin/sh -xe /var/folders/xc/tb86yjr146zfbtqkxr2t95q00000gn/T/jenkins4273197940408317220.sh
+ node_modules/.bin/testcafe chrome 'tests/**/*' -r xunit:res.xml
/var/folders/xc/tb86yjr146zfbtqkxr2t95q00000gn/T/jenkins4273197940408317220.sh: line 2: node_modules/.bin/testcafe: No such file or directory
Build step 'Execute shell' marked build as failure
Recording test results
ERROR: Step ‘Publish JUnit test result report’ failed: No test report files were found. Configuration error?
Finished: FAILURE

我也在本地(Jenkins 之外)安装了一个 Testcafe Mac。这会是个问题吗?

日志中的以下行表明您的主目录中有 node_modules 目录,并且 npm install 将其用作软件包安装目录:

npm WARN saveError ENOENT: no such file or directory, open '/Users/xxxxx/package.json'
npm WARN enoent ENOENT: no such file or directory, open '/Users/xxxxx/package.json'

npm install 命令不会在 Jenkins 工作区目录 (/Users/xxxxx/.jenkins/workspace/tcafe-sample) 中安装包,并且您将无法使用本地安装的 TestCafe,而 node_modules 存在于某些目录中其父目录。

您可以删除 /Users/xxxxx/node_modules 目录以避免此问题。