-
Notifications
You must be signed in to change notification settings - Fork 138
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
Show jest tests which ran in the recording as console messages #5496
Conversation
This pull request is being automatically deployed with Vercel (learn more). 🔍 Inspect: https://vercel.com/recordreplay/devtools/7YM6NuK4pig8qBuv4h8CTkuvDPrJ |
✅ QA Wolf - PR deploymentSitka here: 29 tests ran, see details here. ✅ 29 pass |
This PR adds new functionality where on each recording we look for the jest test runner source "jest-circus/build/utils.js", and if found kick off some analyses to look for places where jest tests ran and failed. Tests and failure messages are added to the console. For failures, we're able to extract the full error message from the expect() module and include it in the console error, but only the first line of the message is shown and I'm not sure how to fix that. This and plenty of other refinements are definitely possible here, but this should be a good starting point. Replay of the new functionality in action: https://app.replay.io/recording/jest-tests--b5df685f-74c4-4f88-85f1-006944ca0193 |
async function setupJestTests(): Promise<JestTestState | null> { | ||
// Look for a source containing the callAsyncCircusFn function which is used to | ||
// run tests using recent versions of Jest. | ||
const circusUtilsSourceId = await findMatchingSourceId("jest-circus/build/utils.js"); |
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.
note that we might start bundling (jestjs/jest#12348) at which point at least the filename will break and possibly the function name (depending on sourcemaps).
Not sure how to handle that. It would be better to have a real hook for this (e.g. handleTestEvent
in the env?), but that might not be feasible - I have no idea how this project works.
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.
Definitely, the pattern matching on file names and code patterns in this PR is not robust at all, and longer term it would be great to have a way of identifying places where tests started and failed that doesn't rely on detecting these patterns. We have a mechanism to add annotations to a recording which could be used to find these points. It isn't currently exposed in node, but if it was we could have something like:
if (process.addRecordReplayAnnotations) {
process.addRecordReplayAnnotation("JestTestStart", { ...info about test... });
}
I don't know if it would be possible to use handleTestEvent
for this --- we would need these annotations to be as close as possible to where the test starts running, so we can find the entry point to the test function which was passed in. Right now we pattern match to detect the calls to the test function, and then step in to each of those calls to find the point to jump to when someone clicks on that test.
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.
We have --testLocationInResults
. Would that be enough? I would assume that info is also included in a handleTestEvent
call, but I haven't verified. In that case you can at the very least point to where the test function is
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 think that would be enough. If the test event callback is notified about every test, and has the name of that test, the file/line/column of the test callback, and whether the test passed, that should be enough information to reconstruct everything we're getting from the pattern matching we're doing. The test callback would call process.addRecordReplayAnnotation with this information, and then the devtools can read that from the recording and use it to figure out where the tests ran.
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.
Yeah, its called when test is declared, execution starts, execution enda etc. I'm not 100% sure the location info is present for all cases, but if not we can probably fix that
WIP for https://github.com/RecordReplay/devtools/issues/5439
This identifies the jest tests in a recording and adds console messages for each of them, which can be clicked on to jump to the start of the test. This still needs to deal with test failures.