Skip to content

Investigate long running JavaScript tests (top 10 over 1 second)

Our Karma tests run in about a minute in total. However the median for a single test (of the roughly 3000) is one millisecond. So half of the tests take roughly 98% of the time. The top 10 longest running tests take up 50% of the time.


I have tested this by adding the following to test_bundle.js:

beforeEach(() => console.time('test duration'));
afterEach(() => console.timeEnd('test duration'));

Then I ran DEBUG=1 yarn karma and filtered the output with

grep -oE 'test duration: \d+' chrome_debug.log | cut -d ' ' -f 3 | sort -n

By adding the following to test_bundle.js I was able to identify the longest running tests:

let testStarted;

beforeEach(() => {
  testStarted = new Date();
});
afterEach(() => {
  const now = new Date();
  if (now.getTime() - testStarted.getTime() > 999) {
    fail('too long!');
  }
});

 

 

We should take a look at those tests because they likely contain bugs or can be split into smaller tests. If we can half the time for running frontend tests, we safe a significant amount of developer time and increase motivation to run tests locally.

After talking care of above mentioned tests, we can fail tests that take longer than a second and reiterate.

Edited by Inactive Account