-
Notifications
You must be signed in to change notification settings - Fork 443
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: serialize errors send to worker (#185)
* feat: serialize errors send to worker * test: error serializer * test: handle webkit error messages * test: handle chromium error messages
- Loading branch information
1 parent
ddc39d7
commit 24e5c84
Showing
6 changed files
with
216 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
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,35 @@ | ||
import { test, expect } from '@playwright/test'; | ||
|
||
test('errors', async ({ page }) => { | ||
await page.goto('/tests/platform/error/'); | ||
|
||
// ReferenceError | ||
await page.waitForSelector('.refErrorReady'); | ||
const attachRefErrorBtn = page.locator('#refErrorAttachHandler'); | ||
await attachRefErrorBtn.click(); | ||
const throwRefErrorBtn = page.locator('#refErrorThrowingButton'); | ||
await throwRefErrorBtn.click(); | ||
|
||
const refErrorName = await page.locator('#refErrorName'); | ||
await expect(refErrorName).toHaveText('ReferenceError') | ||
const refErrorMessage = await page.locator('#refErrorMessage'); | ||
// Error messages differ between Chromium and Webkit | ||
await expect(refErrorMessage).toHaveText(/(blahblah is not defined|Can't find variable: blahblah)/); | ||
const refErrorStack = await page.locator('#refErrorStack'); | ||
// Error messages differ between Chromium and Webkit | ||
await expect(refErrorStack).toContainText( | ||
/(ReferenceError: blahblah is not defined\s+at HTMLButtonElement|@https?:\/\/.+\/tests\/platform\/error\/:\d+:\d+)/ | ||
); | ||
|
||
// CustomError | ||
await page.waitForSelector('.customErrorReady'); | ||
const attachCustomErrorBtn = page.locator('#customErrorAttachHandler'); | ||
await attachCustomErrorBtn.click(); | ||
const throwCustomErrorBtn = page.locator('#customErrorThrowingButton'); | ||
await throwCustomErrorBtn.click(); | ||
|
||
const customErrorName = await page.locator('#customErrorName'); | ||
await expect(customErrorName).toHaveText('FooError') | ||
const customErrorMessage = await page.locator('#customErrorMessage'); | ||
await expect(customErrorMessage).toHaveText('custom error message') | ||
}); |
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,149 @@ | ||
<!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>Error</title> | ||
<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> | ||
<script> | ||
partytown = { | ||
logCalls: true, | ||
logGetters: true, | ||
logSetters: true, | ||
logStackTraces: false, | ||
logScriptExecution: true, | ||
}; | ||
</script> | ||
<script src="/~partytown/debug/partytown.js"></script> | ||
</head> | ||
<body> | ||
<h1>Error</h1> | ||
<ul> | ||
<li> | ||
<button id="refErrorAttachHandler">attach</button> | ||
<button id="refErrorThrowingButton">throw ReferenceError</button> | ||
<code id="refErrorName"></code> | ||
<code id="refErrorMessage"></code> | ||
<code id="refErrorStack"></code> | ||
<script type="text/javascript"> | ||
(function () { | ||
const refErrorThrowingButton = document.getElementById('refErrorThrowingButton'); | ||
|
||
refErrorThrowingButton.addEventListener('click', function () { | ||
blahblah | ||
}); | ||
}()) | ||
</script> | ||
<script type="text/partytown"> | ||
(function () { | ||
const attachErrorBtn = document.getElementById('refErrorAttachHandler'); | ||
const reporterNameEl = document.getElementById('refErrorName'); | ||
const reporterMessageEl = document.getElementById('refErrorMessage'); | ||
const reporterStackEl = document.getElementById('refErrorStack'); | ||
|
||
function errorHandler(message, source, lineno, colno, err) { | ||
reporterNameEl.textContent = err.name; | ||
reporterMessageEl.textContent = err.message; | ||
reporterStackEl.textContent = err.stack; | ||
|
||
window.onerror = null; | ||
} | ||
|
||
attachErrorBtn.addEventListener('click', () => { | ||
window.onerror = errorHandler; | ||
}); | ||
|
||
reporterNameEl.className = 'refErrorReady'; | ||
})(); | ||
</script> | ||
</li> | ||
|
||
<li> | ||
<button id="customErrorAttachHandler">attach</button> | ||
<button id="customErrorThrowingButton">throw CustomError</button> | ||
<code id="customErrorName"></code> | ||
<code id="customErrorMessage"></code> | ||
<code id="customErrorStack"></code> | ||
<script type="text/javascript"> | ||
(function () { | ||
const customErrorThrowingButton = document.getElementById('customErrorThrowingButton'); | ||
|
||
class FooError extends Error { | ||
constructor(msg) { | ||
super(msg); | ||
this.name = 'FooError'; | ||
} | ||
} | ||
|
||
customErrorThrowingButton.addEventListener('click', function () { | ||
const err = new FooError('custom error message'); | ||
console.log(err); | ||
throw err; | ||
}); | ||
}()) | ||
</script> | ||
<script type="text/partytown"> | ||
(function () { | ||
const attachErrorBtn = document.getElementById('customErrorAttachHandler'); | ||
const reporterNameEl = document.getElementById('customErrorName'); | ||
const reporterMessageEl = document.getElementById('customErrorMessage'); | ||
|
||
function errorHandler(message, source, lineno, colno, err) { | ||
reporterNameEl.textContent = err.name; | ||
reporterMessageEl.textContent = err.message; | ||
|
||
window.onerror = null; | ||
} | ||
|
||
attachErrorBtn.addEventListener('click', () => { | ||
window.onerror = errorHandler; | ||
console.log('attached handler'); | ||
}); | ||
reporterNameEl.className = 'customErrorReady'; | ||
})(); | ||
</script> | ||
</li> | ||
</ul> | ||
|
||
<hr /> | ||
<p><a href="/tests/">All Tests</a></p> | ||
</body> | ||
</html> |
24e5c84
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.builder.io
partytown-git-main-builder-io.vercel.app
partytown-builder-io.vercel.app
partytown.vercel.app