Function transformIsolatedComponentFiles

  • Transform a typescript stories file by adding executeCyTests to the bottom with all exports explicitly passed in and the default recreated to be passed in as 'default' prop.

    In webpack, can use with ts-loader like so

    {
    test: /\.[jt]sx?$/,
    exclude: [/node_modules/],
    use: [
    {
    loader: "ts-loader",
    options: {
    happyPackMode: true,
    transpileOnly: true,
    ...(useIsolatedComponentFiles && {
    getCustomTransformers: () => ({
    before: [transformIsolatedComponentFiles()],
    }),
    }),
    },
    },
    ],
    }

    To include mdx files as tests, add this to module rules

    {
    test: /\.mdx$/,
    use: [
    <above ts-loader config>,
    {
    loader: require.resolve("@storybook/mdx1-csf/loader"),
    options: { skipCsf },
    },
    ],
    },

    see cypressWebpackConfigMdx for an abstraction to do just that, as well as load non-story mdx and md files.

    Parameters

    • executeCyTestsLocation: string = "orphic-cypress"

      Location for executeCyTests. Defaults to this module, but you could import it elsewhere and change via pre/post call, or rewrite entirely and point to it from here

    • storyPattern: string | RegExp = ...

      story filename pattern

    Returns TransformerFactory<SourceFile>