-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: observe all mutatiosn to capture late added medias
- Loading branch information
Showing
3 changed files
with
81 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
<html> | ||
|
||
<head> | ||
<title>Test Runner</title> | ||
</head> | ||
|
||
<body> | ||
<script type="module"> | ||
import { runTests } from '@web/test-runner-mocha'; | ||
import { expect } from '@esm-bundle/chai'; | ||
|
||
runTests(async () => { | ||
describe('HTML IMG Tests', () => { | ||
|
||
it('rum enhancer reports image, even if added later', async () => { | ||
let called = false; | ||
let imagesSeen = ''; | ||
window.hlx = { | ||
rum: { | ||
sampleRUM: (checkpoint, data) => { | ||
called = true; | ||
if (checkpoint === 'viewmedia') { | ||
imagesSeen = data.target; | ||
console.log('viewmedia', data.target); | ||
} | ||
} | ||
} | ||
}; | ||
|
||
const script = document.createElement('script'); | ||
script.src = new URL('/modules/index.js', window.location).href; | ||
script.type = 'module'; | ||
document.head.appendChild(script); | ||
|
||
await new Promise((resolve) => { | ||
script.onload = resolve; | ||
}); | ||
|
||
// wait one second for the script to run | ||
await new Promise((resolve) => { | ||
setTimeout(resolve, 1000); | ||
}); | ||
|
||
const img = document.createElement('img'); | ||
img.src = 'https://www.example.com/loadlater.jpg'; | ||
img.alt = 'loadlater example image'; | ||
document.body.appendChild(img); | ||
|
||
// wait one second for the script to run | ||
await new Promise((resolve) => { | ||
setTimeout(resolve, 1000); | ||
}); | ||
|
||
expect(called).to.be.true; | ||
expect(imagesSeen, 'img inserted later triggers viewmedia').to.equal('https://www.example.com/loadlater.jpg'); | ||
|
||
}); | ||
|
||
}); | ||
}); | ||
</script> | ||
</body> | ||
|
||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters