Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

There should be a way to ask karma to serve a specific directory in a given path #872

Closed
lgalfaso opened this issue Dec 29, 2013 · 8 comments · Fixed by #1007
Closed

There should be a way to ask karma to serve a specific directory in a given path #872

lgalfaso opened this issue Dec 29, 2013 · 8 comments · Fixed by #1007

Comments

@lgalfaso
Copy link

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

@glepretre
Copy link

I do this (using another webserver) to serve my images and to avoid 404 errors. Is this related to these issues ?
#893
#864

@lgalfaso
Copy link
Author

@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

@glepretre
Copy link

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

@vojtajina
Copy link
Contributor

@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?

@thirusabari
Copy link

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

@einav7
Copy link

einav7 commented Dec 31, 2017

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

@silvaw
Copy link

silvaw commented May 24, 2018

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

@boeckMt
Copy link

boeckMt commented Oct 8, 2021

In case someone still has this problem, here is my fix

Folders:

  • src/assets
  • karma.conf.js
// karma.conf.js


config.set({
    basePath: '',
    ...
    files: [
      { pattern: 'src/assets/*.jpg', included: false, served: true }
    ]
...

request in the test base/src/assets/myImage.jpg

<img src="base/src/assets/myImage.jpg" />

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants