Webworker not appearing in code coverage report in angular

Discussão em 'Angular' iniciado por dmance, Novembro 12, 2024.

  1. dmance

    dmance Guest

    I've wrote a test for a web worker in angular and it run properly.

    The problem is it not appearing in the code coverage report generated after the run.

    this is the code i'm testing:

    /// <reference lib="webworker" />

    let timer: number;
    let currentInterval: number;
    let _inactivityTime: number;
    const ONE_SECOND = 1000;

    const startTimer = (inactivityTime: number) => {
    _inactivityTime = inactivityTime;
    timer = inactivityTime;
    currentInterval = setInterval(() => {
    timer--;
    if (timer <= 0) {
    clearInterval(currentInterval);
    postMessage('logout');
    }
    }, ONE_SECOND) as unknown as number;
    };


    And this is my test.

    describe('Timeout worker', () => {
    it('should send logout message after the time has expired', (done) => {
    const worker = new Worker(new URL('./app.worker', import.meta.url));
    worker.addEventListener('message', (event) => {
    expect(event.data).toBe('logout');
    done();
    });
    jasmine.clock().install();
    worker.postMessage({ action: 'start', time: 0 });
    jasmine.clock().tick(2001);
    jasmine.clock().uninstall();
    });
    });


    I've tried to explicitly declare it in the karma.conf file with no success.

    Continue reading...

Compartilhe esta Página