catdad/grandma

View on GitHub
lib/estimate-duration.js

Summary

Maintainability
A
1 hr
Test Coverage
A
100%
module.exports = function() {
    var start = Infinity;
    var end = -Infinity;
    var result = 0;

    var api = {};

    api.include = function include(record) {
        if (!record.report) {
            return api;
        }

        var fulltest = record.report.fullTest;

        if (fulltest.start < start) {
            start = fulltest.start;
        }

        if (fulltest.end > end) {
            end = fulltest.end;
        }

        result = end - start;

        return api;
    };

    Object.defineProperty(api, 'result', {
        configurable: false,
        enumerable: true,
        get: function() {
            return result;
        }
    });

    return api;
};