点击测试超时

Tap test times out

我尝试执行 Diffie Hellman Key 协议:

Test.test('testDh', (t) => {
  const k1 = createSelfKey();
  const k2 = createSelfKey(k1.dh.getPrime(), k1.dh.getGenerator());

  const k1Secret = k1.dh.computeSecret(k2.keys);
  const k2Secret = k2.dh.computeSecret(k1.keys);

  t.equal(k1Secret.toString('hex'), k2Secret.toString('hex'));
  t.end();
});

使用以下函数:

const createSelfKey = (p, g) => {
  let returnVal = null;
  if (_.isNumber(p) && _.isNumber(g)) {
    returnVal = { dh: crypto.createDiffieHellman(p, g) };
  } else {
    returnVal = { dh: crypto.createDiffieHellman(2048) };
  }
  returnVal.keys = returnVal.dh.generateKeys();
  return returnVal;
};

但由于某种原因,测试超时。你知道我如何提高超时限制吗?

test/keygenTests.js ................................... 1/2 31s
  not ok timeout!
    expired: test/keygenTests.js

test/participantTest.js ............................... 1/1
total ................................................. 2/3


  2 passing (31s)
  1 failing

npm ERR! Test failed.  See above for more details.

您可以像这样修改您的 package.json 脚本,使测试不会超时:

 "scripts": {
    //Other scripts do there
    "test": "tap --no-timeout test/*.js",
  },

如您所见,您可以传递参数 --no-timeout 以使您的测试完全不会超时,这在测试计算量大的代码时很有用。