storybook/code/addons/docs/jest-transform-mdx.js
Norbert de Langen c2bbe43d02
stage0
2022-07-21 11:24:07 +02:00

22 lines
651 B
JavaScript

const path = require('path');
const { ScriptTransformer } = require('@jest/transform');
const { dedent } = require('ts-dedent');
const { compileSync } = require('@storybook/mdx1-csf');
module.exports = {
process(src, filename, config, { instrument }) {
const result = dedent`
/* @jsx mdx */
import React from 'react'
import { mdx } from '@mdx-js/react'
${compileSync(src, { filepath: filename })}
`;
const extension = path.extname(filename);
const jsFileName = `${filename.slice(0, -extension.length)}.js`;
return new ScriptTransformer(config).transformSource(jsFileName, result, instrument);
},
};