Sonarqube jest coverage report fails on expected XML format - javascript

I am using jest-sonar-reporter for the coverage as below:
package.json
{
"name": "app",
"version": "1.0.0",
"description": "The task runner packages for Gulp",
"main": "gulpfile.js",
"scripts": {
...
"test": "jest --coverage",
...
},
"devDependencies": {
...
"jest": "26.0.1",
"jest-sonar-reporter": "2.0.0",
...
},
"jest": {
...
"collectCoverage": true,
"testResultsProcessor": "jest-sonar-reporter"
},
"jest-junit": {
"suiteName": "jest tests",
...
}
}
I have the test-report.xml file generated after npm run test as below:
test-report.xml
<?xml version="1.0" encoding="UTF-8"?>
<testExecutions version="1">
<file path="<path to>\AreaList.test.jsx">
<testCase name="Description 1 " duration="6"/>
</file>
<file path="<path to>\selectors.search.test.js">
<testCase name="Description 2 " duration="2"/>
</file>
</testExecutions>
SonarScanner command:
sonar-scanner.bat -Dsonar.host.url="http://localhost:9000" -Dsonar.projectKey="Project-A" -Dsonar.projectName="Project-A" -Dsonar.sourceEncoding=UTF-8 -Dsonar.testExecutionReportPaths="\test-report.xml"
I am getting error as:
INFO: Parsing <path to>\test-report.xml
INFO: ------------------------------------------------------------------------
INFO: EXECUTION FAILURE
INFO: ------------------------------------------------------------------------
INFO: Total time: 5:29.011s
INFO: Final Memory: 15M/68M
INFO: ------------------------------------------------------------------------
ERROR: Error during SonarScanner execution
ERROR: Error during parsing of generic test execution report '<path to>\test-report.xml'. Look at the SonarQube documentation to know the expected XML format.
ERROR: Caused by: Line 3 of report refers to a file which is not configured as a test file: <path to>\AreaList.test.jsx
Am I missing any configuration?
Appreciate your response. Thank you.

Related

ReferenceError: remote is not defined-- Evolus Pencil development

I have downloaded Pencil-development, but cannot get it to run in VSCode. Message is coming from electron\resources\default_app.asar\main.js during loadApplicationPackage.
Any help getting this to run under VScode is appreciated.
tkx, Paul
==>VSCode-About
VisualStudioCode--Version: 1.74.3 (system setup)
Date: 2023-01-09T16:59:02.252Z
Electron: 19.1.8
Chromium: 102.0.5005.167
Node.js: 16.14.2
V8: 10.2.154.15-electron.0
OS: Windows_NT x64 10.0.19044
Sandboxed: No
==> launch.json
{
"version": "0.2.0",
"configurations": [
{
"name": "Debug Main Process",
"type": "node",
"request": "launch",
"cwd": "C:\\H_Paul\\Pencil\\electron-v22.0.3-win32-x64",
"env": {
"Path": "C:\\H_Paul\\Pencil\\electron-v22.0.3-win32-x64\\node_modules\\app\\.bin;${env:Path}"
},
"runtimeExecutable": "C:\\H_Paul\\Pencil\\electron-v22.0.3-win32-x64\\electron.exe",
"args" : ["C:\\H_Paul\\Pencil\\pencil-development\\app\\app.js"],
"outputCapture": "std"
}
]
}
==> debug console
C:\H_Paul\Pencil\electron-v22.0.3-win32-x64\electron.exe C:\H_Paul\Pencil\pencil-development\app\app.js
Debugger listening on ws://127.0.0.1:61905/92a1894d-8337-4202-be16-ce48bcbed975
Debugger attached.
App threw an error during load
ReferenceError: remote is not defined
at Object.<anonymous> (C:\H_Paul\Pencil\pencil-development\app\app.js:16:24)
==>app.js the offending line of code
16 const dialog = remote.dialog;

