karma-runner / karma-commonjs

A Karma plugin. Test CommonJS modules.
MIT License
73 stars 30 forks source link

add fallback for require that using aliases #53

Open lucaoliano opened 8 years ago

lucaoliano commented 8 years ago

I added a fallback in module resolution, giving the possibility to add an alias for a module. In the karma.conf.js, aliases can be specified like below:

module.exports = function (config) {
  config.set({
    ...
    commonjsPreprocessor: {
      ...
      alias: {
        'module_a': '../node_modules/common_module_a/lib/common_module.js',
        'module_b': '../node_modules/common_module_b/lib/common_module.js'
      }
    }
    ...
  });
};

In this way require('module_a') is resolved to '../node_modules/common_module_a/lib/common_module.js'

This resolves the issue #52

googlebot commented 8 years ago

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

:memo: Please visit https://cla.developers.google.com/ to sign.

Once you've signed, please reply here (e.g. I signed it!) and we'll verify. Thanks.


lucaoliano commented 8 years ago

I signed it!

googlebot commented 8 years ago

CLAs look good, thanks!