How to use builderContext method in storybook-root

Best JavaScript code snippet using storybook-root

SkillInfoBlockBuilder.test.ts

Source:SkillInfoBlockBuilder.test.ts Github

copy

Full Screen

1import { SkillInfoBlockBuilder } from "../../../src/blocks/builders/SkillInfoBlockBuilder";2import * as _ from "lodash";3import { expect } from "chai";4import "mocha";5import {6 AlexaBuilderContext,7 AlexaDialogContext,8 AlexaEvent,9 Locale,10} from "../../../src/models";11import { resource_utils, paths } from "../../../src/util/ResourceUtil";12import { context_util } from "../../../src/util/ContextUtil";13import { launchRequest } from "../../data/launchRequest";14import { sum } from "lodash";15const context: AlexaDialogContext = {16 currentResponse: {17 version: "1.0",18 response: {},19 },20 platformState: {21 currentStateName: "",22 globalState: {},23 },24};25const event: AlexaEvent = {26 currentRequest: launchRequest,27};28describe("SkillInfoBlockBuilder", () => {29 describe("InvocationName", () => {30 it("should do nothing if name or invocation name are not set", async () => {31 let builderContext: AlexaBuilderContext = JSON.parse("{}");32 let dialogContext: AlexaDialogContext = JSON.parse("{}");33 let event: AlexaEvent = JSON.parse("{}");34 let sib = new SkillInfoBlockBuilder();35 let b = sib.build();36 b.execute(dialogContext, event);37 b.build(builderContext);38 expect(JSON.stringify(dialogContext)).equals("{}");39 expect(JSON.stringify(builderContext)).equals("{}");40 expect(JSON.stringify(event)).equals("{}");41 });42 it("should set invocation name when passed and both locales and im are not in context", async () => {43 let builderContext: AlexaBuilderContext = {44 currentLocales: [],45 resources: { resourceMap: {} },46 };47 let invocationName = "foo";48 let sib = new SkillInfoBlockBuilder();49 let b = sib.invocationName(invocationName).build();50 b.build(builderContext);51 expect(builderContext).to.not.be.undefined;52 expect(context_util.getIMString(builderContext, Locale.en_US)).to.not.be.undefined;53 expect(context_util.getIM(builderContext, Locale.en_US).interactionModel).to.not.be54 .undefined;55 expect(56 context_util.getIM(builderContext, Locale.en_US).interactionModel?.languageModel57 ).to.not.be.undefined;58 expect(59 context_util.getIM(builderContext, Locale.en_US).interactionModel?.languageModel60 ?.invocationName61 ).equals(invocationName);62 // exactly one resource is generated i.e. IM in en_US63 expect(Object.keys(builderContext.resources.resourceMap).length).equals(1);64 });65 it("should set invocation name when passed and locales present in context, im is not", async () => {66 let builderContext: AlexaBuilderContext = {67 currentLocales: [Locale.en_US, Locale.en_CA],68 resources: { resourceMap: {} },69 };70 let invocationName = "foo";71 let sib = new SkillInfoBlockBuilder();72 let b = sib.invocationName(invocationName).build();73 b.build(builderContext);74 expect(builderContext).to.not.be.undefined;75 expect(context_util.getIMString(builderContext, Locale.en_US)).to.not.be.undefined;76 expect(context_util.getIM(builderContext, Locale.en_US).interactionModel).to.not.be77 .undefined;78 expect(79 context_util.getIM(builderContext, Locale.en_US).interactionModel?.languageModel80 ).to.not.be.undefined;81 expect(82 context_util.getIM(builderContext, Locale.en_US).interactionModel?.languageModel83 ?.invocationName84 ).equals(invocationName);85 expect(context_util.getIMString(builderContext, Locale.en_CA)).to.not.be.undefined;86 expect(context_util.getIM(builderContext, Locale.en_CA).interactionModel).to.not.be87 .undefined;88 expect(89 context_util.getIM(builderContext, Locale.en_CA).interactionModel?.languageModel90 ).to.not.be.undefined;91 expect(92 context_util.getIM(builderContext, Locale.en_CA).interactionModel?.languageModel93 ?.invocationName94 ).equals(invocationName);95 });96 it("should set invocation name when passed and locales present in context and im is also present", async () => {97 let builderContext: AlexaBuilderContext = {98 currentLocales: [Locale.en_US, Locale.en_CA],99 resources: {100 resourceMap: {101 [paths.getInteractionModelPath(Locale.en_US)]: JSON.stringify(102 resource_utils.getDefaultInteractionModel()103 ),104 },105 },106 };107 let invocationName = "foo";108 let sib = new SkillInfoBlockBuilder();109 let b = sib.invocationName(invocationName).build();110 b.build(builderContext);111 expect(builderContext).to.not.be.undefined;112 expect(context_util.getIMString(builderContext, Locale.en_US)).to.not.be.undefined;113 expect(context_util.getIM(builderContext, Locale.en_US).interactionModel).to.not.be114 .undefined;115 expect(116 context_util.getIM(builderContext, Locale.en_US).interactionModel?.languageModel117 ).to.not.be.undefined;118 expect(119 context_util.getIM(builderContext, Locale.en_US).interactionModel?.languageModel120 ?.invocationName121 ).equals(invocationName);122 expect(context_util.getIMString(builderContext, Locale.en_CA)).to.not.be.undefined;123 expect(context_util.getIM(builderContext, Locale.en_CA).interactionModel).to.not.be124 .undefined;125 expect(126 context_util.getIM(builderContext, Locale.en_CA).interactionModel?.languageModel127 ).to.not.be.undefined;128 expect(129 context_util.getIM(builderContext, Locale.en_CA).interactionModel?.languageModel130 ?.invocationName131 ).equals(invocationName);132 });133 });134 describe("Skill Name", () => {135 it("should set skill name when passed and both locales and manifest are not in the builder context", async () => {136 let builderContext: AlexaBuilderContext = {137 currentLocales: [],138 resources: { resourceMap: {} },139 };140 let name = "foo";141 let sib = new SkillInfoBlockBuilder();142 let b = sib.name(name).build();143 b.build(builderContext);144 expect(builderContext).to.not.be.undefined;145 expect(context_util.getSkillManifestString(builderContext)).to.not.be.undefined;146 expect(context_util.getSkillManifest(builderContext).manifest).to.not.be.undefined;147 expect(148 context_util.getSkillManifest(builderContext).manifest?.publishingInformation149 ).to.not.be.undefined;150 let publishInfoLocales = context_util.getSkillManifest(builderContext).manifest151 ?.publishingInformation?.locales;152 expect(publishInfoLocales).to.not.be.undefined;153 if (publishInfoLocales) {154 expect(publishInfoLocales[Locale.en_US]).to.not.be.undefined;155 expect(publishInfoLocales[Locale.en_US].name).equals(name);156 // exactly one locale is present in the skill manifest i.e. en_US157 expect(Object.keys(publishInfoLocales).length).equals(1);158 }159 });160 it("should set skill name when passed and locales present in context, manifest is not", async () => {161 let builderContext: AlexaBuilderContext = {162 currentLocales: [Locale.en_US, Locale.en_CA],163 resources: { resourceMap: {} },164 };165 let name = "foo";166 let sib = new SkillInfoBlockBuilder();167 let b = sib.name(name).build();168 b.build(builderContext);169 expect(builderContext).to.not.be.undefined;170 expect(context_util.getSkillManifestString(builderContext)).to.not.be.undefined;171 expect(context_util.getSkillManifest(builderContext).manifest).to.not.be.undefined;172 expect(173 context_util.getSkillManifest(builderContext).manifest?.publishingInformation174 ).to.not.be.undefined;175 let publishInfoLocales = context_util.getSkillManifest(builderContext).manifest176 ?.publishingInformation?.locales;177 expect(publishInfoLocales).to.not.be.undefined;178 if (publishInfoLocales) {179 expect(publishInfoLocales[Locale.en_US]).to.not.be.undefined;180 expect(publishInfoLocales[Locale.en_US].name).equals(name);181 expect(publishInfoLocales[Locale.en_CA]).to.not.be.undefined;182 expect(publishInfoLocales[Locale.en_CA].name).equals(name);183 }184 });185 it("should set skill name when passed and locales present in context, manifest is present", async () => {186 let builderContext: AlexaBuilderContext = {187 currentLocales: [Locale.en_US, Locale.en_CA],188 resources: {189 resourceMap: {190 [paths.getSkillManifestPath()]: JSON.stringify(191 resource_utils.getDefaultSkillManifest()192 ),193 },194 },195 };196 let name = "foo";197 let sib = new SkillInfoBlockBuilder();198 let b = sib.name(name).build();199 b.build(builderContext);200 expect(builderContext).to.not.be.undefined;201 expect(context_util.getSkillManifestString(builderContext)).to.not.be.undefined;202 expect(context_util.getSkillManifest(builderContext).manifest).to.not.be.undefined;203 expect(204 context_util.getSkillManifest(builderContext).manifest?.publishingInformation205 ).to.not.be.undefined;206 let publishInfoLocales = context_util.getSkillManifest(builderContext).manifest207 ?.publishingInformation?.locales;208 expect(publishInfoLocales).to.not.be.undefined;209 if (publishInfoLocales) {210 expect(publishInfoLocales[Locale.en_US]).to.not.be.undefined;211 expect(publishInfoLocales[Locale.en_US].name).equals(name);212 expect(publishInfoLocales[Locale.en_CA]).to.not.be.undefined;213 expect(publishInfoLocales[Locale.en_CA].name).equals(name);214 }215 });216 });217 describe("Publishing Information", () => {218 it("should set skill publishing information", async () => {219 let builderContext: AlexaBuilderContext = {220 currentLocales: [],221 resources: { resourceMap: {} },222 };223 let name = "foo";224 let description = "description";225 let examplePhrases = ["ex1", "ex2", "ex3"];226 let smallIcon = "http://small";227 let largeIcon = "http://large";228 let keywords = ["kwd1", "kwd2"];229 let summary = "summary";230 let updatesDescription = "updatesDescription";231 let sib = new SkillInfoBlockBuilder();232 let b = sib233 .name(name)234 .description(description)235 .examplePhrases(examplePhrases)236 .icons(smallIcon, largeIcon)237 .keywords(keywords)238 .summary(summary)239 .updatesDescription(updatesDescription)240 .build();241 b.build(builderContext);242 expect(builderContext).to.not.be.undefined;243 expect(context_util.getSkillManifestString(builderContext)).to.not.be.undefined;244 expect(context_util.getSkillManifest(builderContext).manifest).to.not.be.undefined;245 expect(246 context_util.getSkillManifest(builderContext).manifest?.publishingInformation247 ).to.not.be.undefined;248 let publishInfoLocales = context_util.getSkillManifest(builderContext).manifest249 ?.publishingInformation?.locales;250 expect(publishInfoLocales).to.not.be.undefined;251 if (publishInfoLocales) {252 expect(publishInfoLocales[Locale.en_US]).to.not.be.undefined;253 expect(publishInfoLocales[Locale.en_US].name).equals(name);254 expect(publishInfoLocales[Locale.en_US].description).equals(description);255 expect(publishInfoLocales[Locale.en_US].examplePhrases).deep.equals(256 examplePhrases257 );258 expect(publishInfoLocales[Locale.en_US].smallIconUri).equals(smallIcon);259 expect(publishInfoLocales[Locale.en_US].largeIconUri).equals(largeIcon);260 expect(publishInfoLocales[Locale.en_US].keywords).deep.equals(keywords);261 expect(publishInfoLocales[Locale.en_US].summary).equals(summary);262 expect(publishInfoLocales[Locale.en_US].updatesDescription).equals(263 updatesDescription264 );265 // exactly one locale is present in the skill manifest i.e. en_US266 expect(Object.keys(publishInfoLocales).length).equals(1);267 }268 });269 });270 describe("executor", () => {271 it("should not change anything", () => {272 let b = new SkillInfoBlockBuilder().build();273 let c = _.cloneDeep(context);274 b.execute(c, event);275 expect(_.isEqual(c, context)).to.be.true;276 });277 });...

Full Screen

Full Screen

framework-preset-angular-cli.ts

Source:framework-preset-angular-cli.ts Github

copy

Full Screen

1import webpack from 'webpack';2import { logger } from '@storybook/node-logger';3import { targetFromTargetString, BuilderContext } from '@angular-devkit/architect';4import { sync as findUpSync } from 'find-up';5import semver from '@storybook/semver';6import { logging, JsonObject } from '@angular-devkit/core';7import { moduleIsAvailable } from './utils/module-is-available';8import { getWebpackConfig as getWebpackConfig12_2_x } from './angular-cli-webpack-12.2.x';9import { getWebpackConfig as getWebpackConfig13_x_x } from './angular-cli-webpack-13.x.x';10import { getWebpackConfig as getWebpackConfigOlder } from './angular-cli-webpack-older';11import { PresetOptions } from './options';12export async function webpackFinal(baseConfig: webpack.Configuration, options: PresetOptions) {13 if (!moduleIsAvailable('@angular-devkit/build-angular')) {14 logger.info('=> Using base config because "@angular-devkit/build-angular" is not installed');15 return baseConfig;16 }17 const angularCliVersion = await import('@angular/cli').then((m) => semver.coerce(m.VERSION.full));18 /**19 * Ordered array to use the specific getWebpackConfig according to some condition like angular-cli version20 */21 const webpackGetterByVersions: {22 info: string;23 condition: boolean;24 getWebpackConfig(25 baseConfig: webpack.Configuration,26 options: PresetOptions27 ): Promise<webpack.Configuration> | webpack.Configuration;28 }[] = [29 {30 info: '=> Loading angular-cli config for angular >= 13.0.0',31 condition: semver.satisfies(angularCliVersion, '>=13.0.0'),32 getWebpackConfig: async (_baseConfig, _options) => {33 const builderContext = getBuilderContext(_options);34 const builderOptions = await getBuilderOptions(_options, builderContext);35 return getWebpackConfig13_x_x(_baseConfig, {36 builderOptions,37 builderContext,38 });39 },40 },41 {42 info: '=> Loading angular-cli config for angular 12.2.x',43 condition: semver.satisfies(angularCliVersion, '12.2.x') && options.angularBuilderContext,44 getWebpackConfig: async (_baseConfig, _options) => {45 const builderContext = getBuilderContext(_options);46 const builderOptions = await getBuilderOptions(_options, builderContext);47 return getWebpackConfig12_2_x(_baseConfig, {48 builderOptions,49 builderContext,50 });51 },52 },53 {54 info: '=> Loading angular-cli config for angular lower than 12.2.0',55 condition: true,56 getWebpackConfig: getWebpackConfigOlder,57 },58 ];59 const webpackGetter = webpackGetterByVersions.find((wg) => wg.condition);60 logger.info(webpackGetter.info);61 return Promise.resolve(webpackGetter.getWebpackConfig(baseConfig, options));62}63/**64 * Get Builder Context65 * If storybook is not start by angular builder create dumb BuilderContext66 */67function getBuilderContext(options: PresetOptions): BuilderContext {68 return (69 options.angularBuilderContext ??70 (({71 target: { project: 'noop-project', builder: '', options: {} },72 workspaceRoot: process.cwd(),73 getProjectMetadata: () => ({}),74 getTargetOptions: () => ({}),75 logger: new logging.Logger('Storybook'),76 } as unknown) as BuilderContext)77 );78}79/**80 * Get builder options81 * Merge target options from browser target and from storybook options82 */83async function getBuilderOptions(84 options: PresetOptions,85 builderContext: BuilderContext86): Promise<JsonObject> {87 /**88 * Get Browser Target options89 */90 let browserTargetOptions: JsonObject = {};91 if (options.angularBrowserTarget) {92 const browserTarget = targetFromTargetString(options.angularBrowserTarget);93 logger.info(94 `=> Using angular browser target options from "${browserTarget.project}:${95 browserTarget.target96 }${browserTarget.configuration ? `:${browserTarget.configuration}` : ''}"`97 );98 browserTargetOptions = await builderContext.getTargetOptions(browserTarget);99 }100 /**101 * Merge target options from browser target options and from storybook options102 */103 const builderOptions = {104 ...browserTargetOptions,105 ...(options.angularBuilderOptions as JsonObject),106 tsConfig:107 options.tsConfig ??108 findUpSync('tsconfig.json', { cwd: options.configDir }) ??109 browserTargetOptions.tsConfig,110 };111 logger.info(`=> Using angular project with "tsConfig:${builderOptions.tsConfig}"`);112 return builderOptions;...

Full Screen

Full Screen

context.ts

Source:context.ts Github

copy

Full Screen

1import { assert } from "chai";2import { ERRORS } from "../../src/errors/errors-list";3import { BuilderContext } from "../../src/internal/context";4import { resetBuilderContext } from "../../src/internal/reset";5import { useEnvironment } from "../helpers/environment";6import { expectBuilderError } from "../helpers/errors";7import { useFixtureProject } from "../helpers/project";8describe("Builder context", function () {9 describe("no context", () => {10 it("context is not defined", async function () {11 assert.isFalse(BuilderContext.isCreated());12 });13 it("should throw when context isn't created", async function () {14 expectBuilderError(15 () => BuilderContext.getBuilderContext(),16 ERRORS.GENERAL.CONTEXT_NOT_CREATED17 );18 });19 });20 describe("create context but no environment", function () {21 afterEach("reset context", function () {22 resetBuilderContext();23 });24 it("context is defined", async function () {25 BuilderContext.createBuilderContext();26 assert.isTrue(BuilderContext.isCreated());27 });28 it("context initialize properly", async function () {29 const ctx = BuilderContext.createBuilderContext();30 assert.isDefined(ctx.extendersManager);31 assert.isDefined(ctx.tasksDSL);32 assert.isUndefined(ctx.environment);33 });34 it("should throw when recreating algob context", async function () {35 BuilderContext.createBuilderContext();36 expectBuilderError(37 () => BuilderContext.createBuilderContext(),38 ERRORS.GENERAL.CONTEXT_ALREADY_CREATED39 );40 });41 it("should delete context", async function () {42 assert.isFalse(BuilderContext.isCreated());43 BuilderContext.createBuilderContext();44 assert.isTrue(BuilderContext.isCreated());45 BuilderContext.deleteBuilderContext();46 assert.isFalse(BuilderContext.isCreated());47 });48 it("should throw when BRE is not defined", async function () {49 const ctx = BuilderContext.createBuilderContext();50 expectBuilderError(51 () => ctx.getRuntimeEnv(),52 ERRORS.GENERAL.CONTEXT_BRE_NOT_DEFINED53 );54 });55 });56 describe("environment creates context", function () {57 useFixtureProject("config-project");58 useEnvironment();59 it("should create context and set BRE into context", async function () {60 assert.equal(61 BuilderContext.getBuilderContext().getRuntimeEnv(),62 this.env63 );64 });65 it("should throw when trying to set BRE", async function () {66 expectBuilderError(67 () =>68 BuilderContext.getBuilderContext().setRuntimeEnv(69 this.env70 ),71 ERRORS.GENERAL.CONTEXT_BRE_ALREADY_DEFINED72 );73 });74 });...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1import {builderContext} from 'storybook-root-cause'2import {MyComponent} from './MyComponent'3export default {4 parameters: {5 builderContext: builderContext({6 storyParameters: {},7 }),8 },9}10export const MyComponentStory = () => <MyComponent />11import React from 'react'12import {render} from '@testing-library/react'13import {MyComponent} from './MyComponent'14describe('MyComponent', () => {15 it('should render', () => {16 const {container} = render(<MyComponent />)17 expect(container).toMatchSnapshot()18 })19})20import React from 'react'21import {render} from '@testing-library/react'22import {MyComponent} from './MyComponent'23describe('MyComponent', () => {24 it('should render', () => {25 const {container} = render(<MyComponent />)26 expect(container).toMatchSnapshot()27 })28})29import React from 'react'30import {MyComponent} from './MyComponent'31export default {32}33export const MyComponentStory = () => <MyComponent />34import React from 'react'35import {MyComponent} from './MyComponent'36export default {37}38export const MyComponentStory = () => <MyComponent />39import React from 'react'40import {MyComponent} from './MyComponent'41export default {42}43export const MyComponentStory = () => <MyComponent />44import React from 'react'45import {MyComponent} from './MyComponent'46export default {47}48export const MyComponentStory = () => <MyComponent />49- [getStorybookRootCauseConfig](#getstorybookrootcauseconfig)

Full Screen

Using AI Code Generation

copy

Full Screen

1import { builderContext } from 'storybook-root-cause';2import { BuilderContext } from '@angular-devkit/architect';3import { Story } from '@storybook/angular';4import { AppComponent } from './app.component';5const builderContext: BuilderContext = builderContext();6export default {7};8const Template: Story<AppComponent> = (args: AppComponent) => ({9 moduleMetadata: {10 imports: [11 },12});13export const Default = Template.bind({});14Default.args = {15};16import { BuilderContext } from '@angular-devkit/architect';17import { StorybookBuilderOptions } from '@storybook/angular';18import { StorybookBuilder } from 'storybook-root-cause';19import { join } from 'path';20const builderContext: BuilderContext = builderContext();21export default class CustomStorybookBuilder extends StorybookBuilder {22 constructor(context: BuilderContext) {23 super(context);24 }25 async run(builderConfig: StorybookBuilderOptions) {26 builderConfig.configDir = join(__dirname, '../.storybook');27 builderConfig.configType = 'ts';28 builderConfig.config = join(__dirname, '../.storybook/main.ts');29 builderConfig.port = 6006;30 builderConfig.staticDir = [join(__dirname, '../src/assets')];31 builderConfig.webpackFinal = (config) => {32 return config;33 };34 await super.run(builderConfig);35 }36}37"custom-storybook": {38}

Full Screen

Using AI Code Generation

copy

Full Screen

1import { builderContext } from 'storybook-root';2export default {3 parameters: {4 builderContext: builderContext('test', 'test'),5 },6};7export const Test = () => {8 return <div>Test</div>;9};10import { addParameters } from '@storybook/react';11import { builderContext } from 'storybook-root';12addParameters({13 builderContext: builderContext('test', 'test'),14});15import { builderContext } from 'storybook-root';16import { addParameters } from '@storybook/react';17addParameters({18 builderContext: builderContext('test', 'test'),19});20export default {21 parameters: {22 builderContext: builderContext('test', 'test'),23 },24};25export const Test = () => {26 return <div>Test</div>;27};28import { builderContext } from 'storybook-root';29import { addParameters } from '@storybook/react';30addParameters({31 builderContext: builderContext('test', 'test'),32});

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