404 on Karma when trying to use web worker

こ雲淡風輕ζ 提交于 2021-02-08 04:37:27

问题


I'm getting the error WARN [web-server]: 404: /app/workers/total.js when trying to run a unit test on a web worker.

Karma.conf.js includes the following:

...
files: [
        ...
        'app/workers/*.js',
        'unit-tests/mocks/**/*.js',
        'unit-tests/src/**/*.js'
    ],
....

the test goes as follows:

describe('totals', function () {
    var worker;

    beforeEach(function() {
        worker = new Worker('/app/workers/total.js');
    });

    it('should do something', function () {
        ...
    });
});

I have tried many urls, but none seem to work


回答1:


Finally I found the solution on https://github.com/karma-runner/karma/issues/1302, the trick is to include /base as part of the worker URL, being the solution:

describe('totals', function () {
    var worker;

    beforeEach(function() {
        worker = new Worker('/base/app/workers/total.js');
    });

    it('should do something', function () {
        ...
    });
});

Note /base as part of the worker URL.

Thanks to maksimr



来源:https://stackoverflow.com/questions/33035228/404-on-karma-when-trying-to-use-web-worker

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!