Open anius opened 7 years ago
There is the solution based on path
node module:
const path = require('path');
module.exports = {
basePath: '../src',
files: [
{pattern: '../node_modules/some-package/dist/img/*.png', watched: false, included: false, served: true, nocache: false}
],
proxies: {
'/img/': path.resolve('../node_modules/some-package/dist/img/')
},
};
I couldn't make it work with @ymkins suggestion, but debugging how Karma loads scripts I saw it uses the /absolute
path in the debug.html
when loading scripts above it's current path in the files
array. The code below works:
proxies: {
'/img/': '/absolute' + path.resolve('../node_modules/some-package/dist/img/')
},
I don't see this documented anywhere though, so I have to guess it's some magic internal API.
And this is what I had to do to get a javascript file from one project in another project
The url:
http://localhost:9876/OurPath/Utils.js
And the karma.conf.js. Note the difference in the number of '..'s in files compared to proxy, I don't know why
files: [
{ pattern: "../../../OtherWebProduct/Scripts/OurPath/Utils.js", included: false, served: true, watched: false, nocache: true }
],
proxies: {
'/OurPath/': '/absolute' + path.resolve('../../OtherWebProduct/Scripts/OurPath')
}
Expected behaviour
Proxied files found.
Actual behaviour
WARN [web-server]: 404
when running tests withproxy
path that is one level above basePath:WARN [web-server]: 404: /base/../node_modules/some-package/dist/img/t10062725.png
Pattern that is not outside
basePath
works perfectly.Environment Details
karma.config.js
file: