|
1 | | -import { join } from 'node:path' |
| 1 | +import { dirname, join, normalize } from 'node:path' |
2 | 2 | import logger from '@wdio/logger' |
3 | 3 | import { expect as wdioExpect } from '@wdio/globals' |
4 | 4 | import { beforeEach, describe, expect, it, vi } from 'vitest' |
@@ -199,5 +199,41 @@ describe('@wdio/visual-service', () => { |
199 | 199 | const [saveScreenOptions] = vi.mocked(saveScreen).mock.calls[0] |
200 | 200 | expect((saveScreenOptions as any).saveScreenOptions?.wic?.alwaysSaveActualImage).toBe(true) |
201 | 201 | }) |
| 202 | + |
| 203 | + it('should use dirname() of resolveSnapshotPath result as baselineFolder to avoid EISDIR conflicts', async () => { |
| 204 | + vi.mocked(saveScreen).mockResolvedValue({} as any) |
| 205 | + const resolveSnapshotPath = vi.fn().mockReturnValue('/custom/snapshots/specs/test.e2e.png') |
| 206 | + const config = { |
| 207 | + framework: 'mocha', |
| 208 | + resolveSnapshotPath, |
| 209 | + } as unknown as WebdriverIO.Config |
| 210 | + const service = new VisualService({}, {}, config) |
| 211 | + ;(service as any).defaultOptions = {} |
| 212 | + ;(service as any).folders = { baselineFolder: normalize('./__snapshots__/') } |
| 213 | + const browser = { |
| 214 | + isMultiremote: false, |
| 215 | + addCommand: vi.fn((name, fn) => { |
| 216 | + (browser as any)[name] = fn |
| 217 | + }), |
| 218 | + capabilities: {}, |
| 219 | + requestedCapabilities: {}, |
| 220 | + on: vi.fn(), |
| 221 | + execute: vi.fn().mockResolvedValue(1), |
| 222 | + } as any as WebdriverIO.Browser |
| 223 | + |
| 224 | + await service.before({}, [], browser) |
| 225 | + service.beforeTest({ |
| 226 | + file: '/project/specs/test.e2e.ts', |
| 227 | + parent: 'suite', |
| 228 | + title: 'test', |
| 229 | + } as any) |
| 230 | + await (browser as any).saveScreen('tag') |
| 231 | + |
| 232 | + expect(resolveSnapshotPath).toHaveBeenCalledWith('/project/specs/test.e2e.ts', '.png') |
| 233 | + const [saveScreenOptions] = vi.mocked(saveScreen).mock.calls[0] |
| 234 | + expect((saveScreenOptions as any).folders.baselineFolder).toBe( |
| 235 | + dirname('/custom/snapshots/specs/test.e2e.png') |
| 236 | + ) |
| 237 | + }) |
202 | 238 | }) |
203 | 239 | }) |
0 commit comments