Question

I am running jasmine tests on Karma server. On my tests I have to load a image and a json file test.

They depend on path. Which is the default path for Karma? I mean if i have a image in a directory inside my .js test files how can I reach that file?

I have tested src="myDir/myImage.jpg" but no sucess...

Was it helpful?

Solution

If you use a nodejs web-server to run your app, you can add this to karma.conf.js :

proxies: {
  '/path/to/img/': 'http://localhost:8000/path/to/img/'
},

If you don't use or want to use another server you can define a local proxy but as Karma doesn't provide access to port in use, dynamically, if karma starts on another port than 9876 (default), you will still get a 404 error...

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

Based on this answer

Related GitHub issue for more info ;)

I would also suggest using requireJS because Karma does not deal well with fixtures...

OTHER TIPS

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

To avoid 404 error if karma starts in in a different port, even after setting proxies, do the following:

  1. Kill all the process using the port starting from 9876 (killing node.exe will do the trick)
  2. Run you karma with 9876 port free now
  3. Subsequent runs will be mapped automatically by karma to whatever port it launches
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top