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

Unable to resolve non-existing file #7

Closed
polortiz4 opened this issue Dec 31, 2020 · 14 comments
Closed

Unable to resolve non-existing file #7

polortiz4 opened this issue Dec 31, 2020 · 14 comments
Labels
bug Something isn't working

Comments

@polortiz4
Copy link

polortiz4 commented Dec 31, 2020

So I'm enjoying this extension and currently have only one issue with it:

My file structure is

root
|_src
  |_main
  |   |_java
  |     |_my
  |       |_package
  |          |_Thing.java
  |_test
      |_java
        |_my
          |_package
             |_ThingTest.java

(among other, likely irrelevant, stuff)

Even though koverage correctly identifies the test coverage, when trying to open the source file from the koverage explorer, I can see the extension attempts to open "root/my/package/Thing.java" instead of "root/src/main/java/my/package/Thing.java"
Is there a way to fix this so koverage knows the correct absolute path to my file?

@tenninebt
Copy link
Owner

tenninebt commented Jan 2, 2021

@polortiz4 Hey, I need to have a look in details. There is some assumptions on how the file path are specified in the coverage file. Could you send me an extract of a coverage file on a project where you are using that hierarchy?

@polortiz4
Copy link
Author

Sorry, I just saw you replied to me. I'll try to replicate the issue and send you the file (I've switched systems since last time)

@polortiz4
Copy link
Author

jacocoTestReport.xml.txt

@elbeshenrique
Copy link
Contributor

Maybe the fix is in this file/line. I changed it and worked for me, on Windows.

src/files-loader.ts
line 34

From:
const coverageFileFullPath = iopath.join(workspaceFolder.uri.path, filePath, fileName);
image

To:
const coverageFileFullPath = iopath.join(workspaceFolder.uri.fsPath, filePath, fileName);
image

@tenninebt
Copy link
Owner

@elbeshenrique Had a look, that fix is probably going to fix some bugs (UNC paths and similar...) but won't fix the issue here.
The part of the path "src/main/java" is neither in the Jacoco coverage file nor in the workspace points to root. I have no idea for now how to fix this properly. @polortiz4 can you share a full folder with the sources, which plugin you use to run the tests and generate the report? (Or command line if you do it using command line). The fix might in the way the report is generated.

Have a look at the first screenshot which is an extract from the jacoco file and then you can see the watch on the left with the result how the data is read. (src/main/java could be src/main/java/example/example2/... or shorter, meaning if it is not present the jacoco, I can't see how we can "guess" it)
jacoco_xml_screenshot
debug_screenshot

Thanks all for your help.

@polortiz4
Copy link
Author

try-vscode.zip
Sorry again, I forgot to upload this after you requested it.

@tenninebt
Copy link
Owner

Thanks, that helps a lot. Actually I realised it is a common issue with Jacoco and Java. I had a look at https://github.com/ryanluker/vscode-coverage-gutters and realised they had to do file matching when trying to bind the coverage to the file open in the text editor. They probably realised those file path issues which might exist in different environments. In any case, I implement a similar fix, much simpler and tests are ongoing. I will build a version for you and share it here to be tested when you have time/chance.
Thanks for your contributions.

@tenninebt
Copy link
Owner

@polortiz4 Sorry for delay, life kept me really busy. I published the extension to the market place with the fix. Could you test and confirm it is fixed?

@neirupr
Copy link

neirupr commented Dec 27, 2021

Hello!

I am facing the same issue. My project structure is:

root
|
|_ appLibrary - test
|
|_ demoApp

They are separate projects, I am building a library which is in appLibrary (the one I want to test) and a demoApp which is just going to consume for viewing purposes only.

I added flutter-coverage.coverageFilePaths = ["appLibrary/coverage"] in order for the plugin to recognize only test files in appLibrary. But when I take a look on the coverage tree it displays like this:

root
|
|_ lib _ (inner folders), which of course don't exist.

@tenninebt
Copy link
Owner

@neirupr Hi, can you send me a zip with a sample project having the same issue? What version do you have?
Thanks for the feedback

@neirupr
Copy link

neirupr commented Jan 5, 2022

@tenninebt

Attaching the whole project. Inside it you need to run
$ cd demo
then
$ flutter test --coverage

When you watch the coverage tree you will face the error when you click over any of the source files in that tree. I think it happens because demo project is not located directly in the root but in a subfolder. I think a good solution would be to make the path relative to value specified in "flutter-coverage.coverageFilePaths" in settings.json which you will also find in the root project.

demo.zip

@tenninebt
Copy link
Owner

tenninebt commented Jan 6, 2022

Hi @neirupr, I will have a look in details, but as a workaround, when you have multiple projects inside your root, create a Workspace and it should work better. I use the workspace to locate folders as of now when you have more than a project in your root.

You can start with an empty VSCode window, then, File>Add Folder to Workspace and select demo. Do the same for your second folder which is demo_consumer, then File>Save Workspace As and save your workspace. Try this and let me know if it works for you, until I have a more permanent fix. (Check the zip below, contains your example but with a vscode workspace and in VScode, just do File>Open Workspace from File and select "demo.code-workspace")

As I explained before, depending on the test framework, the file path inside the coverage files are not always relative to the project root, so I had to workaround it trying to match files from the workspace to paths on the coverage file. I can't use the coverage path can not be a "reference".

demo.zip

@tenninebt tenninebt added the bug Something isn't working label Jan 8, 2022
@tenninebt
Copy link
Owner

I had a look, and I'm not sure there is a proper way to do it. The issue here is that you are running your flutter test command from a different "root" than your VSCode workspace "root". @neirupr check my previous suggestion and tell me if that works out for you.
I will consider this issue resolved if no new from @polortiz4 in the next week.
Thanks

@default-writer
Copy link

#19

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants