Storycrawler
Utilities to build Storybook crawling tools with Puppeteer.
Install
$ npm i storycrawler
Usage
import {
StorybookConnection,
StoriesBrowser,
StoryPreviewBrowser,
MetricsWatcher,
createExecutionService,
} from 'storycrawler';
(async function () {
const storybookUrl = 'https://storybookjs.netlify.app/vue-kitchen-sink';
const connection = await new StorybookConnection({ storybookUrl }).connect();
const storiesBrowser = await new StoriesBrowser(connection).boot();
const stories = await storiesBrowser.getStories();
const workers = await Promise.all([0, 1, 2, 3].map(i => new StoryPreviewBrowser(connection, i).boot()));
try {
const service = createExecutionService(workers, stories, story => async worker => {
await worker.setCurrentStory(story);
await new MetricsWatcher(worker.page).waitForStable();
const m = await worker.page.metrics();
return { story, nodesCount: m.Nodes };
});
const results = await service.execute();
results.forEach(({ story, nodesCount }) => console.log(`${story.id}: ${nodesCount}`));
} finally {
await storiesBrowser.close();
await Promise.all(workers.map(worker => worker.close()));
await connection.disconnect();
}
})();
API
See here.
LICENSE
MIT