“ vue-cli-service test:unit”成功运行;但是npm退出错误代码1 ELIFECYCLE

问题描述 投票:1回答:1

我正在尝试运行npm run test:unit,真正的错误似乎是npm debug.log中的test:unit: Failed to exec test:unit script。但是脚本确实可以运行和执行而没有问题。

我对NPM + Node还是有点陌生​​,所以我正在为这种行为而苦苦挣扎。当我运行npm run test:unit(在Package.json中为"test:unit": "vue-cli-service test:unit")时,我得到以下输出:

Test Suites: 1 passed, 1 total
Tests:       1 passed, 1 total
Snapshots:   1 file obsolete, 0 total
Time:        1.208s
Ran all test suites.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] test:unit: `vue-cli-service test:unit`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the [email protected] test:unit script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/max/.npm/_logs/2020-03-26T18_16_36_155Z-debug.log

预期结果测试应该通过,我不应该看到NPM / Node崩溃。

正在运行./node_modules/.bin/vue-cli-service test:unit,我只得到测试和Jest输出。一切正常。那么我的设置出了什么问题?

尝试的分辨率

  • 重新安装的node_modules
  • 更新后的npm
  • 更新为node:stable
  • 重新安装nvm(节点版本管理器)并更新
  • 试图向vue-cli-service添加额外的调试标志
npm_debug.log
0 info it worked if it ends with ok
1 verbose cli [
1 verbose cli   '/home/max/.nvm/versions/node/v13.11.0/bin/node',
1 verbose cli   '/home/max/.nvm/versions/node/v13.11.0/bin/npm',
1 verbose cli   'run',
1 verbose cli   'test:unit'
1 verbose cli ]
2 info using [email protected]
3 info using [email protected]
4 verbose run-script [ 'pretest:unit', 'test:unit', 'posttest:unit' ]
5 info lifecycle [email protected]~pretest:unit: [email protected]
6 info lifecycle [email protected]~test:unit: [email protected]
7 verbose lifecycle [email protected]~test:unit: unsafe-perm in lifecycle true
8 verbose lifecycle [email protected]~test:unit: PATH: /home/max/.nvm/versions/node/v13.11.0/lib/node_modules/npm/node_modules/npm-lifecycle/node-gyp-bin:/home/max/cheatsheet_project/cheatsheet/node_modules/.bin:/home/max/.pyenv/plugins/pyenv-virtualenv/shims:/home/max/.pyenv/shims:~/.pyenv/bin:/home/max/Maven/apache-maven-3.5.2/bin:/home/max/.nvm/versions/node/v13.11.0/bin:/home/max/.rbenv/shims:/home/max/.rbenv/bin:/home/max/workspace/go/bin:/home/max/.cargo/bin:/home/max/.cargo/bin:/home/max/bin:/home/max/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/usr/lib/jvm/java-9-oracle/bin:/usr/lib/jvm/java-9-oracle/db/bin:/usr/lib/jvm/java-9-oracle/bin:/usr/lib/jvm/java-9-oracle/db/bin:/usr/local/go/bin
9 verbose lifecycle [email protected]~test:unit: CWD: /home/max/cheatsheet_project/cheatsheet
10 silly lifecycle [email protected]~test:unit: Args: [ '-c', 'vue-cli-service test:unit' ]
11 silly lifecycle [email protected]~test:unit: Returned: code: 1  signal: null
12 info lifecycle [email protected]~test:unit: Failed to exec test:unit script
13 verbose stack Error: [email protected] test:unit: `vue-cli-service test:unit`
13 verbose stack Exit status 1
13 verbose stack     at EventEmitter.<anonymous> (/home/max/.nvm/versions/node/v13.11.0/lib/node_modules/npm/node_modules/npm-lifecycle/index.js:332:16)
13 verbose stack     at EventEmitter.emit (events.js:315:20)
13 verbose stack     at ChildProcess.<anonymous> (/home/max/.nvm/versions/node/v13.11.0/lib/node_modules/npm/node_modules/npm-lifecycle/lib/spawn.js:55:14)
13 verbose stack     at ChildProcess.emit (events.js:315:20)
13 verbose stack     at maybeClose (internal/child_process.js:1026:16)
13 verbose stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:286:5)
14 verbose pkgid [email protected]
15 verbose cwd /home/max/cheatsheet_project/cheatsheet
16 verbose Linux 4.15.0-91-generic
17 verbose argv "/home/max/.nvm/versions/node/v13.11.0/bin/node" "/home/max/.nvm/versions/node/v13.11.0/bin/npm" "run" "test:unit"
18 verbose node v13.11.0
19 verbose npm  v6.14.4
20 error code ELIFECYCLE
21 error errno 1
22 error [email protected] test:unit: `vue-cli-service test:unit`
22 error Exit status 1
23 error Failed at the [email protected] test:unit script.
23 error This is probably not a problem with npm. There is likely additional logging output above.
24 verbose exit [ 1, true ]
vue.js npm jestjs vue-cli
1个回答
0
投票

./node_modules/.bin/vue-cli-service test:unit -u修复了这个问题。这是jest --updatesnapshot的简写命令。

由于我们刚刚将组件更新为指向其他地址,因此可以预期该组件的快照会发生变化。我们的快照测试用例失败了,因为我们更新的组件的快照不再与该测试用例的快照工件匹配。

要解决此问题,我们将需要更新快照工件。您可以使用标记来运行Jest,该标记将告诉它重新生成快照...-从Snapshot Testing

观察到有关快照的错误:

快照:1个文件已过时,总共0个

不确定为什么会导致NPM错误,但-u已清除它,而我没有再看到它。

© www.soinside.com 2019 - 2024. All rights reserved.