Hi,
I'm testing this preprocessor and it seems to work well. But there is a little thing annoying for me : modules are registered under their absolute full path name (ie. c:/absolute/path/to/my/app/then/my/file.js). So in my test, I have to do something like this to load my module :
describe("test with require", function(){
var serviceUnderTest;
var serviceUnderTestModule = require('c:/absolute/path/to/my/app/then/my/file.js');
beforeEach(function(){
serviceUnderTest= new serviceUnderTestModule ();
});
it('should have a method defined', function() {
expect(serviceUnderTest.anyFunction).toBeDefined();
});
});
With commonjsPreprocessor options, I saw that I can do a path replacement like that to use relative path instead of absolute one :
commonjsPreprocessor: {
options: {
pathReplace: function(path){
return path.replace(/^c\:\/absolute\/path\/to\/my\/app/, '\.');
}
}
}
so my test become :
describe("test with require", function(){
var serviceUnderTest;
var serviceUnderTestModule = require('./then/my/file.js');
beforeEach(function(){
serviceUnderTest= new serviceUnderTestModule ();
});
it('should have a method defined', function() {
expect(serviceUnderTest.anyFunction).toBeDefined();
});
});
which is better.
But this solution is not good enough : absolute path is still hard coded in my karma conf, but it will be different for each colleagues and for continuous integration.
So, is there a configuration way that I didn't see to avoid these absolute paths ?
Or maybe do you know a way to get current absolute path directly from karma conf file ?
Any help will be very appreciate :)
Hi,
I'm testing this preprocessor and it seems to work well. But there is a little thing annoying for me : modules are registered under their absolute full path name (ie. c:/absolute/path/to/my/app/then/my/file.js). So in my test, I have to do something like this to load my module :
With commonjsPreprocessor options, I saw that I can do a path replacement like that to use relative path instead of absolute one :
so my test become :
which is better.
But this solution is not good enough : absolute path is still hard coded in my karma conf, but it will be different for each colleagues and for continuous integration.
So, is there a configuration way that I didn't see to avoid these absolute paths ?
Or maybe do you know a way to get current absolute path directly from karma conf file ?
Any help will be very appreciate :)