"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const chai_1 = require("chai");
const strackTrace_1 = require("../../src/utils/strackTrace");
const trace_1 = require("../../src/utils/trace");
const managedTest_1 = require("../managedTest");
// eslint-disable-next-line @typescript-eslint/no-var-requires
const chai = require("chai");
// eslint-disable-next-line @typescript-eslint/no-var-requires
chai.use(require("chai-as-promised"));
describe("Managed test", () => {
    let dec;
    before(async function () {
        trace_1.traceManager.displayRuntimeTrace = false;
        trace_1.traceManager.displayStateOnException = false;
        dec = new managedTest_1.ManagedTest();
    });
    beforeEach(async function () {
        trace_1.traceManager.clearTrace();
    });
    it("Stack trace", async () => {
        const stack = new strackTrace_1.StackTrace();
        (0, chai_1.expect)(stack.stack).to.eq(`new StackTrace\nContext.<anonymous>\ncallFn\nTest.Runnable.run\nRunner.runTest\nnext\nnext\ncbHookRun\ndone\n`);
    });
    it("Stack trace find", async () => {
        const stack = new strackTrace_1.StackTrace();
        (0, chai_1.expect)(stack.find(`new StackTrace`)).to.not.eq(null);
    });
    it("Stack trace find - undefined", async () => {
        const stack = new strackTrace_1.StackTrace();
        (0, chai_1.expect)(stack.find(`nekaj`)).to.eq(undefined);
    });
    it("Stack trace find - undefined", async () => {
        const stack = new strackTrace_1.StackTrace();
        (0, chai_1.expect)(stack.find(`new StackTrace`, 20)).to.eq(undefined);
    });
    it("Managed method sync", async () => {
        dec.method(5, 6);
        +(0, chai_1.expect)(trace_1.traceManager.firstTrace).to.eq(`ManagedTest.method(5,6)=36`);
    });
    it("Managed method async", async () => {
        await dec.asyncMethod(7, 8);
        (0, chai_1.expect)(trace_1.traceManager.firstTrace).to.eq(`ManagedTest.asyncMethod(7,8)=224`);
    });
    it("Managed getter", async () => {
        dec.getter;
        (0, chai_1.expect)(trace_1.traceManager.firstTrace).to.eq(`ManagedTest.getter()=1`);
    });
    it("Managed setter", async () => {
        dec.setter = 15;
        (0, chai_1.expect)(trace_1.traceManager.firstTrace).to.eq(`ManagedTest.setter(15)`);
    });
    it("Managed throw sync", async () => {
        (0, chai_1.expect)(function () {
            dec.methodThrow(5, 0);
        }).to.throw("OutsideError");
        (0, chai_1.expect)(trace_1.traceManager.firstTrace).to.eq(`ManagedTest.methodThrow(5,0)`);
    });
    it("Managed throw sync mcc error", async () => {
        (0, chai_1.expect)(function () {
            dec.methodThrowMccError();
        }).to.throw("InvalidData");
        (0, chai_1.expect)(trace_1.traceManager.firstTrace).to.eq(`ManagedTest.methodThrowMccError()`);
    });
    it("Managed throw async", async () => {
        await (0, chai_1.expect)(dec.asyncMethodThrow(7, 0)).to.be.rejectedWith("OutsideError");
        (0, chai_1.expect)(trace_1.traceManager.firstTrace).to.eq(`ManagedTest.asyncMethodThrow(7,0)`);
    });
    it("Managed throw getter", async () => {
        (0, chai_1.expect)(function () {
            dec.getterThrow;
        }).to.throw("OutsideError");
        (0, chai_1.expect)(trace_1.traceManager.firstTrace).to.eq(`ManagedTest.getterThrow()`);
    });
    it("Managed throw setter", async () => {
        (0, chai_1.expect)(function () {
            dec.setterThrow = 15;
        }).to.throw("OutsideError");
        (0, chai_1.expect)(trace_1.traceManager.firstTrace).to.eq(`ManagedTest.setterThrow(15)`);
    });
    it("Managed function", async () => {
        (0, managedTest_1.TestFunctionCall)(1, "A");
        (0, chai_1.expect)(trace_1.traceManager.firstTrace).to.eq(`.TestFunction(1,A)`);
    });
    it("Managed nested test", async () => {
        var _a;
        dec.f1("123");
        (0, chai_1.expect)((_a = trace_1.traceManager.getAsync(0)) === null || _a === void 0 ? void 0 : _a.trace.length).to.eq(20);
    });
});
//# sourceMappingURL=managedTest.test.js.map