@@ -149,11 +149,19 @@ export function getArgvValue<ParseFuncReturnType>(
149149 return undefined
150150}
151151
152+ /**
153+ * Get the story baseline path for the given category and component
154+ */
155+ const getStoriesBaselinePathFn = ( (
156+ category : CategoryComponent [ 'category' ] ,
157+ component : CategoryComponent [ 'component' ]
158+ ) => `./${ category } /${ component } /` )
159+
152160/**
153161 * Creates a it function for the test file
154162 * @TODO : improve this
155163 */
156- export function itFunction ( { additionalSearchParams, clip, clipSelector, compareOptions, folders : { baselineFolder } , framework, skipStories, storyData, storybookUrl } : CreateItContent ) {
164+ export function itFunction ( { additionalSearchParams, clip, clipSelector, compareOptions, folders, framework, skipStories, storyData, storybookUrl, getStoriesBaselinePath = getStoriesBaselinePathFn } : CreateItContent ) {
157165 const { id } = storyData
158166 const screenshotType = clip ? 'n element' : ' viewport'
159167 const DEFAULT_IT_TEXT = 'it'
@@ -173,9 +181,12 @@ export function itFunction({ additionalSearchParams, clip, clipSelector, compare
173181
174182 // Setup the folder structure
175183 const { category, component } = extractCategoryAndComponent ( id )
184+ const storiesBaselinePath = getStoriesBaselinePath ( category , component )
176185 const checkMethodOptions = {
177186 ...compareOptions ,
178- baselineFolder : join ( baselineFolder , `./${ category } /${ component } /` ) ,
187+ actualFolder : join ( folders . actualFolder , storiesBaselinePath ) ,
188+ baselineFolder : join ( folders . baselineFolder , storiesBaselinePath ) ,
189+ diffFolder : join ( folders . diffFolder , storiesBaselinePath ) ,
179190 }
180191
181192 const it = `
@@ -212,11 +223,11 @@ export function writeTestFile(directoryPath: string, fileID: string, testContent
212223 * Create the test content
213224 */
214225export function createTestContent (
215- { additionalSearchParams, clip, clipSelector, compareOptions, folders, framework, skipStories, stories, storybookUrl } : CreateTestContent ,
226+ { additionalSearchParams, clip, clipSelector, compareOptions, folders, framework, getStoriesBaselinePath , skipStories, stories, storybookUrl } : CreateTestContent ,
216227 // For testing purposes only
217228 itFunc = itFunction
218229) : string {
219- const itFunctionOptions = { additionalSearchParams, clip, clipSelector, compareOptions, folders, framework, skipStories, storybookUrl }
230+ const itFunctionOptions = { additionalSearchParams, clip, clipSelector, compareOptions, folders, framework, getStoriesBaselinePath , skipStories, storybookUrl }
220231
221232 return stories . reduce ( ( acc , storyData ) => acc + itFunc ( { ...itFunctionOptions , storyData } ) , '' )
222233}
@@ -319,14 +330,14 @@ function filterStories(storiesJson: Stories): StorybookData[] {
319330 * Create the test files
320331 */
321332export function createTestFiles (
322- { additionalSearchParams, clip, clipSelector, compareOptions, directoryPath, folders, framework, numShards, skipStories, storiesJson, storybookUrl } : CreateTestFileOptions ,
333+ { additionalSearchParams, clip, clipSelector, compareOptions, directoryPath, folders, framework, getStoriesBaselinePath , numShards, skipStories, storiesJson, storybookUrl } : CreateTestFileOptions ,
323334 // For testing purposes only
324335 createTestCont = createTestContent ,
325336 createFileD = createFileData ,
326337 writeTestF = writeTestFile
327338) {
328339 const fileNamePrefix = 'visual-storybook'
329- const createTestContentData = { additionalSearchParams, clip, clipSelector, compareOptions, folders, framework, skipStories, stories : storiesJson , storybookUrl }
340+ const createTestContentData = { additionalSearchParams, clip, clipSelector, compareOptions, folders, framework, getStoriesBaselinePath , skipStories, stories : storiesJson , storybookUrl }
330341
331342 if ( numShards === 1 ) {
332343 const testContent = createTestCont ( createTestContentData )
0 commit comments