Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
vinay gosain committed Mar 28, 2023
1 parent 6009ce3 commit 3e517f2
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
14 changes: 14 additions & 0 deletions tests/platform/script/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,20 @@ <h1 class="title">Script</h1>
})();
</script>
</li>
<li>
<strong>script cloneNode</strong>
<code id="testSrcCloneNode"></code>
<script src="script-1.js" type="text/partytown"></script>
<script type="text/partytown">
(function () {
const scriptElm = document.querySelector("script[src='script-1.js']");
const scriptCloneElm = scriptElm.cloneNode(true);
const elm = document.getElementById('testSrcCloneNode');
elm.textContent = scriptCloneElm.src;
elm.className = 'testSrcCloneNode';
})();
</script>
</li>
</ul>

<hr />
Expand Down
4 changes: 4 additions & 0 deletions tests/platform/script/script-1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
(function () {
console.log('a simple script is loaded');
})();

6 changes: 6 additions & 0 deletions tests/platform/script/script.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,10 @@ test('script', async ({ page }) => {
await page.waitForSelector('.testAppendMainScript');
const testAppendMainScript = page.locator('#testAppendMainScript');
await expect(testAppendMainScript).toHaveText('ptupdate');

await page.waitForSelector('.testSrcCloneNode');
const testSrcCloneNode = page.locator('#testSrcCloneNode');
const srcAttr2 = await testSrcCloneNode.textContent();
const srcUrl2 = new URL(srcAttr2!);
expect(srcUrl2.pathname).toBe('/tests/platform/script/script-1.js');
});

0 comments on commit 3e517f2

Please sign in to comment.