Search code examples
javascriptsonarqubesurefiresonar-runnerjs-test-driver

Is it a bug in SonarQube's JavaScript plugin that it doesn't pick up Surefire test results of tests that are in a subdirectory?


I have a Surefire results directory with 2 files: TEST-Chrome_4202311135_Windows.dashboard.MonkeyTest.xml and TEST-Chrome_4202311135_Windows.PersonTest.xml. Thus, my tests have the following directory structure:

-tests
    -PersonTest.js
    -dashboard
        -MonkeyTest.js

When I run Sonar Runner it picks up PersonTest.js but it says that dashboard/MonkeyTest.js doesn't exist:

18:24:58.747 WARN  - Test result will not be saved for test class "dashboard.MonkeyTest", because SonarQube associated resource has not been found using file name: "dashboard/MonkeyTest.js"

Has anybody encountered this? Looks to me like a bug because the file is there.


Solution

  • Well, I've delved into the SonarQube's JavaScript Plugin code to debug it. Found the bug. Looks like this bug only happens on Windows. What the code does is iterates over all the test files, in my case "PersonTest.js" and "dashboard/MonkeyTest.js", and looks for the file "dashboard\MonkeyTest.js". But because "dashboard/MonkeyTest.js" does not equal to "dashboard\MonkeyTest.js" it ignores the results of this test. To be honest iterates over ALL the test files for every test result is inefficient to begin with. Below is the Java method. I'll try to get in contact with the author.

    protected InputFile getTestFileRelativePathToBaseDir(String fileName) {
        for (InputFile inputFile : fileSystem.inputFiles(testFilePredicate)) {
    
          LOG.warn("Slava: '" + inputFile.file().getAbsolutePath() + "'");
    
          if (inputFile.file().getAbsolutePath().endsWith(fileName)) {
            LOG.debug("Found potential test file corresponding to file name: {}", fileName);
            LOG.debug("Will fetch SonarQube associated resource with (logical) relative path to project base directory: {}", inputFile.relativePath());
            return inputFile;
          }
        }
        return null;
    }