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

Check mocha is installed (support monorepos), fix tests #10

Merged
merged 8 commits into from
Oct 2, 2023

Conversation

MisanthropicBit
Copy link
Collaborator

This should fix nvim-neotest/neotest#105.

Summary of changes:

  • Fixed a few types.
  • Refactored util.has_package_dependency.
  • Adapter.is_test_file now finds the root and checks if mocha is installed on each test file.
  • Updated the tests (let me know if I should add some more).

I tested on a monorepo with the following layout where app1/ has mocha installed and app2/ has jest installed. I do not use monorepos and have no experience with them so I hope this covers it.

monorepo-test/
└── apps
    ├── app1
    │   ├── node_modules
    │   ├── package-lock.json
    │   ├── package.json
    │   └── test
    │       └── app1.test.js
    └── app2
        ├── node_modules
        ├── package-lock.json
        ├── package.json
        └── test
            └── app2.test.js

Everything appears to work except that if I run the file or the single test as the first action, I get the following traceback:

Error executing vim.schedule lua callback: /Users/user/.vim-plug/neotest/lua/nio/tasks.lua:95: Async task failed without callback: The coroutine failed with this message:
/Users/user/.vim-plug/neotest/lua/nio/tasks.lua:95: Async task failed without callback: The coroutine failed with this message:
...vim-plug/neotest/lua/neotest/consumers/state/tracker.lua:47: attempt to index local 'tree' (a nil value)
stack traceback:
        ...vim-plug/neotest/lua/neotest/consumers/state/tracker.lua: in function 'is_test'
        ...vim-plug/neotest/lua/neotest/consumers/state/tracker.lua:155: in function 'update_running'
        ...r/.vim-plug/neotest/lua/neotest/consumers/state/init.lua:49: in function 'listener'
        ...ser/.vim-plug/neotest/lua/neotest/client/events/init.lua:51: in function <...ser/.vim-plug/neotest/lua/neotest/client/events/init.lua:47>
stack traceback:
        [C]: in function 'error'
        /Users/user/.vim-plug/neotest/lua/nio/tasks.lua:95: in function 'close_task'
        /Users/user/.vim-plug/neotest/lua/nio/tasks.lua:117: in function 'step'
        /Users/user/.vim-plug/neotest/lua/nio/tasks.lua:145: in function 'run'
        ...ser/.vim-plug/neotest/lua/neotest/client/events/init.lua:47: in function 'emit'
        ...user/.vim-plug/neotest/lua/neotest/client/state/init.lua:95: in function 'update_running'
        /Users/user/.vim-plug/neotest/lua/neotest/client/init.lua:82: in function 'run_tree'
        ...rs/user/.vim-plug/neotest/lua/neotest/consumers/run.lua:73: in function 'func'
        /Users/user/.vim-plug/neotest/lua/nio/tasks.lua:168: in function </Users/user/.vim-plug/neotest/lua/nio/tasks.lua:167>
stack traceback:
        [C]: in function 'error'
        /Users/user/.vim-plug/neotest/lua/nio/tasks.lua:95: in function 'close_task'
        /Users/user/.vim-plug/neotest/lua/nio/tasks.lua:117: in function 'cb'
        /Users/user/.vim-plug/neotest/lua/nio/tasks.lua:181: in function </Users/user/.vim-plug/neotest/lua/nio/tasks.lua:180>

This is the line where the tree is nil. I haven't been able to find an open/closed neotest issue that explains this.

I also get this traceback when using the upstream version of neotest-mocha so this might be a problem with what is passed to neotest or an issue with neotest itself. I do not get this issue with neotest-jest.

Strangely, if I open the summary before running the test, it runs as expected with no tracebacks...I'll try and spend some more time on the issue but it should not really be a blocker for this PR as the issue also exists in upstream neotest-mocha (at least on my machine).

@adrigzr adrigzr merged commit 68f0e97 into adrigzr:main Oct 2, 2023
3 checks passed
@adrigzr
Copy link
Owner

adrigzr commented Oct 2, 2023

Great job @MisanthropicBit! Thank you so much.

@MisanthropicBit MisanthropicBit mentioned this pull request Jul 19, 2024
1 task
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.

Support multiple runners for same test file
2 participants