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

treesitter missing tests in summary/status #110

Open
conermurphy opened this issue Mar 28, 2024 · 0 comments
Open

treesitter missing tests in summary/status #110

conermurphy opened this issue Mar 28, 2024 · 0 comments

Comments

@conermurphy
Copy link
Contributor

First of all I appreciate this is a bit of a niche configuration but wanted to raise an issue to see if anyone had any advice for fixing it as I tried looking into it but was unsuccessful.

In a project I work in, we have a series of tests that test different API endpoints and in these test suites we have multiple describe blocks, one of which is returned from a function that conditionally runs tests (see example below). The issue is that as far as I can tell treesitter will only parse the text in the file itself, it won't evaluate any functions in the file to see what they return and whether that can be a test or not which leads to tests being missed in the discovery window / test statuses in the gutter.

Example implementation below:

// foo.test.js
import {functionReturnsTests} from './test-generator.js';

describe('Foo Test', () => {
   describe('Describe One', () => {
        it('runs some test', () => {});
    });
    
    functionReturnsTests({runTestOne: true, runTestTwo: false});
}
// test-generator.js

function testOne() {
   return  it('runs a test', () => {});
}

function testTwo() {
   return  it('runs a second test', () => {});
}

export function functionReturnsTests({runTestOne, runTestTwo}) {
   return describe('Describe Two', () => {
       if (runTestOne) testOne();
       if (runTestTwo) testTwo();
   });
}

In this example I would expect the discovery panel to look like the below.

- foo.test.js
   - Foo Test
       -  Describe One
          - runs some test
       - Describe Two
          - runs a test

But at the moment I'm only seeing the below.

- foo.test.js
   - Foo Test
       -  Describe One
          - runs some test

As mentioned I did some digging into this to try see what the issue could be and found that the tests are being run by neotest as when I checked the output files in the var directory I could see the results of the tests from the imported function. These tests are also correctly found by the jest CLI which is why I imagine they run correctly through neotest so it appears the issue is just in the project summary / discovery as well as in the pass/fail/in-progress symbols in the gutter.

It's worth noting that these tests are correctly identified and ran with status symbols in VSCode with the Jest extension so I believe this issue is related to neotest.

Someone more experienced with Neovim/treesitter might have a better idea of how to fix this but my original thinking was to somehow build the tests file out into a single file that contains all of the imported code and then run treesitter against that to correctly identify the imported code but I imagine this could get quite time consuming / costly when run at scale which isn't ideal.

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

No branches or pull requests

1 participant