Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to fix images causing "karma WARN [web-server]: 404"?

I have an angular directive with a template that is doing something like:

<img ng-src="{{url}}" />

In my test, I am setting the scope so that url points to a fictitious image... Karma then says:

WARN [web-server]: 404: /fake.png

So I go into my karma config file and add to the files array:

{pattern: 'spec/javascripts/fixtures/**/*.png', watched: false, included: false, served: true},

And then added proxies:

proxies: {
  '/fake.png': 'spec/javascripts/fixtures/assets/fake.png'
}

...

Now I get:

WARN [proxy]: failed to proxy spec/javascripts/fixtures/assets/fake.png ([object Object])

?

That path is correct, and there is a real image called fake.png there.

The basePath in my config is also properly set to the root of my project...

like image 296
patrick Avatar asked May 14 '15 18:05

patrick


3 Answers

If you don't care about showing the actual image in the tests this is enough:

proxies: {
  '/fake.png': ''
}
like image 128
Vedran Avatar answered Nov 09 '22 10:11

Vedran


I figured it out through random trial and error. Apparently you have to use the magic word "base" in your path.

proxies: {
  '/fake.png': '/base/spec/javascripts/fixtures/assets/fake.png'
}

now it works, but let's be honest, prepending "/base" just seems like nonsense.

like image 35
patrick Avatar answered Nov 09 '22 11:11

patrick


I'd like to comment, but I don't have enough rep, as I am a SO newbie. /base is the base path from the karma config. You specify that in

module.exports = function () {
    return {
        ...
        basePath: '../',
        ...
    }    
}

When you do that, the base part is automatically prepended to the pattern. So there is not really nonsense going on, but incomplete configuration. Have a great one :)

like image 3
devastato Avatar answered Nov 09 '22 10:11

devastato