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
85 stars 52 forks source link

Rspec: Passing test not being marked green (remote) #114

Open patrickdavey opened 1 year ago

patrickdavey commented 1 year ago

Your environment

Expected behavior

Running a test remotely which passes the test (as seen in the logs and running it directly) does not result in a green icon in the tree.

Actual behavior

I am running a single test using the explorer. After running the test the icon is gray. I can see the test outputs:

START_OF_TEST_JSON{"version":"3.11.0","messages":["Run options: include {:locations=>{\"/FOO/BAR/spec/models/admin_maintenance_file_spec.rb\"=>[7]}}"],"seed":32808,"examples":[{"id":"/FOO/BAR/spec/models/admin_maintenance_file_spec.rb[1:1:1]","description":"must have a user","full_description":"AdminMaintenanceFile validations must have a user","status":"passed","file_path":"/FOO/BAR/spec/models/admin_maintenance_file_spec.rb","line_number":7,"type":"model","pending_message":null}],"summary":{"duration":2.648112224,"example_count":1,"failure_count":0,"pending_count":0,"errors_outside_of_examples_count":0},"summary_line":"1 example, 0 failures"}END_OF_TEST_JSON

But, this seemingly is not parsed correctly back into the UI.

One possible/probable factor is that I am running this in a remote developing extension. Apologies if this is not an issue with this extension, I am a relative newbie to vscode!

Console log

I can also see this in the logs (which seems like it is parsing it correctly)

[DEBUG] {"version":"3.11.0","messages":["Run options: include {:locations=>{\"/FOO/BAR/spec/models/admin_maintenance_file_spec.rb\"=>[7]}}"],"seed":53589,"examples":[{"id":"/FOO/BAR/spec/models/admin_maintenance_file_spec.rb[1:1:1]","description":"must have a user","full_description":"AdminMaintenanceFile validations must have a user","status":"passed","file_path":"/FOO/BAR/spec/models/admin_maintenance_file_spec.rb","line_number":7,"type":"model","pending_message":null}],"summary":{"duration":2.367175155,"example_count":1,"failure_count":0,"pending_count":0,"errors_outside_of_examples_count":0},"summary_line":"1 example, 0 failures"}

DylanEtris commented 7 months ago

I'm also seeing this behavior

DylanEtris commented 7 months ago

After some playing around, I noticed that running the full test suite correctly updates the badges, but running a single spec file or example does not.

In Tests#runNode, the testStatesEmitter fires the "test running" event with node.id which is the relative path to the spec. In the second branch (when a spec file is run) and the fourth branch (when a single example is run), the testStatesEmitter fires the "test passed/failed" event with the absolute path to the spec, which it parses from the JSON.

I hacked my installation to fire the "test passed/failed" with the relative path, and the badges were updated. So, I think the solution here lies in figuring out why the output JSON has relative paths when running every spec file, but absolute paths when running a single spec file.

DylanEtris commented 7 months ago

I can think of two solutions, without digging further:

  1. Update the initialization of node to use a relative path. This might have side-effects, because that attribute is used in multiple places
  2. Update Tests#runNode to remove the workspace path before calling rspec in the second and fourth branches.
  3. Store the relative path in node and use that in branch two and four.
DylanEtris commented 7 months ago

It looks like there's a pretty big rewrite of this repo though, so I don't know if a PR on this issue is very useful: #90