-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(browser): inline pretty-format and replace picocolors with tinyra…
…inbow (#6077)
- Loading branch information
1 parent
7f0cc24
commit 80a43d5
Showing
108 changed files
with
2,218 additions
and
415 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
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,81 @@ | ||
import { channel, client } from '/@id/@vitest/browser/client' | ||
|
||
function on(event, listener) { | ||
window.addEventListener(event, listener) | ||
return () => window.removeEventListener(event, listener) | ||
} | ||
|
||
function serializeError(unhandledError) { | ||
if (typeof unhandledError !== 'object' || !unhandledError) { | ||
return { | ||
message: String(unhandledError), | ||
} | ||
} | ||
|
||
return { | ||
name: unhandledError.name, | ||
message: unhandledError.message, | ||
stack: String(unhandledError.stack), | ||
} | ||
} | ||
|
||
function catchWindowErrors(cb) { | ||
let userErrorListenerCount = 0 | ||
function throwUnhandlerError(e) { | ||
if (userErrorListenerCount === 0 && e.error != null) { | ||
cb(e) | ||
} | ||
else { | ||
console.error(e.error) | ||
} | ||
} | ||
const addEventListener = window.addEventListener.bind(window) | ||
const removeEventListener = window.removeEventListener.bind(window) | ||
window.addEventListener('error', throwUnhandlerError) | ||
window.addEventListener = function (...args) { | ||
if (args[0] === 'error') { | ||
userErrorListenerCount++ | ||
} | ||
return addEventListener.apply(this, args) | ||
} | ||
window.removeEventListener = function (...args) { | ||
if (args[0] === 'error' && userErrorListenerCount) { | ||
userErrorListenerCount-- | ||
} | ||
return removeEventListener.apply(this, args) | ||
} | ||
return function clearErrorHandlers() { | ||
window.removeEventListener('error', throwUnhandlerError) | ||
} | ||
} | ||
|
||
function registerUnexpectedErrors() { | ||
catchWindowErrors(event => | ||
reportUnexpectedError('Error', event.error), | ||
) | ||
on('unhandledrejection', event => | ||
reportUnexpectedError('Unhandled Rejection', event.reason)) | ||
} | ||
|
||
async function reportUnexpectedError( | ||
type, | ||
error, | ||
) { | ||
const processedError = serializeError(error) | ||
await client.rpc.onUnhandledError(processedError, type) | ||
const state = __vitest_browser_runner__ | ||
|
||
if (state.type === 'orchestrator') { | ||
return | ||
} | ||
|
||
if (!state.runTests || !__vitest_worker__.current) { | ||
channel.postMessage({ | ||
type: 'done', | ||
filenames: state.files, | ||
id: state.iframeId, | ||
}) | ||
} | ||
} | ||
|
||
registerUnexpectedErrors() |
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
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
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
Oops, something went wrong.