adrigzr / neotest-mocha

Neotest runner for Mocha test framework
10 stars 9 forks source link

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

Closed MisanthropicBit closed 1 year ago

MisanthropicBit commented 1 year ago

This should fix nvim-neotest/neotest#105.

Summary of changes:

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 commented 1 year ago

Great job @MisanthropicBit! Thank you so much.