or run

npx @tessl/cli init
Log in

Version

Files

tile.json

task.mdevals/scenario-2/

Test Result Aggregator

Build a test result aggregator that tracks and reports test execution statistics for a testing framework adapter.

Problem Description

You need to implement a test result aggregator module that collects test execution data and reports statistics. The aggregator should support both modern test frameworks (that provide total test counts) and legacy frameworks (that require manual counting).

Your module should track:

  • Total number of tests to be executed
  • Tests that have started
  • Tests that have completed
  • Overall execution statistics

The aggregator should use native test count properties when available, but fall back to manual counting when the test framework doesn't provide this information.

Requirements

Core Functionality

  1. Initialize the aggregator: Create a function that initializes the test tracking system

    • Accept a configuration object with optional reporter callback
    • The reporter callback should be called with statistics when reporting occurs
  2. Handle test suite beginning: Track when the test suite starts

    • If the test framework provides a totalTests property, use it
    • If not available, initialize a manual counter starting at 0
  3. Handle individual test start: Track each test as it begins

    • Increment manual test counter if native tracking is unavailable
    • Store test start timestamp
  4. Handle individual test completion: Track each test as it finishes

    • Record completion status (passed/failed)
    • Calculate execution duration
  5. Report statistics: Provide a way to get current statistics

    • Total test count (from native property or manual counter)
    • Number of tests started
    • Number of tests completed
    • Pass/fail counts

Test Cases

  • When the test framework provides totalTests=5, the aggregator reports total=5 @test
  • When totalTests is unavailable, manual counting increments from 0 as tests start @test
  • Starting a test increments the started count and triggers timestamp recording @test
  • Completing a test increments completed count and records pass/fail status @test

Implementation

@generates

API

/**
 * Creates a new test result aggregator
 * @param {Object} config - Configuration object
 * @param {Function} config.reporter - Optional callback for reporting statistics
 * @returns {Object} Aggregator instance with tracking methods
 */
function createAggregator(config) {
  // Returns object with methods: onBegin, onTestStart, onTestDone, getStats
}

/**
 * Handle test suite beginning
 * @param {Object} suiteInfo - Information about the test suite
 * @param {number} suiteInfo.totalTests - Optional total test count from framework
 */
// aggregator.onBegin(suiteInfo)

/**
 * Handle individual test start
 * @param {Object} testInfo - Information about the starting test
 * @param {string} testInfo.name - Test name
 */
// aggregator.onTestStart(testInfo)

/**
 * Handle individual test completion
 * @param {Object} result - Test result information
 * @param {string} result.name - Test name
 * @param {boolean} result.passed - Whether test passed
 * @param {number} result.duration - Test execution duration in ms
 */
// aggregator.onTestDone(result)

/**
 * Get current statistics
 * @returns {Object} Statistics object with total, started, completed, passed, failed
 */
// aggregator.getStats()

module.exports = { createAggregator };

Dependencies { .dependencies }

karma-qunit { .dependency }

Provides test tracking patterns and strategies for Karma plugin adapters.

@satisfied-by