Best JavaScript code snippet using storybook-root
watch-story-specifiers.test.ts
Source:watch-story-specifiers.test.ts
...13 afterEach(() => close?.());14 it('watches basic globs', async () => {15 const specifier = normalizeStoriesEntry('../src/**/*.stories.@(ts|js)', options);16 const onInvalidate = jest.fn();17 close = watchStorySpecifiers([specifier], { workingDir }, onInvalidate);18 expect(Watchpack).toHaveBeenCalledTimes(1);19 const watcher = Watchpack.mock.instances[0];20 expect(watcher.watch).toHaveBeenCalledWith({ directories: ['./src'] });21 expect(watcher.on).toHaveBeenCalledTimes(2);22 const onChange = watcher.on.mock.calls[0][1];23 const onRemove = watcher.on.mock.calls[1][1];24 // File changed, matching25 onInvalidate.mockClear();26 await onChange('src/nested/Button.stories.ts', 1234);27 expect(onInvalidate).toHaveBeenCalledWith(specifier, `./src/nested/Button.stories.ts`, false);28 // File changed, NOT matching29 onInvalidate.mockClear();30 await onChange('src/nested/Button.ts', 1234);31 expect(onInvalidate).not.toHaveBeenCalled();32 // File removed, matching33 onInvalidate.mockClear();34 await onRemove('src/nested/Button.stories.ts');35 expect(onInvalidate).toHaveBeenCalledWith(specifier, `./src/nested/Button.stories.ts`, true);36 // File removed, NOT matching37 onInvalidate.mockClear();38 await onRemove('src/nested/Button.ts');39 expect(onInvalidate).not.toHaveBeenCalled();40 // File moved out, matching41 onInvalidate.mockClear();42 await onChange('src/nested/Button.stories.ts', null);43 expect(onInvalidate).toHaveBeenCalledWith(specifier, `./src/nested/Button.stories.ts`, true);44 // File renamed, matching45 onInvalidate.mockClear();46 await onChange('src/nested/Button.stories.ts', null);47 await onChange('src/nested/Button-2.stories.ts', 1234);48 expect(onInvalidate).toHaveBeenCalledWith(specifier, `./src/nested/Button.stories.ts`, true);49 expect(onInvalidate).toHaveBeenCalledWith(specifier, `./src/nested/Button-2.stories.ts`, false);50 });51 it('scans directories when they are added', async () => {52 const specifier = normalizeStoriesEntry('../src/**/*.stories.@(ts|js)', options);53 const onInvalidate = jest.fn();54 close = watchStorySpecifiers([specifier], { workingDir }, onInvalidate);55 expect(Watchpack).toHaveBeenCalledTimes(1);56 const watcher = Watchpack.mock.instances[0];57 expect(watcher.watch).toHaveBeenCalledWith({ directories: ['./src'] });58 expect(watcher.on).toHaveBeenCalledTimes(2);59 const onChange = watcher.on.mock.calls[0][1];60 onInvalidate.mockClear();61 await onChange('src/nested', 1234);62 expect(onInvalidate).toHaveBeenCalledWith(specifier, `./src/nested/Button.stories.ts`, false);63 });64 it('watches single file globs', async () => {65 const specifier = normalizeStoriesEntry('../src/nested/Button.stories.mdx', options);66 const onInvalidate = jest.fn();67 close = watchStorySpecifiers([specifier], { workingDir }, onInvalidate);68 expect(Watchpack).toHaveBeenCalledTimes(1);69 const watcher = Watchpack.mock.instances[0];70 expect(watcher.watch).toHaveBeenCalledWith({ directories: ['./src/nested'] });71 expect(watcher.on).toHaveBeenCalledTimes(2);72 const onChange = watcher.on.mock.calls[0][1];73 const onRemove = watcher.on.mock.calls[1][1];74 // File changed, matching75 onInvalidate.mockClear();76 await onChange('src/nested/Button.stories.mdx', 1234);77 expect(onInvalidate).toHaveBeenCalledWith(specifier, `./src/nested/Button.stories.mdx`, false);78 // File changed, NOT matching79 onInvalidate.mockClear();80 await onChange('src/nested/Button.mdx', 1234);81 expect(onInvalidate).not.toHaveBeenCalled();82 // File removed, matching83 onInvalidate.mockClear();84 await onRemove('src/nested/Button.stories.mdx');85 expect(onInvalidate).toHaveBeenCalledWith(specifier, `./src/nested/Button.stories.mdx`, true);86 // File removed, NOT matching87 onInvalidate.mockClear();88 await onRemove('src/nested/Button.mdx');89 expect(onInvalidate).not.toHaveBeenCalled();90 // File moved out, matching91 onInvalidate.mockClear();92 await onChange('src/nested/Button.stories.mdx', null);93 expect(onInvalidate).toHaveBeenCalledWith(specifier, `./src/nested/Button.stories.mdx`, true);94 });95 it('multiplexes between two specifiers on the same directory', async () => {96 const globSpecifier = normalizeStoriesEntry('../src/**/*.stories.@(ts|js)', options);97 const fileSpecifier = normalizeStoriesEntry('../src/nested/Button.stories.mdx', options);98 const onInvalidate = jest.fn();99 close = watchStorySpecifiers([globSpecifier, fileSpecifier], { workingDir }, onInvalidate);100 expect(Watchpack).toHaveBeenCalledTimes(1);101 const watcher = Watchpack.mock.instances[0];102 expect(watcher.watch).toHaveBeenCalledWith({ directories: ['./src', './src/nested'] });103 expect(watcher.on).toHaveBeenCalledTimes(2);104 const onChange = watcher.on.mock.calls[0][1];105 onInvalidate.mockClear();106 await onChange('src/nested/Button.stories.ts', 1234);107 expect(onInvalidate).toHaveBeenCalledWith(108 globSpecifier,109 `./src/nested/Button.stories.ts`,110 false111 );112 onInvalidate.mockClear();113 await onChange('src/nested/Button.stories.mdx', 1234);...
stories-json.ts
Source:stories-json.ts
...50 );51 async function ensureStarted() {52 if (started) return;53 started = true;54 watchStorySpecifiers(normalizedStories, { workingDir }, (specifier, path, removed) => {55 generator.invalidate(specifier, path, removed);56 maybeInvalidate();57 });58 await generator.initialize();59 }60 router.use('/stories.json', async (req: Request, res: Response) => {61 await ensureStarted();62 try {63 const index = await generator.getIndex();64 res.header('Content-Type', 'application/json');65 res.send(JSON.stringify(index));66 } catch (err) {67 res.status(500);68 res.send(err.message);...
Using AI Code Generation
1import { watchStorySpecifiers } from 'storybook-root';2watchStorySpecifiers();3watchStorySpecifiers();4watchStorySpecifiers();5import { watchStorySpecifiers } from 'storybook-root';6watchStorySpecifiers();7import { watchStorySpecifiersIn } from 'storybook-root';8watchStorySpecifiersIn('path/to/storybook');9import { getStorybookRoot } from 'storybook-root';10getStorybookRoot();11import { getStorybookRootIn } from 'storybook-root';12getStorybookRootIn('path/to/storybook');13import { getStorybookRoots } from 'storybook-root';14getStorybookRoots();15import { getStorybookRootsIn } from 'storybook-root';16getStorybookRootsIn('path/to/storybook');17import { getStorybookRootsInCwd } from 'storybook-root';18getStorybookRootsInCwd();19import { getStorybookRootsInCwdSync } from 'storybook-root';20getStorybookRootsInCwdSync();21import { getStorybookRootsInCwdAsync } from 'storybook-root';22getStorybookRootsInCwdAsync();23import { getStorybookRootsInCwdAsync } from 'storybook-root';24getStorybookRootsInCwdAsync();25import { getStorybookRootsInCwdAsync } from 'storybook-root';26getStorybookRootsInCwdAsync();27import
Using AI Code Generation
1import { watchStorySpecifiers } from 'storybook-root';2import { storiesOf } from '@storybook/react';3import { action } from '@storybook/addon-actions';4watchStorySpecifiers({ storybookRoot: 'storybook-root' });5storiesOf('Button', module)6 .add('with text', () => (7 <button onClick={action('clicked')}>Hello Button</button>8 .add('with some emoji', () => (9 <button onClick={action('clicked')}>😀 😎 👍 💯</button>10 ));11import { watchStorySpecifiers } from 'storybook-root';12import { storiesOf } from '@storybook/react';13import { action } from '@storybook/addon-actions';14watchStorySpecifiers({ storybookRoot: 'storybook-root' });15storiesOf('Button', module)16 .add('with text', () => (17 <button onClick={action('clicked')}>Hello Button</button>18 .add('with some emoji', () => (19 <button onClick={action('clicked')}>😀 😎 👍 💯</button>20 ));
Using AI Code Generation
1import { watchStorySpecifiers } from 'storybook-root';2import { storiesOf } from '@storybook/react';3import { action } from '@storybook/addon-actions';4watchStorySpecifiers().then(specifiers => {5 specifiers.forEach(specifier => {6 storiesOf(specifier.kind, module).add(specifier.story, () => (7 <div onClick={action('clicked')}>{specifier.story}</div>8 ));9 });10});11import { watchStorySpecifiers } from 'storybook-root';12test('test', async () => {13 const specifiers = await watchStorySpecifiers();14 expect(specifiers).toEqual([15 {16 },17 ]);18});
Using AI Code Generation
1var storybookRoot = require('storybook-root');2storybookRoot.watchStorySpecifiers(function(storySpecifiers) {3 console.log(storySpecifiers);4});5### storybookRoot.getStorySpecifiers()6### storybookRoot.watchStorySpecifiers(callback)
Using AI Code Generation
1const storybookRoot = require('storybook-root');2const storybookRootPath = storybookRoot.getRootPath();3const storybookRootConfig = storybookRoot.getStorybookConfig(storybookRootPath);4const storybookRootConfigSpecifiers = storybookRootConfig.storySpecifiers;5console.log(storybookRootConfigSpecifiers);6const storybookRoot = require('storybook-root');7const storybookRootPath = storybookRoot.getRootPath();8const storybookRootConfig = storybookRoot.getStorybookConfig(storybookRootPath);9const storybookRootConfigSpecifiers = storybookRootConfig.storySpecifiers;10console.log(storybookRootConfigSpecifiers);11const storybookRoot = require('storybook-root');12const storybookRootPath = storybookRoot.getRootPath();13const storybookRootConfig = storybookRoot.getStorybookConfig(storybookRootPath);14const storybookRootConfigSpecifiers = storybookRootConfig.storySpecifiers;15console.log(storybookRootConfigSpecifiers);16const storybookRoot = require('storybook-root');17const storybookRootPath = storybookRoot.getRootPath();18const storybookRootConfig = storybookRoot.getStorybookConfig(storybookRootPath);19const storybookRootConfigSpecifiers = storybookRootConfig.storySpecifiers;20console.log(storybookRootConfigSpecifiers);21const storybookRoot = require('storybook-root');22const storybookRootPath = storybookRoot.getRootPath();23const storybookRootConfig = storybookRoot.getStorybookConfig(storybookRootPath);24const storybookRootConfigSpecifiers = storybookRootConfig.storySpecifiers;25console.log(storybookRootConfigSpecifiers);26const storybookRoot = require('storybook-root');27const storybookRootPath = storybookRoot.getRootPath();28const storybookRootConfig = storybookRoot.getStorybookConfig(storybookRootPath);29const storybookRootConfigSpecifiers = storybookRootConfig.storySpecifiers;30console.log(storybookRootConfig
Using AI Code Generation
1const { watchStorySpecifiers } = require('storybook-root');2watchStorySpecifiers(storySpecifiers => {3});4import { getStorySpecifiers } from 'storybook-root';5const storySpecifiers = getStorySpecifiers();6 { id: 'story-id-1', name: 'story-name-1', kind: 'story-kind-1' },7 { id: 'story-id-2', name: 'story-name-2', kind: 'story-kind-2' },8];9import { watchStorySpecifiers } from 'storybook-root';10watchStorySpecifiers(storySpecifiers => {11});12const stopWatching = watchStorySpecifiers(storySpecifiers => {13});14stopWatching();
Using AI Code Generation
1import { watchStorySpecifiers } from 'storybook-rooter';2import specifiers from './stories';3watchStorySpecifiers(specifiers);4 {5 {6 props: {7 },8 },9 },10];11import { storiesOf } from '@storybook/react';12import { action } from '@storybook/addon-actions';13import { linkTo } from '@storybook/addon-links';14import { withSpecifiers } from 'storybook-rooter';15import MyComponent from '../src/MyComponent';16storiesOf('MyComponent', module)17 .add('default', withSpecifiers(() => <MyComponent />));18 {19 {20 props: {21 },22 },23 },24];
Using AI Code Generation
1const storybookRoot = require('storybook-root');2const storybookRootPath = storybookRoot.getRootPath();3const storybookSpecifiers = storybookRoot.watchStorySpecifiers();4const storybookStories = storybookRoot.watchStorybookStories(storybookSpecifiers);5const storybookRoot = require('storybook-root');6const storybookRootPath = storybookRoot.getRootPath();7const storybookSpecifiers = storybookRoot.watchStorySpecifiers();8const storybookStories = storybookRoot.watchStorybookStories(storybookSpecifiers);9console.log(storybookStories);10const storybookRoot = require('storybook-root');11const storybookRootPath = storybookRoot.getRootPath();12const storybookSpecifiers = storybookRoot.watchStorySpecifiers();13const storybookStories = storybookRoot.watchStorybookStories(storybookSpecifiers);14console.log(storybookStories);15const storybookStoriesKeys = Object.keys(storybookStories);16storybookStoriesKeys.forEach((key) => {17 const storybookStory = storybookStories[key];18 console.log(storybookStory);19});20const storybookRoot = require('storybook-root');21const storybookRootPath = storybookRoot.getRootPath();22const storybookSpecifiers = storybookRoot.watchStorySpecifiers();23const storybookStories = storybookRoot.watchStorybookStories(storybookSpecifiers);24console.log(storybookStories);25const storybookStoriesKeys = Object.keys(storybookStories);26storybookStoriesKeys.forEach((key) => {27 const storybookStory = storybookStories[key];28 console.log(storybookStory);29 const storybookStoryKeys = Object.keys(storybookStory);30 storybookStoryKeys.forEach((key) => {31 const storybookStoryKey = storybookStory[key];32 console.log(storybookStoryKey);33 });34});
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!