"Failed to get configuration" 通过 Node 在 Mocha 测试中使用 Wolkenkit 客户端

"Failed to get configuration" using Wolkenkit client in Mocha test through Node

我正在尝试通过 Node 中的 Mocha 测试与我的 Wolkenkit 应用程序交互。

tutorial on client connections 之后,当 运行 测试时,我得到以下错误:

Error: Failed to get configuration.
  at ConfigurationWatcher.wentOffline (node_modules/wolkenkit-client/dist/ConfigurationWatcher.js:113:28)
  at /home/aef/Projects/experiments/wolkenkit_bullet/node_modules/wolkenkit-client/dist/ConfigurationWatcher.js:101:16
  at tryCatch (node_modules/es6-promise/dist/es6-promise.js:409:12)
  at invokeCallback (node_modules/es6-promise/dist/es6-promise.js:424:13)
  at publish (node_modules/es6-promise/dist/es6-promise.js:398:7)
  at publishRejection (node_modules/es6-promise/dist/es6-promise.js:339:3)
  at flush (node_modules/es6-promise/dist/es6-promise.js:128:5)
  at processTicksAndRejections (internal/process/task_queues.js:79:11)

非常感谢任何解决此问题的帮助。

我在package.json中添加了以下依赖:

"devDependencies": {
  "chai": "^4.2.0",
  "mocha": "^7.0.1"
},
"dependencies": {
  "wolkenkit": "^3.1.2",
  "wolkenkit-client": "^3.1.0"
},

我的测试代码如下所示:

'using strict';

const expect = require('chai').expect;
const wolkenkit = require('wolkenkit-client');

describe("wolkenkit app", () => {
    it("first test", async () => {
        const app = await wolkenkit.connect({host: 'local.wolkenkit.io', port: 3000});
    });
})

这个错误可能是由您本地的自签名证书引起的。客户端无法连接到后端,因为它不信任此证书。您可以像这样使用 process.env.NODE_TLS_REJECT_UNAUTHORIZED 标志绕过此检查...

process.env.NODE_TLS_REJECT_UNAUTHORIZED = 0;

suite('integration', () => {
  let application;

  suiteSetup(async () => {
    application = await wolkenkit.connect({ host: 'local.wolkenkit.io', port: 3000 });
  });

另一种选择是将证书添加到您信任的证书中。

虽然在 Node 中设置环境变量不起作用,但通过在系统环境中将 NODE_TLS_REJECT_UNAUTHORIZED 设置为 0 解决了问题,例如:

export NODE_TLS_REJECT_UNAUTHORIZED=0

感谢@mattwagl 指出正确的方向。