"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const api_1 = require("@opentelemetry/api");
const vitest_1 = require("vitest");
const tracedEventEmitter_js_1 = require("./tracedEventEmitter.js");
class TestEmitter extends tracedEventEmitter_js_1.TracedEventEmitter {
}
(0, vitest_1.describe)('TracedEventEmitter', () => {
    let counter;
    let listenerFn;
    let startActiveSpanSpy;
    let tracer;
    let calledWith;
    (0, vitest_1.beforeEach)(async () => {
        counter = 0;
        calledWith = [];
        // using the real tracer to ensure that things work in reality
        tracer = api_1.trace.getTracer('superblocks-test', 'v0');
        startActiveSpanSpy = vitest_1.vi.spyOn(tracer, 'startActiveSpan');
        listenerFn = function (a, b, c) {
            calledWith.push([a, b, c]);
            counter++;
        };
    });
    (0, vitest_1.it)('generates spans when an event is emitted', async () => {
        const testEmitter = new TestEmitter(tracer);
        testEmitter.on('test_event', listenerFn);
        // anonymous function to show that we handle it
        testEmitter.on('test_event', () => {
            counter++;
        });
        testEmitter.emit('test_event', 'a', 'b', true);
        (0, vitest_1.expect)(counter).toEqual(2);
        (0, vitest_1.expect)(calledWith).toEqual([['a', 'b', true]]);
        const spanNames = startActiveSpanSpy.mock.calls.map(([name]) => {
            return name;
        });
        (0, vitest_1.expect)(spanNames).toEqual([
            'TestEmitter.emit',
            'TestEmitter.emit listener on test_event: listenerFn',
            'TestEmitter.emit listener on test_event: anonymous'
        ]);
    });
});
//# sourceMappingURL=tracedEventEmitter.test.js.map