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.ts
const config: TestRunnerConfig = {
async prepare({ page, browserContext, testRunnerConfig }) {
const targetURL = process.env.TARGET_URL
let URI = 'iframe.html'
if (process.env.STORYBOOK_LANGAGE) {
URI += `?globals=locale:${process.env.STORYBOOK_LANGAGE}`
}
const iframeURL = new URL(URI, targetURL).toString()
if (testRunnerConfig?.getHttpHeaders) {
const headers = await testRunnerConfig.getHttpHeaders(iframeURL)
await browserContext.setExtraHTTPHeaders(headers)
}
await page
.goto(iframeURL, { waitUntil: 'domcontentloaded' })
.catch((err) => {
if (err.message?.includes('ERR_CONNECTION_REFUSED')) {
const errorMessage = `Could not access the Storybook instance at ${targetURL}. Are you sure it's running?\n\n${err.message}`
throw new Error(errorMessage)
}
throw err
})
},
}
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.