網絡問題導致vscode無法運行測試用例


  寫vs code插件的話,難免要寫一些測試用例。vs code提供了end to end測試,在運行npm run test時,會下載當前最新版本(如果你沒指定測試版本號的話)進行測試。但是由於網絡問題,這個下載成功率有點低,我試了一下午,失敗一下午。並且換了電信、移動網絡,都不行。

$ npm run test

> lua-tags@1.0.4 pretest E:\Documents\work\lua-tags
> npm run compile


> lua-tags@1.0.4 compile E:\Documents\work\lua-tags
> tsc -p ./


> lua-tags@1.0.4 test E:\Documents\work\lua-tags
> node ./out/test/runTest.js

Downloading VS Code 1.42.1 from https://update.code.visualstudio.com/1.42.1/win32-archive/stable
Downloaded VS Code 1.42.1 into .vscode-test/vscode-1.42.1
Test error: Error: spawn E:\Documents\work\lua-tags\.vscode-test\vscode-1.42.1\Code.exe ENOENT
Exit code:   -4058
Done

Failed to run tests
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! lua-tags@1.0.4 test: `node ./out/test/runTest.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the lua-tags@1.0.4 test 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!     C:\Users\Administrator\AppData\Roaming\npm-cache\_logs\2020-02-14T08_03_50_906Z-debug.log

  根據日志可以看到,進行測試時,會先下載vscode-1.42.1(當前的最新版本)到目錄.vscode-test/vscode-1.42.1中,沒有報錯。但在隨后運行vscode的時候,報了一個ENOENT。到工作目錄一下,會發現一個空的.vscode-test目錄,里面什么都沒有,顯然是下載失敗造成的。

  給測試代碼加上梯子,這個不太現實,瀏覽器則有現成的。於是把https://update.code.visualstudio.com/1.42.1/win32-archive/stable丟到瀏覽器,會下載一個VSCode-win32-ia32-1.42.1.zip。下載完成后,把這個壓縮包的東西都解壓到工作目錄的.vscode-test/vscode-1.42.1中即可。

  再次運行npm run test,vs code檢測到已有最新版本,會跳過下載,直接運行測試。

  另外,在進行測試時,經常會卡在node ./out/test/runTest.js很久,沒有任何日志,有時甚至測試失敗。

> node ./out/test/runTest.js

events.js:200
      throw er; // Unhandled 'error' event
      ^

Error: connect ETIMEDOUT 104.42.78.153:443
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1134:16)
Emitted 'error' event on ClientRequest instance at:
    at TLSSocket.socketErrorListener (_http_client.js:415:9)
    at TLSSocket.emit (events.js:223:5)
    at emitErrorNT (internal/streams/destroy.js:92:8)
    at emitErrorAndCloseNT (internal/streams/destroy.js:60:3)
    at processTicksAndRejections (internal/process/task_queues.js:81:21)[3
9m {
  errno: 'ETIMEDOUT',
  code: 'ETIMEDOUT',
  syscall: 'connect',
  address: '104.42.78.153',
  port: 443
}
npm ERR! code ELIFECYCLE

這是因為vs code會連接到服務器檢測版本,不過這服務器顯然不是那么好連,因此花的時間比較長。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM