"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.TestContextMemory = void 0;
class TestContextMemory {
    constructor(testArtifactsFolder, testName, testFullName, testFilePath, featuresSettings, dateConstructor = Date) {
        this.testArtifactsFolder = testArtifactsFolder;
        this.testName = testName;
        this.testFullName = testFullName;
        this.testFilePath = testFilePath;
        this.featuresSettings = featuresSettings;
        this.dateConstructor = dateConstructor;
        this.stepIndex = 0;
        this.stepResults = [];
        this.testMetadata = {
            fileName: this.testFilePath,
            testName: this.testName,
            testFullName: this.testFullName,
            timestamp: 0,
            endedTimestamp: 0,
        };
        this._currentStep = undefined;
        this.consoleEntries = [];
        this.unhandledExceptions = [];
        this.testMetadata.timestamp = dateConstructor.now();
    }
    stepStarted() {
        this.stepIndex++;
        const step = {
            index: this.stepIndex,
            startTimestamp: this.dateConstructor.now(),
        };
        return step;
    }
    async stepEnded() {
        if (this._currentStep) {
            this._currentStep.endTimestamp = this.dateConstructor.now();
            this.stepResults.push(this._currentStep);
            this._currentStep = undefined;
        }
    }
    async testEnded() {
        this.testMetadata.endedTimestamp = this.dateConstructor.now();
    }
    addTestMetadata(metadata) {
        Object.assign(this.testMetadata, metadata);
    }
    addAssertionStep(partialStep) {
        if (this._currentStep) {
            throw new Error("invariant: Can't add assertion in a middle of step");
        }
        this.stepIndex++;
        const stepWithIndex = {
            index: this.stepIndex,
            startTimestamp: this.dateConstructor.now(),
            ...partialStep,
        };
        this.stepResults.push(stepWithIndex);
    }
}
exports.TestContextMemory = TestContextMemory;