internalBinding('errors').triggerUncaughtException(

I am facing the issue during installation of chalk module with node version 14 using command npm install chalk and facing this issue could not find any solution.
package.json file
"name": "notes-app",
"version": "1.0.0",
"description": "",
"main": "app.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "jayant",
"license": "ISC",
"dependencies": {
"chalk": "^5.0.0"
},
"type": "module"
}
app.js file
import chalk from 'chalk';
console.log(chalk.blue('Hello world!'));
Got this error while running app.js with node version 14
internalBinding('errors').triggerUncaughtException(
^
Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'C:\previous data\Jayant\Programs\node-tutorials\notes-app\node_modules\chalk\source\node_modules\' imported from C:\previous data\Jayant\Programs\node-tutorials\notes-app\node_modules\chalk\source\index.js
at packageMainResolve (internal/modules/esm/resolve.js:458:9)
at packageResolve (internal/modules/esm/resolve.js:601:14)
at moduleResolve (internal/modules/esm/resolve.js:646:14)
at Loader.defaultResolve [as _resolve] (internal/modules/esm/resolve.js:692:13)
at Loader.resolve (internal/modules/esm/loader.js:97:40)
at Loader.getModuleJob (internal/modules/esm/loader.js:243:28)
at ModuleWrap.<anonymous> (internal/modules/esm/module_job.js:42:40)
at link (internal/modules/esm/module_job.js:41:36) {
code: 'ERR_MODULE_NOT_FOUND'
}

Override jest-junit default output location?

How can I override the default output directory and file name jest-junit?
I would like to customise the output configuration of output when using Jest, but it still ends up in the default location, i.e. ./junit.xml in the project root folder.
My configuration
In package.json:
"scripts": {
"test": "jest --ci --reporters=default --reporters=jest-junit"
},
"devDependencies": {
"jest": "^24.9.0",
"jest-junit": "^10.0.0",
}
In jest.config.js
module.exports = {
testMatch: [
'**/*.spec.js',
],
reporters: [
'default',
[ 'jest-junit', {
outputDirectory: 'test_reports',
outputName: 'jest-junit.xml',
} ]
]
};
Expected result:
A file with the test result at ./test_reports/jest-junit.xml
Actual result:
A file with the test result at the default ./junit.xml
Solution
change package.json script from
"scripts": {
"test": "jest --ci --reporters=default --reporters=jest-junit"
},
to just
"scripts": {
"test": "jest --ci"
},
Explanation
The problem is that reporters configuration have been provided to both the jest.config.js file as well as cli arguments to the test script in package.json. The CLI options has higher precedence and does not provide the outputDirectory and outputName, the test result will revert to the default junit.xml.

loading "gruntfile.js" tasks...ERROR

Ive searched this for over an hour now and no ones post helped me with my problem so i need to post i guess lol
I have some pretty simple code for a grunt task im trying to run but im getting an error.
module.exports = function(grunt){
grunt.initconfig({
pkg: grunt.file.readJSON ('package.json'),
uncss: {
dist: {
files: {
'css/style.css' : ['index.html']
}
}
}
});
grunt.loadNpmTasks('grunt-uncss');
grunt.registerTask('default',['uncss']);
};
my package file is as follows:
{
"name": "Grunt",
"version": "1.0.0",
"description": "grunt",
"main": "index.html",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [
"tt"
],
"author": "troy",
"license": "ISC",
"devDependencies": {
"grunt": "^0.4.5",
"grunt-uncss": "^0.4.3"
}
}
The Error im getting is:
Loading "gruntfile.js" tasks...ERROR
TypeError: undefined is not a function
Warning: Task "default" not found. Use --force to continue.
Aborted due to warnings.
Any assistance is greatly appreciated

Jasmine js: Add source method for test execution

I have as simple "hello world" project and I want to test the famous hélloWorld function.
The project is structured like this:
├── package.json
├── spec
│   ├── helloWorldSpec.js
│   └── support
│   └── jasmine.json
└── src
└── helloWorld.js
And the file content:
package.json
{
"name": "jasmineTest",
"version": "0.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "BSD-2-Clause",
"dependencies": {
"jasmine": "~2.1.0"
}
}
spec/helloWorldSpec.js
// var helloWorld = require('../src/helloWorld.js');
describe('Test', function() {
it('it', function() {
helloWorld();
});
});
src/helloWorld.js
function helloWorld() {
return "Hello world!";
}
// module.exports = helloWorld;
spec/support/jasmine.json
{
"spec_dir": "spec",
"spec_files": [
"**/*[sS]pec.js"
],
"helpers": [
"helpers/**/*.js"
]
}
My problem:
When I run npm install jasmine is downloaded.
=> ok
When I run ./node_modules/jasmine/bin/jasmine.js
I have the error ReferenceError: helloWorld is not defined ReferenceError: helloWorld is not defined
My Question:
How can I access the method helloWord contained in src/helloWorld.js in the test scope without using module.exports = xxx.
A solution is to use Grunt.
Create a GruntFile.js containing:
module.exports = function (grunt) {
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
jasmine: {
src: ['src/**/*.js'],
options: {
specs: ['spec/**/*Spec.js'],
vendor: []
}
}
});
grunt.loadNpmTasks('grunt-contrib-jasmine');
};
Update package.json with grunt, grunt-cli and grunt-contrib-jasmine dependencies
{
"name": "jasmineTest",
"version": "0.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "BSD-2-Clause",
"dependencies": {
"jasmine": "~2.1.0",
"grunt": "~0.4.5",
"grunt-cli": "~0.1.13",
"grunt-contrib-jasmine": "~0.8.1"
}
}
Update npm dependencies:
npm update
And relaunch test using grunt and not directly jasmine:
./node_modules/grunt-cli/bin/grunt jasmine
And you got:
Running "jasmine:src" (jasmine) task
Testing jasmine specs via PhantomJS
Test
- it...
log: Spec 'Test it' has no expectations.
✓ it
1 spec in 0.008s.
>> 0 failures
Done, without errors.
According to Jasmine staff :
You don't need to specify your source files in the config - just require them in from your spec files.
https://github.com/jasmine/jasmine-npm/issues/49
But then, you do need to use export.
This is not a Jasmine issue but vanilla Javascript. You want to call a method from another file so you need to export and require it.
Why don't you want to ?

Categories