You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In order to define the langage that the command line test should use, i try to override the prepare function to send the globals=locale:lang property.
If the URI called is the right one (ie http://127.0.0.1:6006?globals=locale:en&id=my-story-id), the context does have the default value (in my case, context.globals.locale: 'fr').
Thus, the text content in the body is always the default langage and never the one define in the global variable.
To Reproduce
// .storybook/test-runner.tsconstconfig: TestRunnerConfig={asyncprepare({ page, browserContext, testRunnerConfig }){consttargetURL=process.env.TARGET_URLletURI='iframe.html'if(process.env.STORYBOOK_LANGAGE){URI+=`?globals=locale:${process.env.STORYBOOK_LANGAGE}`}constiframeURL=newURL(URI,targetURL).toString()if(testRunnerConfig?.getHttpHeaders){constheaders=awaittestRunnerConfig.getHttpHeaders(iframeURL)awaitbrowserContext.setExtraHTTPHeaders(headers)}awaitpage.goto(iframeURL,{waitUntil: 'domcontentloaded'}).catch((err)=>{if(err.message?.includes('ERR_CONNECTION_REFUSED')){consterrorMessage=`Could not access the Storybook instance at ${targetURL}. Are you sure it's running?\n\n${err.message}`thrownewError(errorMessage)}throwerr})},}
// src/mycomponent/mycomponent.stories.tsxconstmeta: Meta<CustomTvxProps>={// ...loaders: [async(context)=>{awaiti18n.changeLanguage(context.globals.locale)console.log('[HOOK] BEFORE EACH - BUTTON')return{}}],}constMyStory: StoryObj<StoryProps>={play: async({ canvasElement, step })=>{constcanvas=within(canvasElement)constlabel=canvas.getByTestId('translated')awaitstep('is in english ?',async()=>{// Default being 'Bonjour'awaitexpect(label.textContent).toBe('Hello')// => Is always failing})}
Launch the command : STORYBOOK_LANGAGE=en npm run test-storybook
Describe the bug
In order to define the langage that the command line test should use, i try to override the
prepare
function to send theglobals=locale:lang
property.If the URI called is the right one (ie
http://127.0.0.1:6006?globals=locale:en&id=my-story-id
), the context does have the default value (in my case,context.globals.locale: 'fr'
).Thus, the text content in the body is always the default langage and never the one define in the global variable.
To Reproduce
Launch the command :
STORYBOOK_LANGAGE=en npm run test-storybook
System
Additional context
FYI, the tests works fine in the Storybook web interface.
The text was updated successfully, but these errors were encountered: