import { getTestResults, getTestStats } from '../../results';
export 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 = getTestStats(getTestResults(jsonResults));
        cb(jsonResults, stats);
        response.status(200).send();
    };
}
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