How to use invalidStoryTypes method in storybook-root

Best JavaScript code snippet using storybook-root

client_api.js

Source:client_api.js Github

copy

Full Screen

1function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }2/* eslint no-underscore-dangle: 0 */3import deprecate from 'util-deprecate';4import dedent from 'ts-dedent';5import { logger } from '@storybook/client-logger';6import { toId } from '@storybook/csf';7import { applyHooks } from './hooks';8import { defaultDecorateStory } from './decorators'; // ClientApi (and StoreStore) are really singletons. However they are not created until the9// relevant framework instanciates them via `start.js`. The good news is this happens right away.10let singleton;11const addDecoratorDeprecationWarning = deprecate(() => {}, `\`addDecorator\` is deprecated, and will be removed in Storybook 7.0.12Instead, use \`export const decorators = [];\` in your \`preview.js\`.13Read more at https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#deprecated-addparameters-and-adddecorator).`);14export const addDecorator = (decorator, deprecationWarning = true) => {15 if (!singleton) throw new Error(`Singleton client API not yet initialized, cannot call addDecorator`);16 if (deprecationWarning) addDecoratorDeprecationWarning();17 singleton.addDecorator(decorator);18};19const addParametersDeprecationWarning = deprecate(() => {}, `\`addParameters\` is deprecated, and will be removed in Storybook 7.0.20Instead, use \`export const parameters = {};\` in your \`preview.js\`.21Read more at https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#deprecated-addparameters-and-adddecorator).`);22export const addParameters = (parameters, deprecationWarning = true) => {23 if (!singleton) throw new Error(`Singleton client API not yet initialized, cannot call addParameters`);24 if (deprecationWarning) addParametersDeprecationWarning();25 singleton.addParameters(parameters);26};27const addLoaderDeprecationWarning = deprecate(() => {}, `\`addLoader\` is deprecated, and will be removed in Storybook 7.0.28Instead, use \`export const loaders = [];\` in your \`preview.js\`.29Read more at https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#deprecated-addparameters-and-adddecorator).`);30export const addLoader = (loader, deprecationWarning = true) => {31 if (!singleton) throw new Error(`Singleton client API not yet initialized, cannot call addParameters`);32 if (deprecationWarning) addLoaderDeprecationWarning();33 singleton.addLoader(loader);34};35export const addArgsEnhancer = enhancer => {36 if (!singleton) throw new Error(`Singleton client API not yet initialized, cannot call addArgsEnhancer`);37 singleton.addArgsEnhancer(enhancer);38};39export const addArgTypesEnhancer = enhancer => {40 if (!singleton) throw new Error(`Singleton client API not yet initialized, cannot call addArgTypesEnhancer`);41 singleton.addArgTypesEnhancer(enhancer);42};43export const getGlobalRender = () => {44 if (!singleton) throw new Error(`Singleton client API not yet initialized, cannot call getGlobalRender`);45 return singleton.globalRender;46};47export const setGlobalRender = render => {48 if (!singleton) throw new Error(`Singleton client API not yet initialized, cannot call setGobalRender`);49 singleton.globalRender = render;50};51const invalidStoryTypes = new Set(['string', 'number', 'boolean', 'symbol']);52export default class ClientApi {53 // React Native Fast refresh doesn't allow multiple dispose calls54 constructor({55 storyStore,56 decorateStory = defaultDecorateStory,57 noStoryModuleAddMethodHotDispose58 }) {59 this._storyStore = void 0;60 this._addons = void 0;61 this._decorateStory = void 0;62 this._globalRender = void 0;63 this._noStoryModuleAddMethodHotDispose = void 0;64 this.setAddon = deprecate(addon => {65 this._addons = Object.assign({}, this._addons, addon);66 }, dedent`67 \`setAddon\` is deprecated and will be removed in Storybook 7.0.68 https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#deprecated-setaddon69 `);70 this.addDecorator = decorator => {71 this._storyStore.addGlobalMetadata({72 decorators: [decorator]73 });74 };75 this.clearDecorators = deprecate(() => {76 this._storyStore.clearGlobalDecorators();77 }, dedent`78 \`clearDecorators\` is deprecated and will be removed in Storybook 7.0.79 https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#deprecated-cleardecorators80 `);81 this.addParameters = parameters => {82 this._storyStore.addGlobalMetadata({83 parameters84 });85 };86 this.addLoader = loader => {87 this._storyStore.addGlobalMetadata({88 loaders: [loader]89 });90 };91 this.addArgsEnhancer = enhancer => {92 this._storyStore.addArgsEnhancer(enhancer);93 };94 this.addArgTypesEnhancer = enhancer => {95 this._storyStore.addArgTypesEnhancer(enhancer);96 };97 this.storiesOf = (kind, m) => {98 if (!kind && typeof kind !== 'string') {99 throw new Error('Invalid or missing kind provided for stories, should be a string');100 }101 if (!m) {102 logger.warn(`Missing 'module' parameter for story with a kind of '${kind}'. It will break your HMR`);103 }104 if (m) {105 const proto = Object.getPrototypeOf(m);106 if (proto.exports && proto.exports.default) {107 // FIXME: throw an error in SB6.0108 logger.error(`Illegal mix of CSF default export and storiesOf calls in a single file: ${proto.i}`);109 }110 }111 if (m && m.hot && m.hot.dispose) {112 m.hot.dispose(() => {113 const {114 _storyStore115 } = this; // If HMR dispose happens in a story file, we know that HMR will pass up to the configuration file (preview.js)116 // and be handled by the HMR.allow in config_api, leading to a re-run of configuration.117 // So configuration is about to happen--we can skip the safety check.118 _storyStore.removeStoryKind(kind, {119 allowUnsafe: true120 });121 });122 }123 let hasAdded = false;124 const api = {125 kind: kind.toString(),126 add: () => api,127 addDecorator: () => api,128 addLoader: () => api,129 addParameters: () => api130 }; // apply addons131 Object.keys(this._addons).forEach(name => {132 const addon = this._addons[name];133 api[name] = (...args) => {134 addon.apply(api, args);135 return api;136 };137 });138 api.add = (storyName, storyFn, parameters = {}) => {139 hasAdded = true;140 const id = parameters.__id || toId(kind, storyName);141 if (typeof storyName !== 'string') {142 throw new Error(`Invalid or missing storyName provided for a "${kind}" story.`);143 }144 if (!storyFn || Array.isArray(storyFn) || invalidStoryTypes.has(typeof storyFn)) {145 throw new Error(`Cannot load story "${storyName}" in "${kind}" due to invalid format. Storybook expected a function/object but received ${typeof storyFn} instead.`);146 }147 if (!this._noStoryModuleAddMethodHotDispose && m && m.hot && m.hot.dispose) {148 m.hot.dispose(() => {149 const {150 _storyStore151 } = this; // See note about allowUnsafe above152 _storyStore.remove(id, {153 allowUnsafe: true154 });155 });156 }157 const fileName = m && m.id ? `${m.id}` : undefined;158 const {159 decorators,160 loaders161 } = parameters,162 storyParameters = _objectWithoutPropertiesLoose(parameters, ["decorators", "loaders"]);163 this._storyStore.addStory({164 id,165 kind,166 name: storyName,167 storyFn,168 parameters: Object.assign({169 fileName170 }, storyParameters),171 decorators,172 loaders173 }, {174 applyDecorators: applyHooks(this._decorateStory)175 });176 return api;177 };178 api.addDecorator = decorator => {179 if (hasAdded) throw new Error(`You cannot add a decorator after the first story for a kind.180Read more here: https://github.com/storybookjs/storybook/blob/master/MIGRATION.md#can-no-longer-add-decoratorsparameters-after-stories`);181 this._storyStore.addKindMetadata(kind, {182 decorators: [decorator]183 });184 return api;185 };186 api.addLoader = loader => {187 if (hasAdded) throw new Error(`You cannot add a loader after the first story for a kind.`);188 this._storyStore.addKindMetadata(kind, {189 loaders: [loader]190 });191 return api;192 };193 api.addParameters = parameters => {194 if (hasAdded) throw new Error(`You cannot add parameters after the first story for a kind.195Read more here: https://github.com/storybookjs/storybook/blob/master/MIGRATION.md#can-no-longer-add-decoratorsparameters-after-stories`);196 this._storyStore.addKindMetadata(kind, {197 parameters198 });199 return api;200 };201 return api;202 };203 this.getStorybook = () => this._storyStore.getStorybook();204 this.raw = () => this._storyStore.raw();205 this.store = () => this._storyStore;206 this._storyStore = storyStore;207 this._addons = {};208 this._noStoryModuleAddMethodHotDispose = noStoryModuleAddMethodHotDispose || false;209 this._decorateStory = decorateStory;210 if (!storyStore) throw new Error('storyStore is required');211 singleton = this;212 }213 get globalRender() {214 return this._globalRender;215 }216 set globalRender(render) {217 this._globalRender = render;218 } // what are the occasions that "m" is a boolean vs an obj...

