How to use excludeStories method in storybook-root

Best JavaScript code snippet using storybook-root

start.test.js

Source:start.test.js Github

copy

Full Screen

1/* eslint-disable no-underscore-dangle */2import { history, document, window } from 'global';3import Events from '@storybook/core-events';4import start, { isExportStory } from './start';5jest.mock('@storybook/client-logger');6jest.mock('global', () => ({7 history: { replaceState: jest.fn() },8 navigator: { userAgent: 'browser', platform: '' },9 window: {10 __STORYBOOK_CLIENT_API__: undefined,11 addEventListener: jest.fn(),12 location: { search: '' },13 history: { replaceState: jest.fn() },14 matchMedia: jest.fn().mockReturnValue({ matches: false }),15 },16 document: {17 addEventListener: jest.fn(),18 getElementById: jest.fn().mockReturnValue({}),19 body: { classList: { add: jest.fn(), remove: jest.fn() } },20 documentElement: {},21 location: { search: '?id=kind--story' },22 },23}));24afterEach(() => {25 window.__STORYBOOK_CLIENT_API__ = undefined;26});27it('returns apis', () => {28 const render = jest.fn();29 const result = start(render);30 expect(result).toEqual(31 expect.objectContaining({32 context: expect.any(Object),33 clientApi: expect.any(Object),34 configApi: expect.any(Object),35 forceReRender: expect.any(Function),36 })37 );38});39it('reuses the current client api when the lib is reloaded', () => {40 jest.useFakeTimers();41 const render = jest.fn();42 const { clientApi } = start(render);43 const valueOfClientApi = window.__STORYBOOK_CLIENT_API__;44 const { clientApi: newClientApi } = start(render);45 jest.runAllTimers();46 expect(clientApi).toEqual(newClientApi);47 expect(clientApi).toEqual(valueOfClientApi);48});49it('calls render when you add a story', () => {50 jest.useFakeTimers();51 const render = jest.fn();52 const { clientApi, configApi } = start(render);53 configApi.configure(() => {54 clientApi.storiesOf('kind', {}).add('story', () => {});55 }, {});56 jest.runAllTimers();57 expect(render).toHaveBeenCalledWith(58 expect.objectContaining({ selectedKind: 'kind', selectedStory: 'story' })59 );60});61it('emits an exception and shows error when your story throws', () => {62 jest.useFakeTimers();63 const render = jest.fn();64 const { clientApi, configApi } = start(render);65 configApi.configure(() => {66 clientApi.storiesOf('kind', {}).add('story1', () => {});67 }, {});68 jest.runAllTimers();69 expect(render).not.toHaveBeenCalled();70 expect(document.body.classList.add).toHaveBeenCalledWith('sb-show-nopreview');71});72it('emits an error and shows error when your framework calls showError', () => {73 jest.useFakeTimers();74 const error = {75 title: 'Some error',76 description: 'description',77 };78 const render = jest.fn().mockImplementation(({ showError }) => {79 showError(error);80 });81 const { clientApi, configApi } = start(render);82 configApi.configure(() => {83 clientApi.storiesOf('kind', {}).add('story', () => {});84 }, {});85 jest.runAllTimers();86 expect(render).toHaveBeenCalled();87 expect(document.body.classList.add).toHaveBeenCalledWith('sb-show-errordisplay');88});89describe('STORY_INIT', () => {90 it('supports path params', () => {91 document.location = {92 pathname: 'pathname',93 search: '?path=/story/kind--story&bar=baz',94 };95 const render = jest.fn();96 const { clientApi } = start(render);97 const store = clientApi._storyStore;98 store.setSelection = jest.fn();99 store.emit(Events.STORY_INIT);100 store.emit();101 expect(store.setSelection).toHaveBeenCalledWith({ storyId: 'kind--story' });102 });103 it('supports story kind/name params', () => {104 document.location = {105 pathname: 'pathname',106 search: '?selectedKind=kind&selectedStory=story&bar=baz',107 };108 const render = jest.fn();109 const { clientApi } = start(render);110 const store = clientApi._storyStore;111 store.setSelection = jest.fn();112 store.emit(Events.STORY_INIT);113 expect(history.replaceState).toHaveBeenCalledWith({}, '', 'pathname?bar=baz&id=kind--story');114 expect(store.setSelection).toHaveBeenCalledWith({ storyId: 'kind--story' });115 });116});117describe('story filters for module exports', () => {118 it('should exclude __esModule', () => {119 expect(isExportStory('__esModule', {})).toBeFalsy();120 });121 it('should include all stories when there are no filters', () => {122 expect(isExportStory('a', {})).toBeTruthy();123 });124 it('should filter stories by arrays', () => {125 expect(isExportStory('a', { includeStories: ['a'] })).toBeTruthy();126 expect(isExportStory('a', { includeStories: [] })).toBeFalsy();127 expect(isExportStory('a', { includeStories: ['b'] })).toBeFalsy();128 expect(isExportStory('a', { excludeStories: ['a'] })).toBeFalsy();129 expect(isExportStory('a', { excludeStories: [] })).toBeTruthy();130 expect(isExportStory('a', { excludeStories: ['b'] })).toBeTruthy();131 expect(isExportStory('a', { includeStories: ['a'], excludeStories: ['a'] })).toBeFalsy();132 expect(isExportStory('a', { includeStories: [], excludeStories: [] })).toBeFalsy();133 expect(isExportStory('a', { includeStories: ['a'], excludeStories: ['b'] })).toBeTruthy();134 });135 it('should filter stories by regex', () => {136 expect(isExportStory('a', { includeStories: /a/ })).toBeTruthy();137 expect(isExportStory('a', { includeStories: /.*/ })).toBeTruthy();138 expect(isExportStory('a', { includeStories: /b/ })).toBeFalsy();139 expect(isExportStory('a', { excludeStories: /a/ })).toBeFalsy();140 expect(isExportStory('a', { excludeStories: /.*/ })).toBeFalsy();141 expect(isExportStory('a', { excludeStories: /b/ })).toBeTruthy();142 expect(isExportStory('a', { includeStories: /a/, excludeStories: ['a'] })).toBeFalsy();143 expect(isExportStory('a', { includeStories: /.*/, excludeStories: /.*/ })).toBeFalsy();144 expect(isExportStory('a', { includeStories: /a/, excludeStories: /b/ })).toBeTruthy();145 });...

Full Screen

Full Screen

testCsf.js

Source:testCsf.js Github

copy

Full Screen

1import "./preview";2import { toMatchImageSnapshot } from "jest-image-snapshot";3import puppeteer from "puppeteer";4import { sanitize } from "@storybook/csf";5import { paramCase } from "change-case";6expect.extend({ toMatchImageSnapshot });7function matches(storyKey, arrayOrRegex) {8 if (Array.isArray(arrayOrRegex)) {9 return arrayOrRegex.includes(storyKey);10 }11 return storyKey.match(arrayOrRegex);12}13const noop = () => undefined;14const asyncNoop = () => Promise.resolve(undefined);15export function testCsf(16 { default: defaultExport, ...otherExports },17 storyMeta18) {19 if (!defaultExport) {20 throw new Error("Story file not in CSF, please fix!");21 }22 const {23 args: componentArgs,24 decorators: componentDecorators = [],25 excludeStories = [],26 includeStories,27 } = defaultExport;28 let storyEntries = Object.entries(otherExports);29 if (includeStories) {30 storyEntries = storyEntries.filter(([storyKey]) =>31 matches(storyKey, includeStories)32 );33 }34 if (excludeStories) {35 storyEntries = storyEntries.filter(36 ([storyKey]) => !matches(storyKey, excludeStories)37 );38 }39 /** @type {import('@storybook/addon-storyshots-puppeteer').ImageSnapshotConfig } */40 const config = {41 storybookUrl: "http://localhost:6006",42 chromeExecutablePath:43 process.env.SB_CHROMIUM_PATH || "/usr/local/bin/chrome",44 getGotoOptions: noop,45 customizePage: asyncNoop,46 getCustomBrowser: async function () {47 // add some options "no-sandbox" to make it work properly on some Linux systems as proposed here: https://github.com/Googlechrome/puppeteer/issues/290#issuecomment-32285150748 const browser = await puppeteer.launch({49 args: [50 "--no-sandbox ",51 "--disable-setuid-sandbox",52 "--disable-dev-shm-usage",53 ],54 executablePath: config.chromeExecutablePath,55 });56 return browser;57 },58 setupTimeout: 15000,59 testTimeout: 15000,60 getMatchOptions: noop,61 // We consider taking the full page is a reasonable default.62 getScreenshotOptions: () => ({ fullPage: true, encoding: "base64" }),63 beforeScreenshot: noop,64 afterScreenshot: noop,65 suite: "storyshots",66 ...global.imageSnapshotOpts,67 };68 describe(config.suite, () => {69 const { id: firstStoryId } = storyMeta[Object.keys(storyMeta)[0]];70 const [kind] = firstStoryId.split("--");71 describe(kind, () => {72 // Reuse browser and page for each storybook file73 let browser;74 let page;75 beforeAll(async () => {76 browser = await config.getCustomBrowser();77 page = await browser.newPage();78 });79 afterAll(async () => {80 await page.close();81 await browser.close();82 });83 storyEntries84 .filter(85 ([exportName]) =>86 !(Array.isArray(excludeStories)87 ? excludeStories.includes(exportName)88 : exportName.matches(excludeStories))89 )90 .forEach(([exportName, exported]) => {91 const name = exported.story?.name || exported.storyName || exportName;92 it(name, async () => {93 expect.hasAssertions();94 const { id } = storyMeta[exportName];95 const [, story] = id.split("--");96 const options = {97 context: {98 kind,99 story,100 parameters: {},101 },102 url: `${config.storybookUrl}iframe.html?id=${id}`,103 };104 await page.goto(options.url, config.getGotoOptions(options));105 const element = await config.beforeScreenshot(page, options);106 const image = await (element || page).screenshot(107 config.getScreenshotOptions(options)108 );109 await config.afterScreenshot({ image, context: options.context });110 expect(image).toMatchImageSnapshot(config.getMatchOptions(options));111 });112 });113 });114 });...

Full Screen

Full Screen

storybook.ts

Source:storybook.ts Github

copy

Full Screen

1// eslint-disable-next-line import/no-extraneous-dependencies2import { Meta } from '@storybook/html'3export const defineStories = (meta: Meta) => {4 const excludeName = '$$registrations'5 return {6 ...meta,7 excludeStories:8 meta.excludeStories instanceof Array && meta.excludeStories.length9 ? [...meta.excludeStories, excludeName]10 : meta.excludeStories instanceof RegExp11 ? new RegExp(`${excludeName}|${meta.excludeStories}`)12 : [excludeName],13 }...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1import { configure } from '@storybook/react';2import { setOptions } from '@storybook/addon-options';3const req = require.context('../src', true, /\.story\.js$/);4function loadStories() {5 req.keys().forEach(filename => req(filename));6}7setOptions({

Full Screen

Using AI Code Generation

copy

Full Screen

1import { configure, addDecorator } from '@storybook/react';2import { withInfo } from '@storybook/addon-info';3import { excludeStories } from 'storybook-root';4addDecorator(withInfo);5const req = require.context('../src', true, /.stories.js$/);6function loadStories() {7 req.keys().forEach(filename => {8 if (excludeStories(filename)) {9 return;10 }11 req(filename);12 });13}14configure(loadStories, module);15import path from 'path';16const rootPath = path.join(__dirname, '../');17export const excludeStories = filename => {18 if (filename.indexOf(rootPath) === 0) {19 return true;20 }21 return false;22};

Full Screen

Using AI Code Generation

copy

Full Screen

1const req = require.context('../src', true, /\.stories\.js$/);2function loadStories() {3 req.keys().forEach(filename => req(filename));4}5module.exports = {6};7module.exports = {8};

Full Screen

Using AI Code Generation

copy

Full Screen

1import { configure } from '@storybook/react';2import { excludeStories } from 'storybook-root';3const req = require.context('../src/components', true, /\.stories\.js$/);4function loadStories() {5 req.keys().forEach(filename => excludeStories(filename, req));6}7configure(loadStories, module);8import { configure } from '@storybook/react';9import { excludeStories } from 'storybook-root';10const req = require.context('../src/components', true, /\.stories\.js$/);11function loadStories() {12 req.keys().forEach(filename => excludeStories(filename, req));13}14configure(loadStories, module);15import { configure } from '@storybook/react';16const req = require.context('../src/components', true, /\.stories\.js$/);17function loadStories() {18 req.keys().forEach(filename => req(filename));19}20configure(loadStories, module);21import { configure } from '@storybook/react';22const req = require.context('../src/components', true, /\.stories\.js$/);23function loadStories() {24 req.keys().forEach(filename => req(filename));25}26configure(loadStories, module);27import { configure } from '@storybook/react';28import { excludeStories } from 'storybook-root';29const req = require.context('../src/components', true, /\.stories\.js$/);30function loadStories() {31 req.keys().forEach(filename => excludeStories(filename, req));32}33configure(loadStories, module);34import { configure } from '@storybook/react';35import { excludeStories } from 'storybook-root';36const req = require.context('../src/components', true, /\.stories\.js$/);37function loadStories() {38 req.keys().forEach(filename => excludeStories(filename, req));39}40configure(loadStories, module);41import { configure } from '@storybook/react';42import { excludeStories } from 'storybook-root';43const req = require.context('../src/components', true, /\.stories\.js$/);44function loadStories() {45 req.keys().forEach(filename => excludeStories(filename, req));46}47configure(loadStories, module);48import { configure } from '@storybook/react';49import { exclude

Full Screen

Using AI Code Generation

copy

Full Screen

1import React from 'react';2import { storiesOf } from '@storybook/react';3import { excludeStories } from './storybook-root-config';4storiesOf('Button', module)5 .add('with text', () => <button>Click me</button>)6 .add('with emoji', () => <button>😀 😎 👍 💯</button>)7 .add('exclude', () => <button>exclude</button>)8 .add('exclude2', () => <button>exclude2</button>)9 .add('exclude3', () => <button>exclude3</button>)10 .add('exclude4', () => <button>exclude4</button>)11 .add('exclude5', () => <button>exclude5</button>)12 .add('exclude6', () => <button>exclude6</button>)13 .add('exclude7', () => <button>exclude7</button>)14 .add('exclude8', () => <button>exclude8</button>)15 .add('exclude9', () => <button>exclude9</button>)16 .add('exclude10', () => <button>exclude10</button>)17 .add('exclude11', () => <button>exclude11</button>)18 .add('exclude12', () => <button>exclude12</button>)19 .add('exclude13', () => <button>exclude13</button>)20 .add('exclude14', () => <button>exclude14</button>)21 .add('exclude15', () => <button>exclude15</button>)22 .add('exclude16', () => <button>exclude16</button>)23 .add('exclude17', () => <button>exclude17</button>)24 .add('exclude18', () => <button>exclude18</button>)25 .add('exclude19', () => <button>exclude19</button>)26 .add('exclude20', () => <button>exclude20</button>)27 .add('exclude21', () => <button>exclude21</button>)28 .add('exclude22', () => <button>exclude22</button>)29 .add('exclude23', () => <button>exclude23</button>)30 .add('exclude24', () => <button>exclude24</button>)31 .add('exclude25', () => <button>exclude25</button>)

Full Screen

Using AI Code Generation

copy

Full Screen

1import { configure } from '@storybook/react';2const req = require.context('../src/components', true, /\.stories\.tsx$/);3function loadStories() {4 req.keys().forEach(filename => req(filename));5}6];7configure(loadStories, module, {8 storySort: (a, b) => {9 const aKind = a[1].kind;10 const bKind = b[1].kind;11 const aIndex = excludeStories.indexOf(aKind);12 const bIndex = excludeStories.indexOf(bKind);13 if (aIndex < 0 && bIndex < 0) {14 return aKind.localeCompare(bKind);15 } else if (aIndex < 0 && bIndex >= 0) {16 return -1;17 } else if (aIndex >= 0 && bIndex < 0) {18 return 1;19 } else {20 return aIndex - bIndex;21 }22 },23});24import { configure, addDecorator } from '@storybook/react';25import { withInfo } from '@storybook/addon-info';26import { withKnobs } from '@storybook/addon-knobs';27const req = require.context('../src/components', true, /\.stories\.tsx$/);28function loadStories() {29 req.keys().forEach(filename => req(filename));30}31];32addDecorator(withInfo);33addDecorator(withKnobs);34configure(loadStories, module, {35 storySort: (a, b) => {36 const aKind = a[1].kind;37 const bKind = b[1].kind;38 const aIndex = excludeStories.indexOf(aKind);39 const bIndex = excludeStories.indexOf(bKind);40 if (aIndex < 0 && bIndex < 0) {41 return aKind.localeCompare(bKind);42 } else if (aIndex < 0 && bIndex >= 0) {43 return -1;44 } else if (aIndex >= 0 && b

Full Screen

Using AI Code Generation

copy

Full Screen

1import { configure, addParameters } from '@storybook/react';2import { withTests } from '@storybook/addon-jest';3import results from '../.jest-test-results.json';4import { excludeStories } from './storybook-root-config';5addParameters({6 jest: [withTests({ results })],7});8configure(require.context('../src', true, /\.stories\.js$/), module);9excludeStories();10import { configure, addParameters } from '@storybook/react';11import { withTests } from '@storybook/addon-jest';12import results from '../.jest-test-results.json';13import { excludeStories } from './storybook-root-config';14addParameters({15 jest: [withTests({ results })],16});17configure(require.context('../src', true, /\.stories\.js$/), module);18excludeStories();19export const excludeStories = () => {20 const req = require.context('../src', true, /\.stories\.js$/);21 const stories = req.keys();22 const storyName = stories[0].split('/')[2].split('.')[0];23 const story = stories[0];24 console.log('story', story);25 console.log('storyName', storyName);26 stories.forEach((story) => {27 const storyName = story.split('/')[2].split('.')[0];28 console.log('storyName', storyName);29 module.exports[storyName] = null;30 });31};32export default {33};34export const Primary = () => <Button>Primary</Button>;35export const Secondary = () => <Button>Secondary</Button>;36export const Large = () => <Button size="large">Large</Button>;37export const Small = () => <Button size="small">Small</Button>;38export const PrimaryLarge = () => (39);40export const PrimarySmall = () => (41);42export const SecondaryLarge = () => (43);44export const SecondarySmall = () => (

Full Screen

Using AI Code Generation

copy

Full Screen

1import { configure } from '@storybook/react';2configure(require.context('../src', true, /\.stories\.js$/), module);3import { configure, addDecorator } from '@storybook/react';4import { withInfo } from '@storybook/addon-info';5import { withKnobs } from '@storybook/addon-knobs';6import { withA11y } from '@storybook/addon-a11y';7import { withTests } from '@storybook/addon-jest';8import results from '../.jest-test-results.json';9const req = require.context('../src', true, /\.stories\.js$/);10function loadStories() {11 req.keys().forEach(filename => req(filename));12}13];14excludedStories.forEach(excludedStory => {15 const index = req.keys().indexOf(excludedStory);16 if (index > -1) {17 req.keys().splice(index, 1);18 }19});20addDecorator(withInfo);21addDecorator(withKnobs);22addDecorator(withA11y);23addDecorator(withTests({ results }));24configure(loadStories, module);

Full Screen

Using AI Code Generation

copy

Full Screen

1import { excludeStories } from './storybook-root-config.js';2const req = require.context('../src/components', true, /\.stories\.js$/);3excludeStories(req, module);4const excludeStories = (req, module) => {5 req.keys().forEach(filename => {6 if (filename.indexOf('stories') >= 0) {7 req(filename);8 }9 });10};

Full Screen

Using AI Code Generation

copy

Full Screen

1import { excludeStories } from './storybook-root-config'2import { storiesOf } from '@storybook/react'3const stories = storiesOf('test', module)4stories.add('test', () => <div>test</div>)5stories.add('test2', () => <div>test2</div>)6excludeStories(stories)7export const excludeStories = (stories) => {8 stories.excludeStories(/test/)9}10Module build failed (from ./node_modules/babel-loader/lib/index.js):

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run storybook-root automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful