docs
evals
scenario-1
scenario-10
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9
Build a test result aggregator that tracks and reports test execution statistics for a testing framework adapter.
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:
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.
Initialize the aggregator: Create a function that initializes the test tracking system
reporter callbackHandle test suite beginning: Track when the test suite starts
totalTests property, use itHandle individual test start: Track each test as it begins
Handle individual test completion: Track each test as it finishes
Report statistics: Provide a way to get current statistics
/**
* 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 };Provides test tracking patterns and strategies for Karma plugin adapters.