From 49c9fb193d07f3376ecea262e798e0eef60b9b7f Mon Sep 17 00:00:00 2001 From: Daniel Huigens Date: Mon, 30 Apr 2018 14:40:59 +0200 Subject: [PATCH] Only call webCrypto.generateKey once in tests --- test/general/key.js | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/test/general/key.js b/test/general/key.js index 8354423e..3003b8f1 100644 --- a/test/general/key.js +++ b/test/general/key.js @@ -1,11 +1,34 @@ const openpgp = typeof window !== 'undefined' && window.openpgp ? window.openpgp : require('../../dist/openpgp'); +const stub = require('sinon/lib/sinon/stub'); const chai = require('chai'); chai.use(require('chai-as-promised')); const { expect } = chai; describe('Key', function() { + let webCrypto = openpgp.util.getWebCryptoAll(); + + if (webCrypto) { + let generateKey = webCrypto.generateKey; + let keyGenStub; + let keyGenValue; + + beforeEach(function() { + keyGenStub = stub(webCrypto, 'generateKey'); + keyGenStub.callsFake(function() { + if (!keyGenValue) { + keyGenValue = generateKey.apply(webCrypto, arguments); + } + return keyGenValue; + }); + }); + + afterEach(function() { + keyGenStub.restore(); + }); + } + describe('V4', tests); describe('V5', function() {