Full Screen

Full Screen

utils.ts

Source:utils.ts Github

copy

Full Screen

1import { NgModule } from '@angular/core';2import {3 ICollection,4 StoryFnAngularReturnType,5} from '@storybook/angular/dist/ts3.9/client/preview/types';6import { Subject } from 'rxjs';7import { Parameters } from '@storybook/angular/types-6-0';8import { storyPropsProvider } from '@storybook/angular/dist/ts3.9/client/preview/angular-beta/StorybookProvider';9import { isComponentAlreadyDeclaredInModules } from '@storybook/angular/dist/ts3.9/client/preview/angular-beta/utils/NgModulesAnalyzer';10import { isDeclarable } from '@storybook/angular/dist/ts3.9/client/preview/angular-beta/utils/NgComponentAnalyzer';11import { createStorybookWrapperComponent } from '@storybook/angular/dist/ts3.9/client/preview/angular-beta/StorybookWrapperComponent';12import { computesTemplateFromComponent } from '@storybook/angular/dist/ts3.9/client/preview/angular-beta/ComputesTemplateFromComponent';13import { BrowserModule } from '@angular/platform-browser';1415const invalidStoryTypes = new Set(['string', 'number', 'boolean', 'symbol']);1617export const isInvalidStory = (story?: any) =>18 !story || Array.isArray(story) || invalidStoryTypes.has(typeof story);1920// This can probably be avoided by making changes to this method in `@storybook/angular`.21// Without reimplementing this here:22// - The ComponentToInject would unnecessarily be added to the NgModule's bootstrap array.23// - There would be a deprecated warning, because the composed story is currently adding the24// component from Meta to StoryFnAngularReturnType.25export const getStorybookModuleMetadata = (26 {27 storyFnAngular,28 parameters,29 targetSelector,30 }: {31 storyFnAngular: StoryFnAngularReturnType;32 parameters: Parameters;33 targetSelector: string;34 },35 storyProps$: Subject<ICollection | undefined>36): NgModule => {37 const {38 component: storyComponent,39 props,40 styles,41 moduleMetadata = {},42 } = storyFnAngular;43 let { template } = storyFnAngular;4445 const component = storyComponent ?? parameters.component;4647 if (hasNoTemplate(template) && component) {48 template = computesTemplateFromComponent(component, props, '');49 }5051 /**52 * Create a component that wraps generated template and gives it props53 */54 const ComponentToInject = createStorybookWrapperComponent(55 targetSelector,56 template!,57 component,58 styles!,59 props,60 );6162 // Look recursively (deep) if the component is not already declared by an import module63 const requiresComponentDeclaration =64 isDeclarable(component) &&65 !isComponentAlreadyDeclaredInModules(66 component,67 moduleMetadata.declarations!,68 moduleMetadata.imports!,69 );7071 return {72 declarations: [73 ...(requiresComponentDeclaration ? [component] : []),74 ComponentToInject,75 ...(moduleMetadata.declarations ?? []),76 ],77 imports: [BrowserModule, ...(moduleMetadata.imports ?? [])],78 providers: [79 storyPropsProvider(storyProps$),80 ...(moduleMetadata.providers ?? []),81 ],82 entryComponents: [...(moduleMetadata.entryComponents ?? [])],83 schemas: [...(moduleMetadata.schemas ?? [])],84 };85};8687function hasNoTemplate(88 template: string | null | undefined89): template is undefined {90 return template === null || template === undefined; ...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1import { invalidStoryTypes } from 'storybook-root';2import { invalidStoryTypes } from 'storybook-root';3import { invalidStoryTypes } from 'storybook-root';4import { invalidStoryTypes } from 'storybook-root';5import { invalidStoryTypes } from 'storybook-root';6import { invalidStoryTypes } from 'storybook-root';7import { invalidStoryTypes } from 'storybook-root';8import { invalidStoryTypes } from 'storybook-root';9import { invalidStoryTypes } from 'storybook-root';10import { invalidStoryTypes } from 'storybook-root';11import { invalidStoryTypes } from 'storybook-root';12import { invalidStoryTypes } from 'storybook-root';13import { invalidStoryTypes } from 'storybook-root';14import { invalidStoryTypes } from 'storybook-root';15import { invalidStoryTypes } from 'storybook-root';16import { invalidStoryTypes } from 'storybook-root';17import { invalidStoryTypes } from 'storybook-root';18import { invalidStoryTypes } from 'storybook-root';19import { invalidStoryTypes } from 'storybook-root';

