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

Jest test finder can get misled by irrelevant "describe" blocks #16

Merged
merged 1 commit into from
Oct 21, 2023

Conversation

johannes-mueller
Copy link
Owner

@johannes-mueller johannes-mueller commented Oct 21, 2023

Thanks @ktfleming for reporting this. Sorry, I accidentally transformed the issue you reported into a pull request. But anyway. This PR seems to fix it.

Hey, I'm really finding this package useful, thanks for creating it!

I've found that (test-cockpit-npm-jest--find-current-test) doesn't handle the following case:

describe("outer", () => {
  describe("middle", () => {
  });

  it("foo", async () => {
    expect(2).toBe(2); // HERE
  });
});

If I put point on the line marked // HERE and evaluate (test-cockpit-npm-jest--find-current-test), the output is "middle foo", rather than the expected "outer foo". It seems that it's looking for the closest preceding "describe" via search-backward-regexp, rather than looking for the "describe" that contains the test at point.

I do see you have an open issue #7 for looking into tree-sitter which I imagine could help with this by allowing you to look at only the parent node of the current node.

@johannes-mueller johannes-mueller merged commit 98a15ab into master Oct 21, 2023
5 checks passed
@ktfleming
Copy link
Author

@johannes-mueller It's working for me, thanks so much for the quick fix!

@johannes-mueller johannes-mueller deleted the irrelevant-descripe-section branch October 22, 2023 21:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants