Reputation: 10226
I'm running tests on phantomjs via the karma runner and some of my code makes ajax calls which all fail with a 404.
I've struggled with where to place the file (see: Including libraries fails - what is document root?) but I came across a post (Loading external file from Karma/Jasmine test) that indicates I can configure the karma web server to serve other files.
in particular the ajax calls are attempting to load files from the node_modules
directory so I've configured the karma.config.js
like this:
files: [{
pattern: 'node_modules/*',
served: true,
included: false
}]
and my ajax calls look generally like this (I've placed a blah.js
in the directory for testing):
$.ajax({url: 'node_modules/blah.js', ...});
but still it doesn't work. what am I missing?
Upvotes: 1
Views: 810
Reputation: 10226
well... this is odd but according to the karma docs:
By default all assets are served at http://localhost:[PORT]/base/
so this works: 1) in the karma.conf.js
:
files: [{
pattern: 'node_modules/**',
served: true,
included: false
}]
and 2) the call:
$.ajax({url: '/base/node_modules/blah.js', ...});
...which leaves the question of how that base
can be configured, but for now, this works.
Upvotes: 1