问题
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