写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 [90m at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1134:16)[39m Emitted 'error' event on ClientRequest instance at: [90m at TLSSocket.socketErrorListener (_http_client.js:415:9)[39m [90m at TLSSocket.emit (events.js:223:5)[39m [90m at emitErrorNT (internal/streams/destroy.js:92:8)[39m [90m at emitErrorAndCloseNT (internal/streams/destroy.js:60:3)[39m [90m at processTicksAndRejections (internal/process/task_queues.js:81:21)[3 9m { errno: [32m'ETIMEDOUT'[39m, code: [32m'ETIMEDOUT'[39m, syscall: [32m'connect'[39m, address: [32m'104.42.78.153'[39m, port: [33m443[39m } npm ERR! code ELIFECYCLE
这是因为vs code会连接到服务器检测版本,不过这服务器显然不是那么好连,因此花的时间比较长。