简体   繁体   English

vs 代码扩展测试脚本不运行并失败并显示 npm ERR! 代码生命周期

[英]vs code extension test script does not run and fail with npm ERR! code ELIFECYCLE

following are the version details以下是版本详情

Version: 1.74.3 (user setup)
Commit: 97dec172d3256f8ca4bfb2143f3f76b503ca0534
Date: 2023-01-09T16:59:02.252Z
Electron: 19.1.8
Chromium: 102.0.5005.167
Node.js: 16.14.2
V8: 10.2.154.15-electron.0
OS: Windows_NT x64 10.0.22000
Sandboxed: No

creating an extension and write test cases for common method file and when run with debug panel from activity bar ( which use launch.json) then it run and give test result also but when run below in terminal为通用方法文件创建一个扩展并编写测试用例,当从活动栏(使用 launch.json)使用调试面板运行时,它会运行并给出测试结果,但是当在终端下面运行时

npm run test npm 运行测试

it failed with below output它失败了,低于 output

D:\Developer\color-extension>npm run test

> my-extension@0.0.1 pretest D:\Developer\color-extension
> npm run compile && npm run lint


> my-extension@0.0.1 compile D:\Developer\color-extension
> tsc -p ./


> my-extension@0.0.1 lint D:\Developer\color-extension
> eslint src --ext ts


> my-extension@0.0.1 test D:\Developer\color-extension
> node ./out/test/runTest.js

Failed to run tests
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! my-extension@0.0.1 test: `node ./out/test/runTest.js`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the my-extension@0.0.1 test script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

and here is additional log这是额外的日志

0 info it worked if it ends with ok
1 verbose cli [
1 verbose cli   'C:\\Program Files\\nodejs\\node.exe',
1 verbose cli   'C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js',
1 verbose cli   'run',
1 verbose cli   'test'
1 verbose cli ]
2 info using npm@6.14.15
3 info using node@v14.17.6
4 verbose run-script [ 'pretest', 'test', 'posttest' ]
5 info lifecycle my-extension@0.0.1~pretest: my-extension@0.0.1
6 verbose lifecycle my-extension@0.0.1~pretest: unsafe-perm in lifecycle true
7 verbose lifecycle my-extension@0.0.1~pretest: PATH: C:\Program Files\nodejs\node_modules\npm\node_modules\npm-lifecycle\node-gyp-bin;D:\Developer\color-collector\node_modules\.bin;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\WINDOWS\System32\OpenSSH\;C:\Program Files\nodejs\;C:\Program Files\Git\cmd;C:\Program Files (x86)\Git\bin;C:\Program Files (x86)\Git\cmd;C:\Program Files\dotnet\;C:\Program Files\PowerShell\7\;C:\Users\User\AppData\Local\Microsoft\WindowsApps;C:\Users\User\AppData\Roaming\npm;C:\Users\User\AppData\Local\Programs\Microsoft VS Code\bin;C:\Users\User\AppData\Local\GitHubDesktop\bin;C:\xampp\php;C:\Users\User\composer;C:\Users\User\AppData\Roaming\Composer\vendor\bin;C:\Program Files\Sublime Text\;;C:\Users\User\AppData\Local\Programs\oh-my-posh\bin
8 verbose lifecycle my-extension@0.0.1~pretest: CWD: D:\Developer\color-collector
9 silly lifecycle my-extension@0.0.1~pretest: Args: [ '/d /s /c', 'npm run compile && npm run lint' ]
10 silly lifecycle my-extension@0.0.1~pretest: Returned: code: 0  signal: null
11 info lifecycle my-extension@0.0.1~test: my-extension@0.0.1
12 verbose lifecycle my-extension@0.0.1~test: unsafe-perm in lifecycle true
13 verbose lifecycle my-extension@0.0.1~test: PATH: C:\Program Files\nodejs\node_modules\npm\node_modules\npm-lifecycle\node-gyp-bin;D:\Developer\color-collector\node_modules\.bin;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\WINDOWS\System32\OpenSSH\;C:\Program Files\nodejs\;C:\Program Files\Git\cmd;C:\Program Files (x86)\Git\bin;C:\Program Files (x86)\Git\cmd;C:\Program Files\dotnet\;C:\Program Files\PowerShell\7\;C:\Users\User\AppData\Local\Microsoft\WindowsApps;C:\Users\User\AppData\Roaming\npm;C:\Users\User\AppData\Local\Programs\Microsoft VS Code\bin;C:\Users\User\AppData\Local\GitHubDesktop\bin;C:\xampp\php;C:\Users\User\composer;C:\Users\User\AppData\Roaming\Composer\vendor\bin;C:\Program Files\Sublime Text\;;C:\Users\User\AppData\Local\Programs\oh-my-posh\bin
14 verbose lifecycle my-extension@0.0.1~test: CWD: D:\Developer\color-collector
15 silly lifecycle my-extension@0.0.1~test: Args: [ '/d /s /c', 'node ./out/test/runTest.js' ]
16 silly lifecycle my-extension@0.0.1~test: Returned: code: 1  signal: null
17 info lifecycle my-extension@0.0.1~test: Failed to exec test script
18 verbose stack Error: my-extension@0.0.1 test: `node ./out/test/runTest.js`
18 verbose stack Exit status 1
18 verbose stack     at EventEmitter.<anonymous> (C:\Program Files\nodejs\node_modules\npm\node_modules\npm-lifecycle\index.js:332:16)
18 verbose stack     at EventEmitter.emit (events.js:400:28)
18 verbose stack     at ChildProcess.<anonymous> (C:\Program Files\nodejs\node_modules\npm\node_modules\npm-lifecycle\lib\spawn.js:55:14)
18 verbose stack     at ChildProcess.emit (events.js:400:28)
18 verbose stack     at maybeClose (internal/child_process.js:1055:16)
18 verbose stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:288:5)
19 verbose pkgid my-extension@0.0.1
20 verbose cwd D:\Developer\color-collector
21 verbose Windows_NT 10.0.22000
22 verbose argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "run" "test"
23 verbose node v14.17.6
24 verbose npm  v6.14.15
25 error code ELIFECYCLE
26 error errno 1
27 error my-extension@0.0.1 test: `node ./out/test/runTest.js`
27 error Exit status 1
28 error Failed at the my-extension@0.0.1 test script.
28 error This is probably not a problem with npm. There is likely additional logging output above.
29 verbose exit [ 1, true ]

package.json package.json

"scripts": {
    "vscode:prepublish": "npm run compile",
    "compile": "tsc -p ./",
    "watch": "tsc -watch -p ./",
    "pretest": "npm run compile && npm run lint",
    "lint": "eslint src --ext ts",
    "test": "node ./out/test/runTest.js",
    "coverage": "c8 --check-coverage npm run test"
  },
  "devDependencies": {
    "@types/glob": "^8.0.0",
    "@types/mocha": "^10.0.1",
    "@types/node": "16.x",
    "@types/vscode": "^1.74.0",
    "@typescript-eslint/eslint-plugin": "^5.45.0",
    "@typescript-eslint/parser": "^5.45.0",
    "@vscode/test-electron": "^2.2.0",
    "c8": "^7.12.0",
    "eslint": "^8.28.0",
    "glob": "^8.0.3",
    "mocha": "^10.1.0",
    "typescript": "^4.9.3"
  }

what could be the issue here?这里可能是什么问题? As far as I see it run posttest script but there is no posttet script added in package.json, is that the reason because I have created this extension and the package.json generated by yo generator.据我所知,它运行 posttest 脚本,但在 package.json 中没有添加 posttet 脚本,这是因为我创建了这个扩展和由 yo 生成器生成的 package.json 的原因。

re run npm install and npm cache clean --force too but no benifit.重新运行npm installnpm cache clean --force too 但没有好处。

it was node version issue but not displaying in any error.这是节点版本问题,但没有显示任何错误。 when I delete the node_modules and do npm install again then it tell electron require v 16 and more so after updating the node version, able to execute the test command.当我删除 node_modules 并再次执行 npm 安装时,它告诉 electron 需要 v 16 等更新节点版本后,能够执行测试命令。

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

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