import { trace } from '@opentelemetry/api';
import { vi, describe, it, expect, beforeEach } from 'vitest';
import { TracedEventEmitter } from './tracedEventEmitter.js';
class TestEmitter extends TracedEventEmitter {
}
describe('TracedEventEmitter', () => {
    let counter;
    let listenerFn;
    let startActiveSpanSpy;
    let tracer;
    let calledWith;
    beforeEach(async () => {
        counter = 0;
        calledWith = [];
        // using the real tracer to ensure that things work in reality
        tracer = trace.getTracer('superblocks-test', 'v0');
        startActiveSpanSpy = vi.spyOn(tracer, 'startActiveSpan');
        listenerFn = function (a, b, c) {
            calledWith.push([a, b, c]);
            counter++;
        };
    });
    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);
        expect(counter).toEqual(2);
        expect(calledWith).toEqual([['a', 'b', true]]);
        const spanNames = startActiveSpanSpy.mock.calls.map(([name]) => {
            return name;
        });
        expect(spanNames).toEqual([
            'TestEmitter.emit',
            'TestEmitter.emit listener on test_event: listenerFn',
            'TestEmitter.emit listener on test_event: anonymous'
        ]);
    });
});
//# sourceMappingURL=tracedEventEmitter.test.js.map