Skip to content
This repository has been archived by the owner on Jul 29, 2023. It is now read-only.

Jest transformer that wraps mdx-js/mx webpack loader

License

Notifications You must be signed in to change notification settings

JosephEigenraam/jest-mdx-loader

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

Jest transformer that wraps mdx-js/mx webpack loader

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published