Giter VIP home page Giter VIP logo

karma-commonjs-preprocessor's People

Contributors

alexnormand avatar anderssonjohan avatar martinwoitzik avatar mwager avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

karma-commonjs-preprocessor's Issues

Possibility to use relative path instead of absolute one to register module ?

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 :)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.