diff --git a/addons/storyshots/storyshots-core/package.json b/addons/storyshots/storyshots-core/package.json index 7018d8c01134..4b5555534e28 100644 --- a/addons/storyshots/storyshots-core/package.json +++ b/addons/storyshots/storyshots-core/package.json @@ -39,6 +39,7 @@ "@types/glob": "^7.1.1", "@types/jest": "^24.0.16", "@types/jest-specific-snapshot": "^0.5.3", + "babel-plugin-require-context-hook": "^1.0.0", "core-js": "^3.0.1", "glob": "^7.1.3", "global": "^4.3.2", diff --git a/addons/storyshots/storyshots-core/src/frameworks/configure.ts b/addons/storyshots/storyshots-core/src/frameworks/configure.ts index 53e500186e45..fd2689eb27d2 100644 --- a/addons/storyshots/storyshots-core/src/frameworks/configure.ts +++ b/addons/storyshots/storyshots-core/src/frameworks/configure.ts @@ -1,9 +1,13 @@ import fs from 'fs'; import path from 'path'; import { toRequireContext } from '@storybook/core/server'; +import registerRequireContextHook from 'babel-plugin-require-context-hook/register'; +import global from 'global'; import { ClientApi } from './Loader'; import { StoryshotsOptions } from '../api/StoryshotsOptions'; +registerRequireContextHook(); + const isFile = (file: string): boolean => { try { return fs.lstatSync(file).isFile(); @@ -67,8 +71,10 @@ function getConfigPathParts(input: string): Output { output.stories = stories.map( (pattern: string | { path: string; recursive: boolean; match: string }) => { const { path: basePath, recursive, match } = toRequireContext(pattern); - return require.context( - path.resolve(configDir, basePath), + // eslint-disable-next-line no-underscore-dangle + return global.__requireContext( + configDir, + basePath, recursive, new RegExp(match.slice(1, -1)) ); diff --git a/addons/storyshots/storyshots-core/src/typings.d.ts b/addons/storyshots/storyshots-core/src/typings.d.ts index 65251d3abdd5..f334e98658b3 100644 --- a/addons/storyshots/storyshots-core/src/typings.d.ts +++ b/addons/storyshots/storyshots-core/src/typings.d.ts @@ -3,3 +3,4 @@ declare module 'jest-preset-angular/*'; declare module 'preact-render-to-json'; declare module 'react-test-renderer*'; declare module '@storybook/core/server'; +declare module 'babel-plugin-require-context-hook/register';