How to configure test file xml in sonarqube? - javascript

I use sonarqube for JS Project, I would like to integrate the XML result for the unit test. I have this error :
ERROR: Caused by: Line 2 of report refers to a file which is not configured as a test file: modules/project/projectTest.js
I don't understand why this error is here.
The projectTest file get analysed, do I need to set something so that sonarqube can handle them as test files.
My XML result file :
<testExecutions version="1">
<file path="modules/proejct/projectTest.js">
<testCase name="Test" duration="16"/>
</file>
</testExecutions>
Thank you for your hlep

Files referenced in your unit test report need to be test files, in other words they should be configured by sonar.tests property. See docs https://docs.sonarqube.org/display/SONAR/Analysis+Parameters

Related

On running sonar analysis on react-native project getting error related to sonar.java.binaries property

I have a react-native project written in JavaScript for which I'm trying to run the sonar-analysis.
I have a sonar server set-up for this and system where I'm trying to run the analysis has Sonar-scanner, npm and all other project dependencies installed.
However, When I run the sonar analysis on the react-native project I'm getting following error:
ERROR: Error during SonarQube Scanner execution
org.sonar.squidbridge.api.AnalysisException: Please provide compiled classes of your project with sonar.java.binaries property
at org.sonar.java.JavaClasspath.init(JavaClasspath.java:59)
at org.sonar.java.AbstractJavaClasspath.getElements(AbstractJavaClasspath.java:281)
at org.sonar.java.SonarComponents.getJavaClasspath(SonarComponents.java:141)
at org.sonar.java.JavaSquid.<init>(JavaSquid.java:83)
at org.sonar.plugins.java.JavaSquidSensor.execute(JavaSquidSensor.java:83)
at org.sonar.scanner.sensor.SensorWrapper.analyse(SensorWrapper.java:53)
at org.sonar.scanner.phases.SensorsExecutor.executeSensor(SensorsExecutor.java:88)
at org.sonar.scanner.phases.SensorsExecutor.execute(SensorsExecutor.java:82)
at org.sonar.scanner.phases.SensorsExecutor.execute(SensorsExecutor.java:68)
at org.sonar.scanner.phases.AbstractPhaseExecutor.execute(AbstractPhaseExecutor.java:88)
at org.sonar.scanner.scan.ModuleScanContainer.doAfterStart(ModuleScanContainer.java:180)
at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:135)
at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:121)
at org.sonar.scanner.scan.ProjectScanContainer.scan(ProjectScanContainer.java:288)
at org.sonar.scanner.scan.ProjectScanContainer.scanRecursively(ProjectScanContainer.java:283)
at org.sonar.scanner.scan.ProjectScanContainer.doAfterStart(ProjectScanContainer.java:261)
at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:135)
at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:121)
at org.sonar.scanner.task.ScanTask.execute(ScanTask.java:48)
at org.sonar.scanner.task.TaskContainer.doAfterStart(TaskContainer.java:84)
at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:135)
at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:121)
at org.sonar.scanner.bootstrap.GlobalContainer.executeTask(GlobalContainer.java:121)
at org.sonar.batch.bootstrapper.Batch.doExecuteTask(Batch.java:116)
at org.sonar.batch.bootstrapper.Batch.executeTask(Batch.java:111)
at org.sonarsource.scanner.api.internal.batch.BatchIsolatedLauncher.execute(BatchIsolatedLauncher.java:63)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.sonarsource.scanner.api.internal.IsolatedLauncherProxy.invoke(IsolatedLauncherProxy.java:60)
at com.sun.proxy.$Proxy0.execute(Unknown Source)
at org.sonarsource.scanner.api.EmbeddedScanner.doExecute(EmbeddedScanner.java:233)
at org.sonarsource.scanner.api.EmbeddedScanner.runAnalysis(EmbeddedScanner.java:151)
at org.sonarsource.scanner.cli.Main.runAnalysis(Main.java:123)
at org.sonarsource.scanner.cli.Main.execute(Main.java:77)
at org.sonarsource.scanner.cli.Main.main(Main.java:61)
Had the same issue, and was wondering where did java files came in to a node project. Then by doing a file search I found several java classes in the node_modules folder. Was able to move forward by excluding them in the sonar properties file.
sonar.exclusions=test/**, node_modules/**
The error message is actually pretty clear:
Please provide compiled classes of your project with sonar.java.binaries property
Your project includes Java files, which cannot be analyzed without also providing their compiled .class files. You must either first compile (and feed the class file location into analysis) or exclude the .java files from analysis.

How to link features files with the step definitions using Cypress io

I am currently using cucumber with cypress io for testing, however, unlike when using selenium with cucumber/Gherkin that allows you to trace each scenario step to the corresponding step definition step by pressing down the control key and clicking against the scenario step, this is not happening with cypress io. The test also failed when using the below syntax;
given(/^I entered a valid client id as "([^"]*)"$/, (client_id) => {
cy.get('#bpId')
.clear()
.type(client_id);
});
Could someone help me with the way to solve these problems? I am new to cypress.
I have ran into a similar problem, while setting up the project.
I have created a file named, .cypress-cucumber-preprocesorrc and added this line in there
{
"step_definitions": "cypress/integration/**/step_definitions/"
}
The recommended way to integrate cucumber and cypress is the cypress-cucumber-preprocessor. Under the hood, this module uses cosmiconfig, which allows you to specify json or yaml configuration.
The configuration file naming conventions are explained in the cosmiconfig README:
By default, Cosmiconfig will start where you tell it to start and search up the directory tree for the following:
a package.json property
a JSON or YAML, extensionless "rc file"
an "rc file" with the extensions .json, .yaml, .yml, or .js.
a .config.js CommonJS module
For example, if your module's name is "myapp", cosmiconfig will search up the directory tree for configuration in the following places:
a myapp property in package.json
a .myapprc file in JSON or YAML format
a .myapprc.json file
a .myapprc.yaml, .myapprc.yml, or .myapprc.js file
a myapp.config.js file exporting a JS object
This is why the configuration file in this answer works.

