Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add configuration to run specific scripts on main thread (#200)
* add configuration to run scripts on main thread * refactor to comments * remove unused export from module Co-authored-by: Daniel Beck <daniel_beck@next.co.uk>
- Loading branch information
1 parent
c2b72c2
commit 999c13c
Showing
7 changed files
with
159 additions
and
1 deletion.
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
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
121 changes: 121 additions & 0 deletions
121
tests/integrations/load-scripts-on-main-thread/index.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
<!DOCTYPE html> | ||
<html lang='en'> | ||
<head> | ||
<meta charset='UTF-8' /> | ||
<meta name='viewport' content='width=device-width, initial-scale=1' /> | ||
<meta name='description' content='Partytown Test Page' /> | ||
<title>Load scripts on main thread</title> | ||
|
||
<script> | ||
partytown = { | ||
logCalls: true, | ||
logGetters: true, | ||
logSetters: true, | ||
logStackTraces: false, | ||
logScriptExecution: true, | ||
loadScriptsOnMainThread: [`http://${location.host}/tests/integrations/load-scripts-on-main-thread/test-script.js`], | ||
}; | ||
</script> | ||
<script src='/~partytown/debug/partytown.js'></script> | ||
<script type='text/partytown'> | ||
(() => { | ||
const scriptElement = document.createElement("script"); | ||
scriptElement.type = "text/javascript"; | ||
scriptElement.src = "./test-script.js"; | ||
scriptElement.id = "testScript"; | ||
document.head.appendChild(scriptElement); | ||
})() | ||
</script> | ||
|
||
<style> | ||
body { | ||
font-family: -apple-system, BlinkMacSystemFont, Segoe UI, Helvetica, Arial, sans-serif, | ||
Apple Color Emoji, Segoe UI Emoji; | ||
font-size: 12px; | ||
} | ||
|
||
h1 { | ||
margin: 0 0 15px 0; | ||
} | ||
|
||
ul { | ||
list-style-type: none; | ||
margin: 0; | ||
padding: 0; | ||
} | ||
|
||
a { | ||
display: block; | ||
padding: 16px 8px; | ||
} | ||
|
||
a:link, | ||
a:visited { | ||
text-decoration: none; | ||
color: blue; | ||
} | ||
|
||
a:hover { | ||
background-color: #eee; | ||
} | ||
|
||
li { | ||
display: flex; | ||
margin: 15px 0; | ||
} | ||
|
||
li strong, | ||
li code, | ||
li button { | ||
white-space: nowrap; | ||
flex: 1; | ||
margin: 0 5px; | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
<h1>Load scripts on main thread 🎉</h1> | ||
<ul> | ||
<li> | ||
<strong>Script Type:</strong> | ||
<code id='testScriptType'></code> | ||
<script type='text/partytown'> | ||
(() => { | ||
const scriptElement = document.getElementById('testScript'); | ||
const codeElement = document.getElementById('testScriptType'); | ||
|
||
codeElement.innerText = scriptElement.type; | ||
})() | ||
</script> | ||
</li> | ||
<li> | ||
<strong>Script Source:</strong> | ||
<code id='testScriptSource'></code> | ||
<script type='text/partytown'> | ||
(() => { | ||
const scriptElement = document.getElementById('testScript'); | ||
const codeElement = document.getElementById('testScriptSource'); | ||
|
||
codeElement.innerText = scriptElement.src; | ||
})() | ||
</script> | ||
</li> | ||
<li> | ||
<strong>Partytown Config:</strong> | ||
<code id='testConfig'></code> | ||
<script> | ||
(() => { | ||
const partyTownConfig = window.partytown; | ||
const codeElement = document.getElementById('testConfig'); | ||
|
||
codeElement.innerText = partyTownConfig.loadScriptsOnMainThread; | ||
})() | ||
</script> | ||
</li> | ||
</ul> | ||
|
||
<hr /> | ||
<p><a href='/tests/'>All Tests</a></p> | ||
|
||
</body> | ||
</html> |
9 changes: 9 additions & 0 deletions
9
tests/integrations/load-scripts-on-main-thread/load-scripts-on-main-thread.spec.ts
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,9 @@ | ||
import { test, expect } from '@playwright/test'; | ||
|
||
test('integration window accessor', async ({ page }) => { | ||
await page.goto('/tests/integrations/load-scripts-on-main-thread/'); | ||
await page.waitForSelector('.completed'); | ||
|
||
const scriptElement = page.locator('#testScript'); | ||
await expect(scriptElement).toHaveAttribute('type', 'text/javascript') | ||
}); |
3 changes: 3 additions & 0 deletions
3
tests/integrations/load-scripts-on-main-thread/test-script.js
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,3 @@ | ||
(() => { | ||
document.body.classList.add('completed'); | ||
})() |
999c13c
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
partytown – ./
partytown.vercel.app
partytown-builder-io.vercel.app
partytown-git-main-builder-io.vercel.app
partytown.builder.io