Skip to content
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] Initial support for passing back fixits with --json #5718

Closed
wants to merge 1 commit into from
Closed

Conversation

orta
Copy link
Member

@orta orta commented Mar 4, 2018

Summary

I'd like the Jest runner to provide enough information so that jest-editor-support or a watcher plugin could provide an implementation of a fixit. Re: #4442

So for this test:

it('!!!!!!!!!', () => {
  expect(1).toEqual(2);
});

It would result in this JSON:

{
  ...
  "testResults": [
    {
      "assertionResults": [
        {
          "ancestorTitles": [],
          "failureMessages": [
            "Error: ..."
          ],
          "fixits": [
            {
              "expected": {"value": 1},
              "message": "Update value from ${received} to ${expected}",
              "received": {"value": 2},
              "type": "number"
            }
          ],
          "fullName": "!!!!!!!!!",
          "location": null,
          "status": "failed",
          "title": "!!!!!!!!!"
        }
      ],
      "endTime": 1520173114536,
      "message":"...",
      "name":
        "/Users/orta/dev/projects/jest/jest2/packages/expect/src/fixits/__tests__/to_equal.test.js",
      "startTime": 1520173114238,
      "status": "failed",
      "summary": ""
    }
  ],
  "wasInterrupted": false
}

Things that are still a bit ambiguous

The data here is going to need to be enough to have an AST runner dig through the tree to find the right expect and subsequent assertion.

So in this case:

  • Look for the test/it with the same name
  • Loop through all the matchers in that test for the one with the same name
  • Look at the matcher's parameters to see if there's a number primitive e.g. 1 not a variable
  • Use that to offer a way to edit the source code

I feel like the fixit should probably include the matcher name, and maybe I could even include the first line of the error'd stack trace in there to provide a way to verify that the change is on the right one

{
  "expected": {"value": 1},
  "message": "Update value from ${received} to ${expected}",
  "received": {"value": 2},
  "type": "number",

  "matcher": "toEqual"
  "line": 231
}

Test plan

Would like to add an integration test to verify the whole system

@SimenB
Copy link
Member

SimenB commented Apr 14, 2018

We have the stack of all expects seeing as they work by throwing. Only issue with that is potentially sourcemaps.
I'm quite excited by the possibilities here :)

@orta orta mentioned this pull request Jun 2, 2018
10 tasks
@SimenB
Copy link
Member

SimenB commented Aug 15, 2018

@orta can we close this seeing as inline snapshots are merged? Or do you still want this?

@SimenB
Copy link
Member

SimenB commented Sep 17, 2018

Inline snapshots are good for this. We can revisit later if we want to extend the functionality for toBe, toEqual etc

@SimenB SimenB closed this Sep 17, 2018
@SimenB SimenB deleted the fixits branch December 18, 2018 09:30
@github-actions
Copy link

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 12, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants