transform-jest-deps

2.2.2 • Public • Published

transform-jest-deps

Parse the AST, transforming paths in require() calls and other jest-specific calls.

NPM

Based on the transform-deps module.

Install

npm install --save-dev transform-jest-deps

Features

  • Supports ES6 and JSX acorn plugins out-of-the-box.
  • Other plugins can be enabled using falafel options.

Example

var transform = require('transform-jest-deps');
var src = "require('x'); require('y');"
src = transform(src, function(name) {
  if (name == 'x') return 'z';
});
console.log(src);

Output:

require('z'); require('y')

Options

In addition to the options supported by falafel, we support:

  • ignoreTryCatch: Ignore require statements in try/catch blocks

Options may be passed by using an object as the second argument. If this is done, pass the transform function as the 3rd argument.

API

src = transformJestDeps(src, transformFn);

src = transformJestDeps(src, options, transformFn);

Example using options to parse ES6 and JSX:

var acorn = require('acorn-jsx');
var transform = require('transform-jest-deps');
var src = [
  "require('x');",
  "function Thing() {}",
  "var foo = <Thing/>;",
  "var arr1 = [1]; var arr2 = [...arr1, 2]",
  "require('y');"
].join("\n");
 
src = transform(src, {
  ecmaVersion: 6,
  parser: acorn,
  plugins: {jsx: true}
}, function(name) {
  if (name == 'x') return 'z';
});

License

MIT

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 2.2.2
    1,572
    • latest

Version History

  • Version
    Downloads (Last 7 Days)
    • Published
  • 2.2.2
    1,572
  • 2.2.1
    81
  • 2.2.0
    0
  • 2.1.0
    0
  • 2.0.0
    0

Package Sidebar

Install

npm i transform-jest-deps

Weekly Downloads

1,414

Version

2.2.2

License

MIT

Unpacked Size

14.1 kB

Total Files

7

Last publish

Collaborators

  • mwolson