1- import { rmdirSync } from 'node:fs'
1+ import { rmdirSync , rmSync } from 'node:fs'
22import { join } from 'node:path'
33import logger from '@wdio/logger'
44import type { Capabilities , Services } from '@wdio/types'
@@ -25,6 +25,28 @@ vi.mock('../../src/storybook/utils.js', ()=>({
2525 createStorybookCapabilities : vi . fn ( ) ,
2626} ) )
2727
28+ describe ( 'Visual Launcher - clearRuntimeFolder (issue #683)' , ( ) => {
29+ afterEach ( ( ) => {
30+ vi . restoreAllMocks ( )
31+ } )
32+
33+ it ( 'should clear runtime folders once in onPrepare, not per-worker' , async ( ) => {
34+ vi . mocked ( storybookUtils . isStorybookMode ) . mockReturnValueOnce ( false )
35+ const rmSyncMock = vi . mocked ( rmSync )
36+ rmSyncMock . mockClear ( )
37+
38+ const launcher = new VisualLauncher ( { clearRuntimeFolder : true } )
39+ // Clear any calls that happened during construction — these are the bug
40+ rmSyncMock . mockClear ( )
41+
42+ const config = { runner : 'local' , framework : 'mocha' } as WebdriverIO . Config
43+ await launcher . onPrepare ! ( config , [ { } ] )
44+
45+ // onPrepare should clear both the actual and diff folders
46+ expect ( rmSyncMock ) . toHaveBeenCalledTimes ( 2 )
47+ } )
48+ } )
49+
2850describe ( 'Visual Launcher for Storybook' , ( ) => {
2951 describe ( 'onPrepare' , ( ) => {
3052 let options : ClassOptions ,
0 commit comments