Skip to content

Instantly share code, notes, and snippets.

@silvawillian
Created December 4, 2019 15:16
Show Gist options
  • Save silvawillian/388479c322769ff0b22b461a0ca6b16c to your computer and use it in GitHub Desktop.
Save silvawillian/388479c322769ff0b22b461a0ca6b16c to your computer and use it in GitHub Desktop.

Revisions

  1. silvawillian created this gist Dec 4, 2019.
    18 changes: 18 additions & 0 deletions MochaTimer.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,18 @@
    /* eslint-disable */

    beforeEach(function cb() {
    if (!this.currentTest.parent.timerStart) {
    this.currentTest.parent.timerIndex = 0;
    this.currentTest.parent.timerStart = Date.now();
    }
    });

    afterEach(function cb() {
    if (this.currentTest.parent.timerStart && ++this.currentTest.parent.timerIndex === this.currentTest.parent.tests.length) {
    const elapsedTimeInMs = Date.now() - this.currentTest.parent.timerStart;

    if (elapsedTimeInMs >= 1000) {
    console.error(`File: "${this.currentTest.file}" - Suite: "${this.currentTest.parent.fullTitle()}" - Elapsed: ${elapsedTimeInMs}ms`);
    }
    }
    });