efacilitation / karma-commonjs-preprocessor Goto Github PK
View Code? Open in Web Editor NEWA Karma plugin. Wrap JS or Coffee Files into Commonjs on the fly.
License: MIT License
A Karma plugin. Wrap JS or Coffee Files into Commonjs on the fly.
License: MIT License
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 :)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.