Reputation: 14426
Basically i am test driving my knockout viewmodels in durandal.
I am up to 80 tests and the total running time is 58 seconds.
When i watched the video at : https://www.youtube.com/watch?v=5mHjJ4xf_K0#t=577 the guy runs over 1500 tests in under 3 seconds.
It would seem that i must be doing something very wrong.
Here is an example of one of my tests just to give some context to what i am doing.
define(["doubles/TestCart", "komapping", "generators/BenefitGenerator"],
function (vm, mapping, benefitGenerator)
{
describe('When retrieving the cart data', function ()
{
var benefitOne = benefitGenerator.generateBenefit();
var benefitTwo = benefitGenerator.generateBenefit({ Status: 1 });
var benefitThree = benefitGenerator.generateBenefit({ Status: 2 });
beforeEach(function (done)
{
vm.Reset();
$.mockjax({
url: "*/api/Benefits",
contentType: "application/json",
type: "get",
responseText: [
benefitOne,
benefitTwo,
benefitThree
],
onAfterComplete: function () { done(); }
});
//Act
vm.refresh();
});
it('should have the correct benefits', function ()
{
expect(vm.allBenefits()[0].Id()).toEqual(benefitOne.Id);
expect(vm.allBenefits()[1].Id()).toEqual(benefitTwo.Id);
expect(vm.allBenefits()[2].Id()).toEqual(benefitThree.Id);
});
it('should have the correct cart count', function () {
expect(vm.cartBenefitCount()).toEqual(1);
});
});
});
Note, i do not have the browser minimised and i cant yet quite use the new jasmine 2.1 beforeAll rather than beforeEach (although in tests this will half my run time).
==Addendum==
I have removed all the implementation out of the test, i just have an empty describe with no before each and then two empty its. Each it is taking half a second to run. It seems it is not my test itself but the config somehow, i'll keep looking.
==Addendum 2==
I have now got this down to 20 seconds. The issue was that i had a test with no "describe" it was running this test after each of its in all of the other tests. My bottleneck now seems to be mockjax which takes 500ms.
Upvotes: 2
Views: 1040
Reputation: 14426
Okay so now i have the tests down to 0.2 seconds, quite an improvment i am sure you agree.
Steps to fix this for me were 2 fold:
Step 1) I had a test without a describe, karma was running this test after every single "it" for every test. Once i added the describe my run time went down to 20 seconds. This test with the missing describe was using mockjax which leads me to...
Step 2)
Mockjax has a default response time of 500ms. This was costing me about 20 seconds. I set the config to $.mockjaxSettings.responseTime = 1; //1ms
and now the run time is down to 0.23 seconds.
Hopefully this will help others.
Upvotes: 3