Package detail

suite-metrics

reid-moffat337MIT1.3.1

Easily keep track of metrics for many nested test suites

test, metrics, suite, benchmark

readme

suite-metrics

npm npm npm

Easily keep track of metrics for many nested test suites

Features:

  • Precision Tracking: Measure test execution time down to microseconds
  • Flexible Nesting: Organize tests in any number of nested suites with any structure
  • Comprehensive Metrics: Collect data for top-level suites, sub-suites, and individual tests
  • Simple Interface: Easily integrate into your testing workflow with only a few lines of code

📦 Installation

npm i suite-metrics -D

# or
pnpm i suite-metrics -D

# or
yarn add suite-metrics -D

🚀 Usage

Setup

import SuiteMetrics from 'suite-metrics';

// Use as a singleton for easy access across multiple files
const metrics = SuiteMetrics.getInstance();

// Alternatively, create a new instance for isolated metrics
const metrics = new SuiteMetrics();

// Reset the singleton instance to clear data (not required for new instances)
SuiteMetrics.resetInstance();

Tracking Tests

// Start tracking a test (directly before test logic for best accuracy)
metrics.startTest(["Suite Name", "Sub-suite name", "Test Name"]);

// Execute your test logic here...

// Call directly after test logic completes to stop tracking
metrics.endTest();

Getting Metrics

// Simple summary of all suites and tests - # test/suites, total/avg time
console.log(metrics.printAllSuiteMetrics());

// Detailed metrics for a specific test
metrics.getTestMetrics(["Suite Name", "Test Name"]);

// Detailed metrics for a specific suite and its direct tests
metrics.getSuiteMetrics(["Suite Name"]);

// Detailed metrics for a specific suite and all sub-suites & sub-tests
metrics.getSuiteMetricsRecursive(["Suite Name"]);

// Helpers
if (metrics.suiteExists(["Suite Name"])) {
    // ...
}

if (metrics.testExists(["Suite Name", "Test Name"])) {
    // ...
}

changelog

suite-metrics

1.3.1

Patch Changes

  • 9574848: Removed buggy Mocha context validation. Can be done relatively easily with a helper method if desired.

1.3.0

Minor Changes

  • 56905e5: - Added option to reset Metrics singleton
    • Added getNameFromMocha to easily get test path format from a Mocha test
    • Allow passing Mocha contexts to methods in place of literal name arrays

1.2.0

Minor Changes

  • f611f21: Fixed singleton bug (should be static). Added method to get metrics for a specific test. Improved printed metrics formatting + data.

1.1.0

Minor Changes

  • 881c02b: Added optional singleton for ease of use. Added number of sub-suite tests in printing metrics, and added a README with instructions

1.0.0

Major Changes

  • 150d03b: First release. Added suite metrics main class with options ot start & stop testing, check test/suite exists, getting suite metrics and printing metrics