Skip to content

Commit

Permalink
fix: add document.scripts & tests
Browse files Browse the repository at this point in the history
  • Loading branch information
burakbasbug committed Dec 20, 2023
1 parent 07e6a0f commit 2bc0458
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/lib/web-worker/worker-document.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,12 @@ export const patchDocument = (
},
},

scripts: {
get() {
return getter(this, ['scripts']);
},
},

implementation: {
get() {
return {
Expand Down
16 changes: 16 additions & 0 deletions tests/platform/window/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -769,6 +769,22 @@ <h1>Window</h1>
</script>
</li>

<li>
<strong>Scripts</strong>
<code id="testDocumentScripts"></code>
<script type="text/partytown">
(function () {
const elm = document.getElementById('testDocumentScripts');
try{
const scripts = typeof window.document.scripts.length;
elm.textContent = 'scripts.length: ' + scripts;
}catch(e){
elm.textContent = e.toString();
}
})();
</script>
</li>

<script type="text/partytown">
(function () {
document.body.classList.add('completed');
Expand Down
3 changes: 3 additions & 0 deletions tests/platform/window/window.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,4 +154,7 @@ test('window', async ({ page }) => {

const testVisualViewport = page.locator('#testVisualViewport');
await expect(testVisualViewport).toHaveText('scale:1 VisualViewport');

const testDocumentScripts = page.locator('#testDocumentScripts');
await expect(testDocumentScripts).toHaveText('scripts.length: number');
});

0 comments on commit 2bc0458

Please sign in to comment.