Skip to content

Commit 637b06f

Browse files
committed
test: create failing tests
1 parent b076e37 commit 637b06f

2 files changed

Lines changed: 29 additions & 1 deletion

File tree

packages/image-comparison-core/src/base.test.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,10 @@ describe('BaseClass', () => {
5353

5454
expect(rmSync).toHaveBeenCalledTimes(2)
5555
})
56+
57+
it('should not clear runtime folders in the constructor - clearing should only happen once in the launcher (issue #683)', () => {
58+
vi.mocked(rmSync).mockClear()
59+
new BaseClass({ clearRuntimeFolder: true })
60+
expect(rmSync).not.toHaveBeenCalled()
61+
})
5662
})

packages/visual-service/tests/storybook/launcher.test.ts

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { rmdirSync } from 'node:fs'
1+
import { rmdirSync, rmSync } from 'node:fs'
22
import { join } from 'node:path'
33
import logger from '@wdio/logger'
44
import 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+
2850
describe('Visual Launcher for Storybook', () => {
2951
describe('onPrepare', () => {
3052
let options: ClassOptions,

0 commit comments

Comments
 (0)