8
8
DEFAULT_FILES_PATTERN ,
9
9
getInterpretedFile ,
10
10
normalizeStories ,
11
+ optionalEnvToBoolean ,
11
12
resolvePathInStorybookCache ,
12
13
validateConfigurationFiles ,
13
14
} from 'storybook/internal/common' ;
@@ -123,14 +124,18 @@ export const storybookTest = async (options?: UserOptions): Promise<Plugin[]> =>
123
124
} ,
124
125
} as InternalOptions ;
125
126
126
- if ( process . env . DEBUG ) {
127
+ if ( optionalEnvToBoolean ( process . env . DEBUG ) ) {
127
128
finalOptions . debug = true ;
128
129
}
129
130
130
131
// To be accessed by the global setup file
131
132
process . env . __STORYBOOK_URL__ = finalOptions . storybookUrl ;
132
133
process . env . __STORYBOOK_SCRIPT__ = finalOptions . storybookScript ;
133
134
135
+ // We signal the test runner that we are not running it via Storybook
136
+ // We are overriding the environment variable to 'true' if vitest runs via @storybook/addon-vitest's backend
137
+ const isVitestStorybook = optionalEnvToBoolean ( process . env . VITEST_STORYBOOK ) ;
138
+
134
139
const directories = {
135
140
configDir : finalOptions . configDir ,
136
141
workingDir : WORKING_DIR ,
@@ -212,10 +217,6 @@ export const storybookTest = async (options?: UserOptions): Promise<Plugin[]> =>
212
217
// plugin.name?.startsWith('vitest:browser')
213
218
// )
214
219
215
- // We signal the test runner that we are not running it via Storybook
216
- // We are overriding the environment variable to 'true' if vitest runs via @storybook/addon-vitest's backend
217
- const vitestStorybook = process . env . VITEST_STORYBOOK ?? 'false' ;
218
-
219
220
const testConfig = nonMutableInputConfig . test ;
220
221
finalOptions . vitestRoot =
221
222
testConfig ?. dir || testConfig ?. root || nonMutableInputConfig . root || process . cwd ( ) ;
@@ -260,7 +261,7 @@ export const storybookTest = async (options?: UserOptions): Promise<Plugin[]> =>
260
261
// To be accessed by the setup file
261
262
__STORYBOOK_URL__ : finalOptions . storybookUrl ,
262
263
263
- VITEST_STORYBOOK : vitestStorybook ,
264
+ VITEST_STORYBOOK : isVitestStorybook ? 'true' : 'false' ,
264
265
__VITEST_INCLUDE_TAGS__ : finalOptions . tags . include . join ( ',' ) ,
265
266
__VITEST_EXCLUDE_TAGS__ : finalOptions . tags . exclude . join ( ',' ) ,
266
267
__VITEST_SKIP_TAGS__ : finalOptions . tags . skip . join ( ',' ) ,
@@ -288,9 +289,7 @@ export const storybookTest = async (options?: UserOptions): Promise<Plugin[]> =>
288
289
getInitialGlobals : ( ) => {
289
290
const envConfig = JSON . parse ( process . env . VITEST_STORYBOOK_CONFIG ?? '{}' ) ;
290
291
291
- const shouldRunA11yTests = process . env . VITEST_STORYBOOK
292
- ? ( envConfig . a11y ?? false )
293
- : true ;
292
+ const shouldRunA11yTests = isVitestStorybook ? ( envConfig . a11y ?? false ) : true ;
294
293
295
294
return {
296
295
a11y : {
@@ -373,10 +372,10 @@ export const storybookTest = async (options?: UserOptions): Promise<Plugin[]> =>
373
372
configureVitest ( context ) {
374
373
context . vitest . config . coverage . exclude . push ( 'storybook-static' ) ;
375
374
376
- const disableTelemetryVar =
377
- process . env . STORYBOOK_DISABLE_TELEMETRY &&
378
- process . env . STORYBOOK_DISABLE_TELEMETRY !== 'false' ;
379
- if ( ! core ?. disableTelemetry && ! disableTelemetryVar ) {
375
+ if (
376
+ ! core ?. disableTelemetry &&
377
+ ! optionalEnvToBoolean ( process . env . STORYBOOK_DISABLE_TELEMETRY )
378
+ ) {
380
379
// NOTE: we start telemetry immediately but do not wait on it. Typically it should complete
381
380
// before the tests do. If not we may miss the event, we are OK with that.
382
381
telemetry (
@@ -410,7 +409,7 @@ export const storybookTest = async (options?: UserOptions): Promise<Plugin[]> =>
410
409
}
411
410
} ,
412
411
async transform ( code , id ) {
413
- if ( process . env . VITEST !== 'true' ) {
412
+ if ( ! optionalEnvToBoolean ( process . env . VITEST ) ) {
414
413
return code ;
415
414
}
416
415
@@ -434,7 +433,7 @@ export const storybookTest = async (options?: UserOptions): Promise<Plugin[]> =>
434
433
// When running tests via the Storybook UI, we need
435
434
// to find the right project to run, thus we override
436
435
// with a unique identifier using the path to the config dir
437
- if ( process . env . VITEST_STORYBOOK ) {
436
+ if ( isVitestStorybook ) {
438
437
const projectName = `storybook:${ normalize ( finalOptions . configDir ) } ` ;
439
438
plugins . push ( {
440
439
name : 'storybook:workspace-name-override' ,
0 commit comments