"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const utils_1 = require("../../utils");
const consts_1 = require("../../consts");
const runConclusionUtils_1 = require("./runConclusionUtils");
const fs_extra_1 = __importDefault(require("fs-extra"));
class JestReporter {
    constructor(globalConfig, reporterOptions = {}) {
        this.globalConfig = globalConfig;
        this.reporterOptions = reporterOptions;
        this.rootDir = process.cwd();
        this.runId = this.reporterOptions.runId || consts_1.FALLBACK_RUN_ID;
    }
    onTestResult(test, testResult, aggregatedResult) {
    }
    onRunStart(results, options) {
    }
    onTestStart(test) {
    }
    async onRunComplete(contexts, results) {
        const screenplayPath = utils_1.constructScreenplayResultDir(this.rootDir);
        const screenplayRunResultsPath = utils_1.constructTestInvocationResultDir(this.rootDir, this.runId);
        if (!fs_extra_1.default.pathExists(screenplayRunResultsPath)) {
            return;
        }
        const screenplayResults = await runConclusionUtils_1.readRunResultsDirToMap(screenplayRunResultsPath);
        const jestSide = runConclusionUtils_1.jestResultsToIdMap(results.testResults, this.rootDir);
        const finalResults = runConclusionUtils_1.intersectJestAndScreenplay(screenplayResults, jestSide);
        const conclusion = runConclusionUtils_1.prepareRunConclusion(this.runId, results.startTime, finalResults);
        runConclusionUtils_1.writeRunConclusion(screenplayPath, this.runId, conclusion);
        const history = await runConclusionUtils_1.readRunsHistory(screenplayPath);
        runConclusionUtils_1.updateRunsHistory(history, conclusion, consts_1.HISTORY_RUNS_TO_RETAIN);
        runConclusionUtils_1.writeRunsHistory(screenplayPath, history);
    }
    getLastError() {
    }
}
module.exports = JestReporter;
