UNPKG

histoire

Version:

A fast story book powered by Vite

20 lines (19 loc) • 854 B
/** Captures Markdown lookup data alongside stories without crossing live context handles. */ export function captureTestContextFiles(ctx) { return { storyFiles: ctx.storyFiles.map(({ markdownFile: _markdown, ...file }) => file), markdownFiles: ctx.markdownFiles.map(({ storyFile, ...file }) => ({ ...file, storyPath: storyFile?.path })), }; } /** Reconstructs the child-owned graph before inline Markdown transforms execute. */ export function restoreTestContextFiles(ctx, files) { ctx.storyFiles = files.storyFiles; ctx.markdownFiles = files.markdownFiles.map(({ storyPath, ...file }) => ({ ...file, storyFile: ctx.storyFiles.find(story => story.path === storyPath), })); for (const file of ctx.markdownFiles) { if (file.storyFile) file.storyFile.markdownFile = file; } }