点击测试超时

时间:2019-01-02 15:03:14

标签: node.js unit-testing tap

我尝试执行Diffie Hellman密钥协议:

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.

1 个答案:

答案 0 :(得分:1)

您可以通过修改package.json脚本来使测试不超时:

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

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