sonarqube test coverage with istanbul : No coverage property. Skip Sensor

I'm trying to output some test coverage (lcov) reports from istanbul into sonarqube to analyse our test coverage using thoughtworks GO. There is a coverage/html folder being output but sonarqube reports the following error No coverage property. Skip Sensor. Here's my properties file, what am I missing ?
sonar.projectKey=transformers.allspark.ui
sonar.projectName=Transformers Allspark UI
sonar.projectVersion=1.0
sonar.host.url=https://sonarqube-security.test.ctmers.io
sonar.sources=.
sonar.projectBaseDir=.
sonar.language=js
sonar.sourceEncoding=UTF-8
sonar.javascript.lcov.reportPath=coverage/html
Thanks for responding. I've managed to fix this by replacing the last line with this : sonar.javascript.lcov.reportPath=coverage/html/lcov.info. It appears that sonarqube needs a path to a file (lcov.info) and not just the folder. Also my istanbul configuration was wrong because it needed to output lcov and not just a standard report.

How to reuse LCOV report from JSCover in Sonar for javascript code coverage

I am using JSCover to capture coverage of my javascript files. JSCover outputs coverage in json format and I can use the given html files to view the coverage results.
I am converting the json file to lcov using:
java -cp JSCover-all.jar jscover.report.Main --format=LCOV REPORT-DIR SRC-DIRECTORY
This is what I set in my sonar.propoerties file
sonar.javascript.jstestdriver.reportsPath= C:/...reports
sonar.javascript.lcov.reportPath=C:/.../JSCover/target/jscover.lcov
sonar.dynamicAnalysis=reuseReports
But I am not able to see coverage. Why?

Google Closure MSBuild Task Error

I am trying to write a custom task in my MSBuild file to compress some js files with Google Closure Compiler. I downloaded the ClosureCompiler.dll and ClosureCompiler.tasks files from the site and have kept them in a folder on my m/c. I added the below lines in my csproj file
<Import Project="C:\Projects\Closure\ClosureCompiler.tasks" />
<Target Name="AfterBuild">
<ItemGroup>
<JS Include="test.js" />
</ItemGroup>
<ClosureCompiler CompilationLevel="SIMPLE_OPTIMIZATIONS" SourceFiles="#(JS)" SourceExtensionPattern="\.js$" TargetExtension=".min.js" />
</Target>
The test.js file is kept on the root of my project files. I do not want to include the optional ApiUrl since I want to compress files locally using ClosureCompiler.dll. The ClosureCompiler.tasks file is
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<UsingTask TaskName="ClosureCompiler" AssemblyFile="C:\Projects\Closure\ClosureCompiler.dll" />
</Project>
However when I try to compile the project, it gives me an error:
Compilation Failed: test.js, Reason: Object reference not set to instance of an object
Can anyone help as to what is the issue or what am I doing wrong?
I ran into the same issue and it is a bug in the custom task code. It is because the API is returning an error and the custom code is not checking to see if the API returns an error.
It will check
compiledSource.SelectSingleNode("//compileCode").InnerText
That will throw an object not reference for .InnerText if there is no node named compiledCode. You need to check for errors in the response first.
if (compiledSource.SelectSingleNode("//error") != null)
throw new Exception(compiledSource.SelectSingleNode("//error").InnerText);
Go to
http://closure-compiler.appspot.com/home
And see if you can paste "Anything" in. You may have reached your hourly limit. VS2010 WILL throw this message if the aforementioned happens and causes an error. So...it is One thing that will cause it.

Categories