Full Screen

Using AI Code Generation

copy

Full Screen

1import {invalidStoryTypes} from 'storybook-root'2console.log(invalidStoryTypes)3import {invalidStoryTypes} from 'storybook-root'4console.log(invalidStoryTypes)5import {invalidStoryTypes} from 'storybook-root'6console.log(invalidStoryTypes)7import {invalidStoryTypes} from 'storybook-root'8console.log(invalidStoryTypes)9import {invalidStoryTypes} from 'storybook-root'10console.log(invalidStoryTypes)11import {invalidStoryTypes} from 'storybook-root'12console.log(invalidStoryTypes)13import {invalidStoryTypes} from 'storybook-root'14console.log(invalidStoryTypes)15import {invalidStoryTypes} from 'storybook-root'16console.log(invalidStoryTypes)17import {invalidStoryTypes} from 'storybook-root'18console.log(invalidStoryTypes)19import {invalidStoryTypes} from 'storybook-root'20console.log(invalidStoryTypes)21import {invalidStoryTypes} from 'storybook-root'22console.log(invalidStoryTypes)23import {invalidStoryTypes} from 'storybook-root'24console.log(invalidStoryTypes)

Full Screen

Using AI Code Generation

copy

Full Screen

1const { invalidStoryTypes } = require('storybook-root');2const storyTypes = ['a', 'b', 'c'];3const invalidTypes = invalidStoryTypes(storyTypes);4module.exports = {5 {6 options: {7 },8 },9};

