connorshea / vscode-ruby-test-adapter

A Ruby test adapter extension for the VS Code Test Explorer
https://marketplace.visualstudio.com/items?itemName=connorshea.vscode-ruby-test-adapter
MIT License
83 stars 50 forks source link

`vscode:minitest:list` -> TypeError: no implicit conversion of nil into Integer #99

Closed nadnoslen closed 1 year ago

nadnoslen commented 2 years ago

Your environment

Expected behaviour

Typically a few seconds pass and my tests load. When they don't it is usually because I have a rake error...e.g. my postgres container isn't running the app's database. At this point I'd start the database and perform a VS Code Developer: Reload Window.

Actual behaviour

In my case, I have two separate Rails applications who are suddenly failing to list tests even when everything seems to be working. I do have some rake noise where some Ruby/Rails trace/deprecation messages are appearing but they are in no way producing a non-zero error code preventing the vscode:minitest:list command from succeeding.

Here are the log messages from the extension; note the no implicit conversion of nil into Integer ... I'm seeing this in multiple projects.

[2022-07-12 20:24:25.727] [INFO] Getting a list of Minitest tests in suite with the following command: DISABLE_SPRING=1 PARALLEL_WORKERS=1 ./bin/rake -R $EXT_DIR vscode:minitest:list
[2022-07-12 20:24:25.727] [INFO] Initialization finished
[2022-07-12 20:24:30.287] [ERROR] Error while finding Minitest test suite: Command failed: DISABLE_SPRING=1 PARALLEL_WORKERS=1 ./bin/rake -R $EXT_DIR vscode:minitest:list
... (I have some deprecation messages from rails here BUT nothing generating an error code) ... 
rake aborted!
TypeError: no implicit conversion of nil into Integer
/Users/.../.vscode/extensions/connorshea.vscode-ruby-test-adapter-0.9.0/ruby/vscode/minitest/tests.rb:33:in `block in build_list'
/Users/.../.vscode/extensions/connorshea.vscode-ruby-test-adapter-0.9.0/ruby/vscode/minitest/tests.rb:32:in `map'
/Users/.../.vscode/extensions/connorshea.vscode-ruby-test-adapter-0.9.0/ruby/vscode/minitest/tests.rb:32:in `build_list'
/Users/.../.vscode/extensions/connorshea.vscode-ruby-test-adapter-0.9.0/ruby/vscode/minitest/tests.rb:9:in `all'
/Users/.../.vscode/extensions/connorshea.vscode-ruby-test-adapter-0.9.0/ruby/vscode/minitest.rb:25:in `list'
/Users/.../.vscode/extensions/connorshea.vscode-ruby-test-adapter-0.9.0/ruby/vscode.rake:8:in `block (3 levels) in <main>'
Tasks: TOP => vscode:minitest:list
(See full trace by running task with --trace)
SergeyBurtsev commented 2 years ago

The problem is that vscode:minitest:list tries to get list of defined tests calling Minitest::Test.runnable_methods, which depends on seed for random shuffling. If seed is nil srand throws an exception. Usually Minitest sets seed when CLI options parsed, but that step is skipped here.

My simple workaround is to ensure that seed is set in test_helper.rb

Minitest.seed ||= 0

nadnoslen commented 2 years ago

Get the heck out of here @SergeyBurtsev!!! That's awesome. Thank you for the tip. I'll try it out immediately!!

connorshea commented 1 year ago

Released a new version of the extension with this fix, thanks :)