Socket
Socket
Sign inDemoInstall

karma-commonjs-alias

Package Overview
Dependencies
137
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    karma-commonjs-alias

A Karma plugin. Test CommonJS modules with added alias support


Version published
Weekly downloads
25
increased by2400%
Maintainers
1
Install size
11.5 kB
Created
Weekly downloads
 

Readme

Source

karma-commonjs-alias

This is a clone of karma-commonjs with additional features

Here is a link to the original repo karma-commonjs . Go there for a full list of features.

Module aliasing

Added the ability to alias modules for testing. This is useful for mocking and specifying environment. It works the same way as file aliasing in grunt-browserify. Also can alias directories, below is an example.

Here is an example karma.conf configuration

module.exports = function (config) {
	config.set({
	   ...
	   commonjsPreprocessor: {
	      alias : {
	        './config/dev.js': 'config',
	        
	        // Core folder alias, can be used as 'core/util/dom' instead of './js/core/util/dom'
	        './js/core': 'core'
	      }
	   }
	   ...
  });
}

In another file, you can specify the following and it will be resolve to ./config/dev.js

require('config');

NPM Module Support

Just add NPM modules to the files array and they will be available in the tests

module.exports = function (config) {
	config.set({
	   ...
	   files: [
	      '**/*.js'
	      'promise-polyfill', // NPM module used in JS files
	      'observable-lite' // Another NPM module
	   ]
	   ...
  });
}

Transform Support

You can create transforms for other file types, for instance handlebars.

module.exports = function (config) {
	config.set({
	   ...
	   commonjsPreprocessor: {
	      ...
	      transform: {
	         // Send .hbs extension to karma-commonjs-handlebars node module
	         'hbs': 'karma-commonjs-handlebars'
	      }
	   }
	   ...
  });
}

Here is an example of a transform plugin karma-commonjs-handlebars

Node/NPM Installation

npm install karma-commonjs-alias

Keywords

FAQs

Last updated on 30 Nov 2014

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc