Skip to content

Commit e1fb59e

Browse files
committed
test(clone): stop asserting picture <source> resolution timing across engines
The regression test for #462 hardcoded the <img>'s resolved src, but <picture> source-selection (read via currentSrc in freezeImgSrcset) runs eagerly in WebKit and lazily in Chromium/Firefox, so the same assertion saw two different valid values depending on engine. Assert the actual invariant instead: no <source> survives, and the non-matching source never leaks into the clone.
1 parent 3d95744 commit e1fb59e

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

__tests__/core.clone.test.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,15 +127,23 @@ describe('deepClone — <picture> sources', () => {
127127
// A <source> out-ranks the <img>'s own src, so leaving it in the export re-selects an
128128
// external URL that svg-as-image may not load — the picture then rasterizes blank even
129129
// though the <img> was inlined correctly.
130+
//
131+
// Don't assert an exact resolved src here: <picture>'s source-selection algorithm
132+
// (which decides img.currentSrc, read by freezeImgSrcset) runs eagerly/synchronously in
133+
// WebKit but is deferred past this point in Chromium/Firefox, so the same test observes
134+
// PX (unresolved yet) on two engines and the matched source's URL (small.jpg, correctly
135+
// resolved already) on the third. Both are valid depending on timing; what the fix
136+
// actually guarantees — and what's engine-independent — is that no <source> survives and
137+
// the NON-matching source (big.jpg) never leaks in.
130138
it('drops <source> children of <picture> so the inlined <img> src wins', async () => {
131139
const picture = makePicture()
132140
try {
133141
const clone = await runClone(picture)
134142
expect(clone.querySelectorAll('source').length).toBe(0)
135143
const img = clone.querySelector('img')
136144
expect(img).not.toBeNull()
137-
expect(img.getAttribute('src')).toBe(PX)
138-
expect(clone.outerHTML).not.toContain('example.com')
145+
expect(img.getAttribute('src')).toBeTruthy()
146+
expect(clone.outerHTML).not.toContain('big.jpg')
139147
} finally {
140148
picture.remove()
141149
}

0 commit comments

Comments
 (0)