olimorris / neotest-phpunit

🧪 Neotest adapter for PHPUnit
MIT License
29 stars 22 forks source link

Fix docker path #18

Closed eerison closed 5 months ago

eerison commented 10 months ago

Close #11

eerison commented 10 months ago
Screenshot 2023-11-14 at 16 09 14

I am investigating why test is passing and it is red on the left side (🔴 )

eerison commented 10 months ago

Hey @olimorris

when I run the tests I can see this error in neotest.log

ERROR | 2023-11-14T17:25:13Z+0100 | ...e/nvim/lazy/neotest-phpunit/lua/neotest-phpunit/init.lua:126 | No test output file found: var/nvim/phpunit.output

do you have any idea why?

Note: this folder is visible into the container and host Note 2: I guess it is still saving in the old path 🤔 Note 3: this phpunit.output, should it be a file or folder? in theory it should be generated automatically, shouldn't it? if yes it hasn't created 🤔

olimorris commented 10 months ago

@eerison thanks for your work on this, looks really promising. Off the top of my head, I have no idea but will see if I can take a look in the coming weeks.

eerison commented 10 months ago

Ok just a update, the file is created into the folder, then the problem is when it is loaded.

probably it is getting from old path

Note 1: Ok the file is created in container and host, But I saw that output file it is adding full path file="/app/test/...

eerison commented 10 months ago

Ok just a update, the file is created into the folder, then the problem is when it is loaded.

probably it is getting from old path

Note 1: Ok the file is created in container and host, But I saw that output file it is adding full path file="/app/test/...

well I guess it is the issue, when I run test with relative path it create the output file with full path :'( https://github.com/infection/infection/issues/1329

eerison commented 9 months ago

Hey @olimorris do you remember where this icon is handled?

foobar1643 commented 9 months ago

If we're at the point of parsing test results (NeotestAdapter.results function), you can use a regular expression to replace the path prefix:

function escape_pattern(target)
    return target:gsub("(%W)", "%%%1")
end

function NeotestAdapter.results(test, result, tree)
  local output_file = test.context.results_path

  local ok, data = pcall(lib.files.read, output_file)
  if not ok then
    logger.error("No test output file found:", output_file)
    return {}
  end

  data = data:gsub(escape_pattern("/app"),  escape_pattern(local_root_dir))

  local ok, parsed_data = pcall(lib.xml.parse, data)
  ...

This code replaces all occurences of /app (location of the project inside a container) with local_root_dir which is the result of NeotestAdapter.root function.

I made this as a quick-fix solution in my fork of this plugin and it has been working successfully for a couple of months now. There's probably more efficient way around escaping/replacing stuff but I don't have the time to look into it at the moment.