Created
August 9, 2022 13:22
-
-
Save jeremieflrnt/357157010998e44b80b6ce0b08ec7602 to your computer and use it in GitHub Desktop.
Get Stories from storybook
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
test.describe('Get a list of all stories', () => { | |
test('Get a list of all stories', async ({ page, baseURL }) => { | |
await page.goto(baseURL); | |
await page.click('#storybook-explorer-tree >> #components >> //*[name()="svg"]'); | |
const componentList = {}; | |
const components = await page | |
.locator('#storybook-explorer-tree >> //*[@data-nodetype="component"]') | |
.allTextContents(); | |
for (const component of components) { | |
componentList[component] = []; | |
const dataItemId = await page | |
.locator(`#storybook-explorer-tree >> //*[@data-nodetype="component" and text()="${component}"]`) | |
.getAttribute('data-item-id'); | |
const stories = page.locator( | |
`#storybook-explorer-tree >> //*[@data-nodetype="story" and @data-parent-id="${dataItemId}"]`, | |
); | |
const count = await stories.count(); | |
for (let i = 0; i < count; ++i) { | |
componentList[component].push(await stories.nth(i).getAttribute('data-item-id')); | |
} | |
} | |
const pathForpageList = `resources`; | |
!fs.existsSync(pathForpageList) && | |
fs.mkdir(`resources`, (err) => { | |
if (err) throw err; | |
}); | |
fs.writeFile(`resources/componentList.json`, JSON.stringify(componentList), function (err) { | |
if (err) throw err; | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment