Import Angular unit test report into Sonarqube - javascript

Context
In an Angular5 project using karma and jasmine for unit testing, I am generating this report file for my unit tests using karma-sonarqube-unit-reporter.
<testExecutions version="1">
<file path="src/app/app.component.spec.ts">
<testCase name="app/app.component.spec.ts should create the app" duration="314"/>
<testCase name="app/app.component.spec.ts should have as title 'Projet de test Angular5'" duration="104"/>
<testCase name="src/app/app.component.spec.ts should render title in a h1 tag" duration="114"/>
</file>
<file path="src/app/client-add/client-add.component.spec.ts">
<testCase name="client-add/client-add.component.spec.ts should create" duration="107"/>
</file>
<file path="app/client.service.spec">
<testCase name="app/client.service.spec #getClients should return an Observable<Client[]>" duration="38"/>
</file>
<file path="src/app/message.service">
<testCase name="app/message.service should be created" duration="35"/>
</file>
</testExecutions>
But when I import it into Sonarqube (v6.7) (via Jenkins), I get the following
INFO: Sensor Generic Test Executions Report
WARN: Property 'sonar.genericcoverage.unitTestReportPaths' is deprecated. Please use 'sonar.testExecutionReportPaths' instead.
INFO: Parsing C:\Users\adminpp\.jenkins\workspace\ELIS JustElis Beta WEB\reports\ut_report.xml
INFO: Imported test execution data for 0 files
INFO: Test execution data ignored for 4 unknown files, including:
src/app/app.component.spec.ts
src/app/client-add/client-add.component.spec.ts
src/app/client.service.spec
src/app/message.service
INFO: Sensor Generic Test Executions Report (done) | time=110ms
Here are my sonar properties for excluding and including sources and test codes.
sonar.sourceEncoding=UTF-8
sonar.sources=.
sonar.exclusions=**/node_modules/**
sonar.test.inclusions = **/*.spec.ts
sonar.import_unkown_files=true
sonar.typescript.lcov.reportPaths=coverage/lcov.info
sonar.testExecutionReportPaths=reports/ut_report.xml
I checked and I have my *.spec.ts files where they are supposed to be.
Questions
Why Sonarqube doesn't find my files?
Have I missed a property or an important step?
(Is this property sonar.test.inclusions = **/*.spec.ts important?)

can you try to add property sonar.tests=. (value set to current directory) – Tibor Blenessy
Adding this property in the sonar config worked for me.
I got an error when I had the property sonar.tests set but not sonar.test.inclusions though but with the two, everything works fine.

Related

Jest: Failed prop type: Invalid prop `source` supplied to `Image`, expected one of type [number]

I am using jest with react-native to run unit test cases. And whenever it encounters Image it throws the following warning
Warning: Failed prop type: Invalid prop `source` supplied to `Image`, expected one of type [number].
at Component (~/.../node_modules/react-native/jest/mockComponent.js:28:18)
at SummaryTile (~/.../src/components/home/SomeComponent.tsx:18:3)
23 | >
24 | {backgroundImg || (
> 25 | <Image
| ^
26 | source={require('images/cloud.png')}
27 | />
I tried to replace the code to
<Image src={{uri: require('images/cloud.png')}} />
as suggested in https://stackoverflow.com/a/36460928/3855179 but it started throwing the following warning and the application breaks
Warning: Failed prop type: Invalid prop `source` supplied to `Image`, expected one of type [string, number].
at Image (http://expo_url:19000/node_modules/expo/AppEntry.bundle?platform=android&dev=true&hot=false&strict=false&minify=false:76209:43)
Jest Version: 26.6.3
React Native version: 0.64.3
Node Version: 16.14.2
Any idea how this can be handled?
It would be helpful to see your file structure along with the jest configuration file.
But my best guess is - jest isn't able to find the file in the designated location.
Few things that can be tried:
(1) try changing file location to be a bit more explicit like so:
eg - if image in same directory -- source={require('./images/cloud.png')}
eg - if one directory up -- source={require('../images/cloud.png')}
(2) try mocking out the image in test file like so:
jest.mock("images/cloud.png")
(3) Specify a location in jest configuration file (or in package.json file if you have a jest key there) for all image types, this way jest will use that as the image source whenever it encounters an image:
eg -
moduleNameMapper: {
"\\.(jpg|jpeg|png|svg)$": "<rootDir>/images/dummy-image.js",
}
More doco on moduleNameWrapper here - https://jestjs.io/docs/configuration#modulenamemapper-objectstring-string--arraystring
In my case, I was trying to use an image, that has an space in its name, like <rootDir>/stupidly_named images.png. It's seems, React Native is happy with these naming, but not Jest. Filling in the space (<rootDir>/stupidly_named_images.png) fixed the error. And I am not using any moduleNameWrapper:
"react-native": "0.68.2"
"jest": "^28.1.0"
"#testing-library/react-native": "^9.1.0"

Migration to the angular v9. i18n breaking changes

I'm migrating an Angular project from 8.2.14 to the 9.0.0-rc.14. Using i18n for localization.
I followed the guide here https://update.angular.io/#8.2:9.0 and it feels it went fine. After the upgrade, I'm trying to run the project, but
ng serve leads to the following error:
An unhandled exception occurred: An i18n locale ('en-US') cannot both be a source locale and provide a translation.
See "...my local logs path...\angular-errors.log" for further details.
In the angular-errors.log the error is more detailed:
[error] Error: An i18n locale ('en-US') cannot both be a source locale and provide a translation.
at createI18nOptions (...my project path...\node_modules\#angular-devkit\build-angular\src\utils\i18n-options.js:69:23)
at Object.configureI18nBuild (...my project path...\node_modules\#angular-devkit\build-angular\src\utils\i18n-options.js:100:18)
at process._tickCallback (internal/process/next_tick.js:68:7)
I have got more details about the error: opening the #angular-devkit\build-angular\src\utils\i18n-options.js:69:23 and I see the following logic:
if (locale === i18n.sourceLocale) {
throw new Error(`An i18n locale ('${locale}') cannot both be a source locale and provide a translation.`);
}
I have en-US locale and I want to continue using it as both translation and source. So how to fix this breaking error?
I assume your default language is different than English.
Thus, you should have change the default source 'sourceLocale' as shown in the official docs.
So it would be like:
"projects": {
"AngularApp": {
"i18n": {
"sourceLocale": "he-IL",
"locales": {
"en-US": "src/locale/messages.en.xlf"
}
},
...
simply open your angular.json file and remove the entry under locales which you have set under "sourceLocale". After the update locales only stores the translation not the language that you use in your source code.
Exactly, as #Markus said:
Your original language (developer) must not appear in '"locales": '.
Only in '"sourceLocale": '.

Parse error in 'test/step_definitions/requester.js': (1:1): expected: #EOF, #Language, #TagLine, #FeatureLine, #Comment, #Empty

I am developing an API automated test case using cucumber and JavaScript and I am getting this error:
Error: Parse error in 'test/step_definitions/requester.js': (1:1): expected: #EOF, #Language, #TagLine, #FeatureLine, #Comment, #Empty, got '//const fetch = require('node-fetch');'
I have a .feature file within 'features' folder.
In addition, I have two .js files within 'step_definitions' folder. Files are 'my_steps' and 'requester.js'.
The Gruntfile.js contains this line to run it:
command: './node_modules/.bin/cucumber-js /features/*.feature -r /Users/alfredo.bazo/XCore-ContentLibrary-Tests/API-Test/test/step_definitions/*.js',
As per error thrown, it seems that requester.js file is considered as a feature file. Why? How can I fix it?
Thanks in advance.

SonarQube doesn't add JavaScript coverage

We have a multi module maven project that has Java and JavaScript sub projects.
For SonarQube analysis we have added configuration to JavaScript module.
<sonar.sources>src</sonar.sources>
<sonar.exclusions>src/test/**/*, src/**/resources/simple/**/*</sonar.exclusions>
<sonar.coverage.exclusions>src/**/resources/simple/**/*, src/registerServiceWorker.js</sonar.coverage.exclusions>
<sonar.projectBaseDir>.</sonar.projectBaseDir>
<sonar.javascript.coveragePlugin>lcov</sonar.javascript.coveragePlugin>
<sonar.dynamicAnalysis>reuseReports</sonar.dynamicAnalysis>
<sonar.javascript.jstest.reportsPath>opui-client/target/surefire-reports</sonar.javascript.jstest.reportsPath>
<sonar.javascript.lcov.reportPath>coverage/lcov.info</sonar.javascript.lcov.reportPath>
<sonar.language>js</sonar.language>
SonarQube shows the analysis logs.
Analysing [C:\Users\mzafar\opui-19dec\path\to\file\coverage\lcov.info]
[WARNING] Problem during processing LCOV report: can't save DA data for line 1491 (Line with number 1491 doesn't belong to file src/modules/core/NagraGrid.js).
Part of lcov.info is like this:
SF:C:\Users\mzafar\path\to\js\code\src\modules\core\search\opuiSearch\AdvancedSearchOptionsPopup.js
FN:89,(anonymous_0)
FN:100,(anonymous_1)
FN:113,(anonymous_2)
FN:119,(anonymous_3)
FN:125,(anonymous_4)
FN:129,(anonymous_5)
FN:167,(anonymous_6)
FN:179,(anonymous_7)
FN:188,(anonymous_8)
FN:197,(anonymous_9)
FN:200,(anonymous_10)
FN:209,(anonymous_11)
FNF:12
FNH:10
FNDA:8,(anonymous_0)
FNDA:4,(anonymous_1)
FNDA:1,(anonymous_2)
FNDA:1,(anonymous_3)
FNDA:1,(anonymous_4)
FNDA:26,(anonymous_5)
FNDA:26,(anonymous_6)
FNDA:0,(anonymous_7)
FNDA:26,(anonymous_8)
FNDA:1,(anonymous_9)
FNDA:1,(anonymous_10)
FNDA:0,(anonymous_11)
DA:10,3
DA:82,3
DA:90,8
DA:91,8
DA:101,4
DA:102,4
DA:114,1
DA:120,1
DA:121,1
DA:126,1
DA:130,26
DA:131,0
DA:134,26
DA:136,2
DA:148,2
DA:160,22
DA:168,26
DA:180,0
DA:189,26
DA:198,1
DA:201,1
DA:210,0
DA:211,0
LF:23
LH:19
BRDA:101,0,0,4
BRDA:101,0,1,0
BRDA:120,1,0,1
BRDA:120,1,1,0
BRDA:130,2,0,0
BRDA:130,2,1,26
BRDA:130,3,0,26
BRDA:130,3,1,0
BRDA:134,4,0,2
BRDA:134,4,1,2
BRDA:134,4,2,22
BRDA:195,5,0,11
BRDA:195,5,1,15
BRDA:232,6,0,25
BRDA:232,6,1,1
BRDA:247,7,0,0
BRDA:247,7,1,26
BRDA:265,8,0,0
BRDA:265,8,1,26
BRDA:275,9,0,26
BRDA:275,9,1,0
BRDA:276,10,0,26
BRDA:276,10,1,0
BRF:23
BRH:15
end_of_record
But still JavaScript files coverage is 0. We are using SonarQube 6.7. Can someone help me if some configuration is wrong?
I added the latest sonar property
<sonar.javascript.lcov.reportPaths>path/to/lcov.info</sonar.javascript.lcov.reportPaths>
And this solved the issue for me.

Nanoc rules file not handling my JavaScript directory

My nanoc content directory structure:
assets -> (css, images, files)
js
partials
[*.textile source files]
Extract from my rules file:
compile '/js/*/' do
# don’t filter or layout
end
.
.
.
route '/js/*/' do
item.identifier.chop + '.' + #item[:extension].to_s
end
Command line result:
Message:
RuntimeError: Found 2 content files for content/js/bootstrap; expected 0 or 1
Compilation stack:
(empty)
Stack trace:
0. /home/tomc/.rvm/gems/ruby-2.1.1/gems/nanoc-3.7.1/lib/nanoc/data_sources/filesystem.rb:168:in `block in all_split_files_in'
1. /home/tomc/.rvm/gems/ruby-2.1.1/gems/nanoc-3.7.1/lib/nanoc/data_sources/filesystem.rb:158:in `each_pair'
2. /home/tomc/.rvm/gems/ruby-2.1.1/gems/nanoc-3.7.1/lib/nanoc/data_sources/filesystem.rb:158:in `all_split_files_in'
3. /home/tomc/.rvm/gems/ruby-2.1.1/gems/nanoc-3.7.1/lib/nanoc/data_sources/filesystem.rb:86:in `load_objects'
4. /home/tomc/.rvm/gems/ruby-2.1.1/gems/nanoc-3.7.1/lib/nanoc/data_sources/filesystem.rb:45:in `items'
5. /home/tomc/.rvm/gems/ruby-2.1.1/gems/nanoc-3.7.1/lib/nanoc/base/source_data/site.rb:334:in `block in load_items'
6. /home/tomc/.rvm/gems/ruby-2.1.1/gems/nanoc-3.7.1/lib/nanoc/base/source_data/site.rb:333:in `each'
7. /home/tomc/.rvm/gems/ruby-2.1.1/gems/nanoc-3.7.1/lib/nanoc/base/source_data/site.rb:333:in `load_items'
8. /home/tomc/.rvm/gems/ruby-2.1.1/gems/nanoc-3.7.1/lib/nanoc/base/source_data/site.rb:244:in `load'
9. /home/tomc/.rvm/gems/ruby-2.1.1/gems/nanoc-3.7.1/lib/nanoc/base/source_data/site.rb:128:in `layouts'
... 27 more lines omitted. See full crash log for details.
I consulted How add own javascript file to nanoc?. I seem to be setting things up correctly, but my results say otherwise.
I cannot see the error. Anyone have any ideas?
Because of the way it maps input filenames onto output paths, Nanoc requires the base name (i.e., the filename less extension) of each file under content to be unique. From Nanoc's perspective you are giving it two files that share the base name bootstrap and thus cannot have unique output paths, so it gives you this error.
Since what you really want is to have Nanoc copy over this portion of your site (the third-party JavaScript files) verbatim, it'd be better to move these files out of the content tree altogether and set up a static data source from which to load them. Then Nanoc will simply copy the files over as-is without trying to process or rename them. The "Troubleshooting" page on the Nanoc website has instructions on how to do this; see "Solution #2" under "Error: “Found 3 content files for X; expected 0 or 1”.

Categories