Full Screen

Using AI Code Generation

copy

Full Screen

1import { invalidStoryTypes } from 'storybook-root';2if (invalidStoryTypes()) {3 throw new Error('Invalid Story Types');4}5export const invalidStoryTypes = () => {6 const storyTypes = ['a', 'b', 'c'];7 const invalidTypes = storyTypes.filter(type => !['a', 'b'].includes(type));8 return invalidTypes.length > 0;9};10"scripts": {11}12{13 "scripts": {14 },15}

Full Screen

Using AI Code Generation

copy

Full Screen

1import { invalidStoryTypes } from "storybook-root";2import { invalidStoryTypes } from "storybook-root";3import { invalidStoryTypes } from "storybook-root";4import { invalidStoryTypes } from "storybook-root";5import { invalidStoryTypes } from "storybook-root";6import { invalidStoryTypes } from "storybook-root";7import { invalidStoryTypes } from "storybook-root";

Full Screen

Using AI Code Generation

copy

Full Screen

1import { invalidStoryTypes } from 'storybook-root';2console.log(invalidStoryTypes);3export const invalidStoryTypes = ['story'];4import { invalidStoryTypes } from '../index';5console.log(invalidStoryTypes);6import { invalidStoryTypes } from '../index';7console.log(invalidStoryTypes);8import { invalidStoryTypes } from '../index';9console.log(invalidStoryTypes);10import { invalidStoryTypes } from '../index';11console.log(invalidStoryTypes);12import { invalidStoryTypes } from '../index';13console.log(invalidStoryTypes);14import { invalidStoryTypes } from '../index';15console.log(invalidStoryTypes);16import { invalidStoryTypes } from '../index';17console.log(invalidStoryTypes);18import { invalidStoryTypes } from '../index';19console.log(invalidStoryTypes);20import { invalidStoryTypes } from '../index';21console.log(invalidStoryTypes);22import { invalidStoryTypes } from '../index';23console.log(invalidStoryTypes);24import { invalidStoryTypes } from '../index';25console.log(invalidStoryTypes);

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