-
Notifications
You must be signed in to change notification settings - Fork 42
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[WIP] Jest globals 2 #65
Open
andrewiggins
wants to merge
11
commits into
jest-globals
Choose a base branch
from
jest-globals-2
base: jest-globals
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
39b3ed7
=== BEGIN jest-globals-2 === Upgrade chalk to reduce dupes
andrewiggins 6d3e4c4
Add --skip-install flag to e2e script
andrewiggins 8c4f7c5
Build jest-globals.js separately to target web; add test to verify it…
andrewiggins ccc5549
Expose expect through jest globals file
andrewiggins 76d55de
Upgrade expect; bundle jest globals using microbundle
andrewiggins 9022665
Bundle jest globals through webpack
andrewiggins 219a90a
Revert "Bundle jest globals through webpack"
andrewiggins d7431ea
Add jest-mock with tests from Jests
andrewiggins fe17dd2
WIP: Add initial timer implementation
andrewiggins de82dca
Replace copy of fakeTimers.js with ModernFakerTimers import
andrewiggins e4b5837
WIP: Add fakeTimers tests
andrewiggins File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Upgrade expect; bundle jest globals using microbundle
- Loading branch information
commit 76d55de37df8ce810fe7761ef201c01b45cef6ab
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
// As of writing, the [jest-message-util] package has a dependency on graceful-fs | ||
// to read file contents mentioned in the stack trace to produce code frames for | ||
// errors. Since this module is running in the browser and not in Node, we'll | ||
// mock out this module for now so `expect` (and other Jest packages) can run in | ||
// the browser. Karmatic adds code frames when errors are reported from the | ||
// browser to the Karma server which has file system access to add code frames. | ||
// | ||
// jest-message-util: | ||
// https://npmfs.com/package/jest-message-util/26.3.0/package.json#L20 | ||
|
||
// Based on https://github.com/facebook/jest/blob/c9c8dba4dd8de34269bdb971173659399bcbfd55/packages/jest-message-util/src/index.ts | ||
|
||
/** | ||
* @param {Error} error | ||
* @returns {string} | ||
*/ | ||
export function formatExecError(error) { | ||
return error.stack; | ||
} | ||
|
||
/** | ||
* @param {string} stack | ||
* @returns {string[]} | ||
*/ | ||
export function getStackTraceLines(stack) { | ||
return stack.split(/\n/); | ||
} | ||
|
||
/** | ||
* @param {string[]} lines | ||
* @returns {Frame} | ||
*/ | ||
export function getTopFrame(lines) { | ||
throw new Error('Not implemented: messageUtilFake.js:getTopFrame'); | ||
} | ||
|
||
/** | ||
* @param {string} stack | ||
* @returns {string} | ||
*/ | ||
export function formatStackTrace(stack) { | ||
return stack; | ||
} | ||
|
||
export function formatResultsErrors() { | ||
throw new Error('Not implemented: messageUtilsFake.js:formatResultsErrors'); | ||
} | ||
|
||
const errorRegexp = /^Error:?\s*$/; | ||
|
||
/** @type {(str: string) => string} */ | ||
const removeBlankErrorLine = (str) => | ||
str | ||
.split('\n') | ||
// Lines saying just `Error:` are useless | ||
.filter((line) => !errorRegexp.test(line)) | ||
.join('\n') | ||
.trimRight(); | ||
|
||
/** | ||
* @param {string} content | ||
* @returns {{ message: string; stack: string; }} | ||
*/ | ||
export function separateMessageFromStack(content) { | ||
if (!content) { | ||
return { message: '', stack: '' }; | ||
} | ||
|
||
// All lines up to what looks like a stack -- or if nothing looks like a stack | ||
// (maybe it's a code frame instead), just the first non-empty line. | ||
// If the error is a plain "Error:" instead of a SyntaxError or TypeError we | ||
// remove the prefix from the message because it is generally not useful. | ||
const messageMatch = content.match( | ||
/^(?:Error: )?([\s\S]*?(?=\n\s*at\s.*:\d*:\d*)|\s*.*)([\s\S]*)$/ | ||
); | ||
if (!messageMatch) { | ||
// For typescript | ||
throw new Error('If you hit this error, the regex above is buggy.'); | ||
} | ||
const message = removeBlankErrorLine(messageMatch[1]); | ||
const stack = removeBlankErrorLine(messageMatch[2]); | ||
return { message, stack }; | ||
} |
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,10 @@ | ||
// As of writing, the [jest-matcher-utils] package expects there to be a | ||
// `Buffer` global available. It only uses its constructor, and doesn't | ||
// instantiate or call any methods off of it. So for browsers, we are just gonna | ||
// create a `Buffer` global that maps to a Uint8Array since that is the closest | ||
// browser primitive that matches Buffer | ||
// | ||
// [jest-matcher-utils]: | ||
// https://npmfs.com/package/jest-matcher-utils/26.4.0/build/deepCyclicCopyReplaceable.js#L16 | ||
|
||
window.Buffer = Uint8Array; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I'm bundling
jest-globals.js
separately at build time to avoid our users having to re-bundle all the jest stuff on each run of karmatic. Probably need to move some of these deps intodevDeps
since they are bundled. Or maybe move them tobundledDeps
?Also need to figure out/fix how to specify aliases in microbundle so that it doesn't require absolute paths