Karma: There should be a way to ask karma to serve a specific directory in a given path

Created on 29 Dec 2013  路  7Comments  路  Source: karma-runner/karma

There should be a way to specify karma that a specific content should be served from a specified path. Right now, the only (very hacky) way to do this is

files = [
  {pattern: 'images/*.png', included: false, served: true}
];

proxies =  {
  '/images': 'http://localhost:9876/base/images'
};

That has the big issue that, when the configuration is run, we cannot be positive that karma will run at port 9876 or another port

help wanted feature

Most helpful comment

None of those answers solved this annoying 404 warn.

I've this setup in my karma.conf.js:

files: [
    {pattern: 'src/main/webapp/assets/images/**/*.png', included: false, served: true},
    'src/main/webapp/assets/scripts/vendor/*.js',
    'src/main/webapp/assets/scripts/dist/*.js',
    'src/main/webapp/assets/bower_components/angular-mocks/angular-mocks.js',
    'src/main/webapp/assets/partials/**/*.html',
    'src/test/javascript/spec_helper.js',
    'src/test/javascript/**/*.js',
],
exclude: [],
.
.
.
proxies: {
    '/assets/images/diagnostico-assinador/': '/base/',
    '/assets/images/prioridade/': '/base/'
}

with proxies setup I got this warn:

WARN [web-server]: 404: /base/image.png

without proxies setup I got this warn:

WARN [web-server]: 404: /assets/images/diagnostico-assinador/image.png
WARN [web-server]: 404: /assets/images/prioridade/image.png

All 7 comments

I do this (using another webserver) to serve my images and to avoid 404 errors. Is this related to these issues ?
https://github.com/karma-runner/karma/issues/893
https://github.com/karma-runner/karma/issues/864

@glepretre Even when having a second web server would somehow fix this, I was thinking that being able to do

proxies = {
  '/images': 'file:///somepath/'
};

would be simple enough to solve the issue here.

I view this issue as unrelated to #893 #864 maybe I am not being able to see the connection

I tried to do :

proxies: {
  '/img/': '/base/app/img/'
},

but I got :

Error: options.host and options.port or options.target are required.

I think it depends on the tests but mine pass anyway with this error

@glepretre I think I like your suggestion the best, this should work:

proxies: {
  '/img/': '/base/app/img/'
},

We just need to fix https://github.com/karma-runner/karma/blob/master/lib/middleware/proxy.js#L37-L42 - if no host/port is defined, use the Karma ones (proxy to Karma itself).
Anybody willing to send a PR for this?

I have tried above fix for karma-warnings. But it was not fixed for me. Could you any one provide me an right solution to the clear the WARN web- server in karma

I've also encountered this issue,
can't I have fake images URL that doesn't exists when I run the tests?

None of those answers solved this annoying 404 warn.

I've this setup in my karma.conf.js:

files: [
    {pattern: 'src/main/webapp/assets/images/**/*.png', included: false, served: true},
    'src/main/webapp/assets/scripts/vendor/*.js',
    'src/main/webapp/assets/scripts/dist/*.js',
    'src/main/webapp/assets/bower_components/angular-mocks/angular-mocks.js',
    'src/main/webapp/assets/partials/**/*.html',
    'src/test/javascript/spec_helper.js',
    'src/test/javascript/**/*.js',
],
exclude: [],
.
.
.
proxies: {
    '/assets/images/diagnostico-assinador/': '/base/',
    '/assets/images/prioridade/': '/base/'
}

with proxies setup I got this warn:

WARN [web-server]: 404: /base/image.png

without proxies setup I got this warn:

WARN [web-server]: 404: /assets/images/diagnostico-assinador/image.png
WARN [web-server]: 404: /assets/images/prioridade/image.png
Was this page helpful?
0 / 5 - 0 ratings

Related issues

anius picture anius  路  3Comments

jhildenbiddle picture jhildenbiddle  路  4Comments

wellyshen picture wellyshen  路  4Comments

jambonrose picture jambonrose  路  5Comments

TKTheTechie picture TKTheTechie  路  4Comments