w3resource

Testing MOCHA and test duration


In the previous tutorial we looked at real live example code for mocha; this tutorial will examine the different test durations that exist and how we can test mocha.

TEST DURATION

Many reporters display test duration and then flag tests that are slow (default: 75ms), as shown below with the "spec" reporter:

test duration

Three levels of test duration exist (they are in the image below):

mocha thre levels of test duration
  1. FAST: All tests that run within half of the "slow" threshold shows the duration in green (if at all).
  2. NORMAL: All tests that run exceeding half of the threshold (but still within it) shows the duration in yellow.
  3. SLOW: All tests that run exceeding the threshold shows the duration in red.

If you want to change what is considered "slow", you can make use of the slow() method:

describe('something slow', function() {
  this.slow(300000); // five minutes

  it('it should take long enough for me to go make a sandwich', function() {
    // ...
  });
});

TESTING MOCHA

For you to run Mocha's tests, you need either GNU Make or compatible; Cygwin should be sufficient.

  • You should cd to /path/to/mocha
  • Then run npm install
  • Finally run npm tes


Share this Tutorial / Exercise on : Facebook and Twitter