Skip to content

Latest commit

 

History

History
63 lines (45 loc) · 1.03 KB

README.md

File metadata and controls

63 lines (45 loc) · 1.03 KB

jest-mdx-loader

Jest transformer that wraps mdx-js/mx webpack loader

Install

yarn add --dev jest-mdx-loader

Usage

Install jest-mdx-loader and then add it to your jest.config.js under transform:

/// jest.config.js

module.exports = {
  //...
  transform: {
    "^.+\\.jsx?$": "babel-jest",
    ".mdx?$": "jest-mdx-loader"
  }
  //...
};

If you need to perform any additional pre-processing prior to parsing with mdx you can easily extend the loader as follows:

// src/my-custom-jest-mdx-loader.js

const createTransformer = require("jest-mdx-loader/src/createTransformer");

preMdxParseCallback = function(src) {
  var modifiedSrc = src;

  // CUSTOM LOGIC HERE

  return modifiedSrc;
};

module.exports = {
  process: createTransformer(preMdxParseCallback)
};
/// jest.config.js

module.exports = {
  //...
  transform: {
    "^.+\\.jsx?$": "babel-jest",
    ".mdx?$": "<rootDir>/src/my-custom-jest-mdx-loader.js"
  }
  //...
};

Licence

MIT © Joseph Black