|
1 | | -/// <reference types="@wdio/visual-service" /> |
| 1 | +import { readdirSync } from 'node:fs' |
| 2 | +import { join } from 'node:path' |
2 | 3 | import { browser, expect } from '@wdio/globals' |
3 | 4 |
|
4 | 5 | describe('@wdio/visual-service matcher', () => { |
@@ -36,4 +37,36 @@ describe('@wdio/visual-service matcher', () => { |
36 | 37 | ] |
37 | 38 | }) |
38 | 39 | }) |
| 40 | + |
| 41 | + it(`should NOT save actual image when mismatch is within threshold (#1111) for '${browserName}'`, async () => { |
| 42 | + const tag = 'threshold-test-1111' |
| 43 | + const actualFolder = join(process.cwd(), '.tmp/actual') |
| 44 | + const subtitle = await $('.hero__subtitle') |
| 45 | + const getActualImageCount = () => { |
| 46 | + try { |
| 47 | + return readdirSync(actualFolder).filter(f => f.includes(tag)).length |
| 48 | + } catch { |
| 49 | + return 0 |
| 50 | + } |
| 51 | + } |
| 52 | + |
| 53 | + // 1. Save the original subtitle as baseline |
| 54 | + await browser.saveElement(subtitle, tag) |
| 55 | + |
| 56 | + // 2. Manipulate the subtitle to create a small text difference |
| 57 | + await browser.execute( |
| 58 | + 'arguments[0].innerHTML = "Test Demo Page";', |
| 59 | + subtitle |
| 60 | + ) |
| 61 | + |
| 62 | + const beforeCount = getActualImageCount() |
| 63 | + |
| 64 | + // 3. Run the matcher with a threshold (90%) higher than the expected mismatch |
| 65 | + await expect(subtitle).toMatchElementSnapshot(tag, 90) |
| 66 | + |
| 67 | + const afterCount = getActualImageCount() |
| 68 | + |
| 69 | + // 4. With the fix: no new actual image should be saved when mismatch is within threshold |
| 70 | + expect(afterCount).toBe(beforeCount) |
| 71 | + }) |
39 | 72 | }) |
0 commit comments