0

I need your help/guidance about one problem I have for the last two days.

The sonar-javascript plugin is not able to get the results of my Javascript UnitTests. I am generating unit tests and lcov results using JSTestDriver. The lcov results are working and are correctly shown in SonarQube. I also have to say that I am using Windows. Here is the error I have:

Test result will not be saved for test class "UnitTests.controlesTest", because SonarQube associated resource has not been found using file name: UnitTests\controlesTest.js"

The error is very similar to this one: Importing javascript XML JUnit tests to sonar using jstestdriver fails. However, this error seems to be fixed in the last SNAPSHOT (2.8). The file I am trying to access is stored in UnitTests/controlesTest.js. I tried to go into the sonar-javascript source, and find a way to correct this issue (at least, try to understand it). I ended up in the file JsTestDriverSensor.java in the function getTestFileRelativePathToBaseDir. I found that this line is not able to get my file (UnitTests\controles.js). Actually, fileIterator does not contain any InputFile.

    Iterator<InputFile> fileIterator = fileSystem.inputFiles(predicate).iterator();

So I tried different predicates to understand why my file is not found. At the end, I found that the following predicate fileSystem.predicates().hasType(InputFile.Type.TEST) is the reason why this file is not found. A quick fix is to change:

- 108             testFilePredicate,
+ 108             mainFilePredicate,

I must be doing something wrong, maybe someone has an idea ?

Community
  • 1
  • 1
Julien D.
  • 58
  • 1
  • 7
  • 1
    Nice investigation! Indeed the JavaScript Plugin is assuming that the test results are associated to test files, so it is seeking files from test sources only. Could you provide the content of your sonar-project.properties file please ? Your test directories should be set through "sonar.tests" property, see an example [here](https://github.com/SonarSource/sonar-examples/blob/master/projects/languages/javascript/javascript-sonar-runner-JsTestDriver/sonar-project.properties#L10) – Linda - SonarSource Team Aug 18 '15 at 06:53
  • Oh ! So that's what testFilePredicate means. My "sonar.tests" is not set, so this was the problem. Maybe you can add this information on your [JavaScript Unit Tests Execution Reports Import](http://docs.sonarqube.org/display/PLUG/JavaScript+Unit+Tests+Execution+Reports+Import) documentation page ? Merci beaucoup – Julien D. Aug 18 '15 at 13:08
  • Documentation update. Thanks for your feedback! – Linda - SonarSource Team Aug 19 '15 at 07:59

1 Answers1

2

The "sonar.tests" property has to be set in the sonar-project.properties (or in newer version SonarQube.Analysis.xml). This allows the sonar-javascript plugin to find the javascript test files.

Julien D.
  • 58
  • 1
  • 7