-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
test(jest): Use jest-circus
and instrument jest tests
#22237
Merged
billyvg
merged 8 commits into
getsentry:master
from
billyvg:build/jest/add-perf-timings
Nov 30, 2020
Merged
test(jest): Use jest-circus
and instrument jest tests
#22237
billyvg
merged 8 commits into
getsentry:master
from
billyvg:build/jest/add-perf-timings
Nov 30, 2020
Conversation
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
billyvg
commented
Nov 23, 2020
Comment on lines
+1
to
+258
if (parent && !Array.isArray(parent)) { | ||
return parent.child(span); | ||
} else if (Array.isArray(parent)) { | ||
return parent.find(isNotTransaction).child(span); | ||
} | ||
return span; | ||
}, | ||
}; | ||
|
||
case 'start_describe_definition': | ||
case 'finish_describe_definition': | ||
case 'add_test': | ||
case 'add_hook': | ||
case 'run_start': | ||
case 'run_finish': | ||
case 'test_todo': | ||
case 'setup': | ||
case 'teardown': | ||
return null; | ||
|
||
default: | ||
return null; | ||
} | ||
} | ||
|
||
handleTestEvent(event) { | ||
if (!this.Sentry) { | ||
return; | ||
} | ||
|
||
const data = this.getData(event); | ||
const {name} = event; | ||
|
||
if (!data) { | ||
return; | ||
} | ||
|
||
const {obj, parentObj, dataStore, parentStore, op, description, beforeFinish} = data; | ||
|
||
const testName = this.getName(obj); | ||
|
||
if (name.includes('start')) { | ||
// Make this an option maybe | ||
if (!testName) { | ||
return; | ||
} | ||
|
||
const spans = []; | ||
const parentName = parentObj && this.getName(parentObj); | ||
const spanProps = {op, description: description || testName}; | ||
const span = | ||
parentObj && parentStore.has(parentName) | ||
? Array.isArray(parentStore.get(parentName)) | ||
? parentStore | ||
.get(parentName) | ||
.map(s => | ||
typeof s.child === 'function' | ||
? s.child(spanProps) | ||
: s.startChild(spanProps) | ||
) | ||
: [parentStore.get(parentName).child(spanProps)] | ||
: [this.transaction.startChild(spanProps)]; | ||
|
||
spans.push(...span); | ||
|
||
// If we are starting a test, let's also make it a transaction so we can see our slowest tests | ||
if (spanProps.op === 'test') { | ||
spans.push( | ||
Sentry.startTransaction({ | ||
...spanProps, | ||
op: 'jest test', | ||
name: spanProps.description, | ||
description: null, | ||
}) | ||
); | ||
} | ||
|
||
dataStore.set(testName, spans); | ||
|
||
return; | ||
} | ||
|
||
if (dataStore.has(testName)) { | ||
const spans = dataStore.get(testName); | ||
|
||
spans.forEach(span => { | ||
if (beforeFinish) { | ||
span = beforeFinish(span); | ||
if (!span) { | ||
throw new Error('`beforeFinish()` needs to return a span'); | ||
} | ||
} | ||
|
||
span.finish(); | ||
}); | ||
} | ||
} | ||
} | ||
|
||
module.exports = SentryEnvironment; |
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.
@HazAT This might be interesting to do as an independent package.
scttcper
approved these changes
Nov 24, 2020
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.
this is really neat, would like to see this as a node module
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
This changes to use the new jest test runner: jest-circus and adds Sentry instrumentation to our test runs. You can view the transactions here: https://sentry.io/organizations/sentry/performance/?project=4857230