Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Socket
Sign inDemoInstall

jest-webpack-alias

Package Overview
Dependencies
Maintainers
1
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jest-webpack-alias

Preprocessor for Jest that is able to resolve require() statements using webpack aliases.


Version published
Maintainers
1
Created
Source

jest-webpack-alias

Preprocessor for Jest that is able to resolve require() statements using webpack aliases.

See also transform-jest-deps.

Install

npm install --save-dev jest-webpack-alias

Setup

File __tests__/preprocessor.js:

var babelJest = require('babel-jest');
var webpackAlias = require('jest-webpack-alias');

module.exports = {
  process: function(src, filename) {
    if (filename.indexOf('node_modules') === -1) {
      src = babelJest.process(src, filename);
      src = webpackAlias.process(src, filename);
    }
    return src;
  }
};

File package.json:

{
  ...
  "jest": {
    ...
    "scriptPreprocessor": "<rootDir>/__tests__/preprocessor.js",
  },
  "jest-webpack-alias": {
    "profile": "dev"
  }
}

Manual package resolution

Code like this will not work, because an AST parser is not smart enough to evaluate variables into strings.

var moduleName = 'myModName';
var computed = require(moduleName);

It can be rewritten like this, using the resolve function:

var resolve = require('jest-webpack-alias').resolve;
var moduleName = 'myModName';
var computed = require(resolve(moduleName, __filename));

package.json options

  • jest-webpack-alias.configFile: Optional, default is "webpack.config.js". If provided, this should be a path fragment relative to your package.json file. Example: "webpack/config.dev.js".

  • jest-webpack-alias.profile: Optional. If provided, will expect your webpack config to be an array of profiles, and will match against the name field of each to choose a webpack config that applies to your Jest tests. See https://github.com/webpack/webpack/tree/master/examples/multi-compiler for an example of this kind of setup.

Missing features

This module does not yet support:

  • resolve.alias settings whose values are absolute paths

License

MIT

Keywords

FAQs

Package last updated on 12 Jan 2016

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc