"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const results_1 = require("../../results");
function results(cb) {
    return (request, response) => {
        const body = request.body;
        const jsonResults = body.map(x => (Object.assign({}, x, { results: x.results.map(convertBackToError) })));
        const stats = results_1.getTestStats(results_1.getTestResults(jsonResults));
        cb(jsonResults, stats);
        response.status(200).send();
    };
}
exports.results = results;
function convertBackToError(testResult) {
    switch (testResult.type) {
        case 'pass':
        case 'skip':
            return testResult;
        case 'fail':
            return Object.assign({}, testResult, { error: toError(testResult.error) });
    }
    return Object.assign({}, testResult, { results: testResult.results.map(convertBackToError) });
}
function toError(errLikeObject) {
    const error = new Error(errLikeObject.message);
    Object.keys(errLikeObject).forEach(key => {
        ;
        error[key] = errLikeObject[key];
    });
    return error;
}
//# sourceMappingURL=results.js.map