SonarQube showing 0% coverage for Unit Test in a NodeJS appliication - sonarqube

On SonarQube server, for all my projects, the scans are happening and I can see the Sonar metrics but the Unit Test coverage is showing as 0% for both 'new code' and 'overall code'.
The project source code is written in NodeJS/JavaScript which I need to scan with SonarQube.
Please refer attached screenshot:-
Package.json:-
{
"name": "analytics",
"version": "1.0.0",
"description": "Microservice to handle CRUD operations of analytics",
"main": "server.js",
"directories": {
"test": "test"
},
"scripts": {
"dev": "node -r dotenv/config server.js",
"dev:watch": "nodemon --watch ../analytics --watch ../../common -r dotenv/config server.js",
"start": "node server.js",
"test": "nyc --reporter=lcov --reporter=text-lcov mocha -r dotenv/config"
},
"author": "",
"license": "ISC",
"dependencies": {
"aws-sdk": "^2.752.0",
"aws-xray-sdk": "^2.5.0",
"axios": "^0.19.2",
"bcrypt": "3.0.8",
"body-parser": "1.19.0",
"cls-hooked": "4.2.2",
"cors": "2.8.5",
"dotenv": "8.2.0",
"express": "4.17.1",
"express-mung": "^0.5.1",
"express-useragent": "^1.0.13",
"fast-csv": "^4.1.3",
"json2csv": "^5.0.5",
"jsonwebtoken": "^8.5.1",
"kafka-node": "^5.0.0",
"lodash": "^4.17.20",
"moment": "^2.24.0",
"multer": "^1.4.2",
"node-cron": "^2.0.3",
"nodemon": "^2.0.5",
"passport-saml": "1.3.3",
"path": "^0.12.7",
"pg": "7.14.0",
"pg-hstore": "2.3.3",
"prom-client": "12.0.0",
"prometheus-api-metrics": "2.2.3",
"qrcode": "1.4.4",
"redis": "^3.0.2",
"redis-clustr": "1.7.0",
"seedrandom": "^3.0.5",
"sequelize": "5.21.2",
"speakeasy": "2.0.0",
"streamifier": "^0.1.1",
"uuid": "3.3.3",
"winston": "3.2.1"
},
"devDependencies": {
"ajv": "6.10.2",
"chai": "4.2.0",
"chai-as-promised": "^7.1.1",
"chai-http": "4.3.0",
"chai-jest-snapshot": "^2.0.0",
"chai-uuid": "1.0.6",
"eslint": "6.8.0",
"mocha": "6.2.2",
"mochawesome": "4.1.0",
"nyc": "14.1.1",
"redis-mock": "0.49.0",
"sequelize-mock": "0.10.2",
"sinon": "7.5.0"
}
}
Jenkinsfile code snippet:-
stages{
stage('Lint Analysis'){
steps{
echo '*************running lint analysis**********'
// sh 'eslint . --ext .js -c .eslintrc.js --fix || true' //To display output on console
// sh 'eslint . --ext .js -c .eslintrc.js --fix -f checkstyle > eslint.xml || true' //To create report which will be use by checkstyle plugin
}
}
stage('Unit Test'){
steps{
//Running Unit test to get Code Coverage report using clover plugin
dir('services/analytics') {
echo '************ Running UT ***********'
// sh 'npm install'
// sh 'npm run coverage'
// step([
// $class: 'CloverPublisher',
// cloverReportDir: 'test/coverage',
// cloverReportFileName: 'clover.xml',
// healthyTarget: [methodCoverage: 80, conditionalCoverage: 80, statementCoverage: 80],
// unhealthyTarget: [methodCoverage: 50, conditionalCoverage: 50, statementCoverage: 50],
// failingTarget: [methodCoverage: 0, conditionalCoverage: 0, statementCoverage: 0]
// ])
}
}
}
stage('Static Code Analysis by SonarQube') {
steps {
script {
withSonarQubeEnv("aws_sonarqube") {
sh "${tool("sonar_scanner")}/bin/sonar-scanner \
-Dproject.settings=./sonar-project.properties \
-Dsonar.login=$SONAR_TOKEN"
}
}
}
}
}
sonar-project.properties:-
sonar.projectKey=test-analytics
sonar.projectName=test-analytics
sonar.projectVersion=1.0
sonar.language=js
sonar.sources=.
sonar.sourceEncoding=UTF-8
# sonar.exclusions=./**/*.spec.js
sonar.tests=.
sonar.test.inclusions=./**/*.spec.js,./**/*.spec.jsx,./**/*.test.js,./**/*.test.jsx
# sonar.coverage.exclusions=./**/*.spec.js,./**/*.mock.js,node_modules/*,coverage/lcov-report/*
sonar.javascript.lcov.reportPaths=./coverage/lcov.info
# sonar.testExecutionReportPaths=test-report.xml
Please advise, thanks

Related

loadTs is not a function

After running graphql-codegen-esm --config codegen.yml the following message is shown in the console
loadTs is not a function
I add files with my project configuration
package.json
{
"main": "src/index.js",
"type": "module",
"scripts": {
"dev": "concurrently \"nodemon\" \"npm run codegen --watch\"",
"codegen": "graphql-codegen-esm --config codegen.yml"
},
"dependencies": {
"#graphql-tools/load-files": "^6.6.0",
"apollo-server": "^3.10.0",
"graphql": "^16.5.0",
"graphql-modules": "^2.1.0",
"graphql-scalars": "^1.17.0"
},
"devDependencies": {
"#graphql-codegen/add": "^3.2.0",
"#graphql-codegen/cli": "2.11.3",
"#graphql-codegen/graphql-modules-preset": "^2.5.0",
"#graphql-codegen/typescript": "^2.7.2",
"#graphql-codegen/typescript-resolvers": "^2.7.2",
"#tsconfig/node18-strictest-esm": "^1.0.0",
"concurrently": "^7.3.0",
"nodemon": "^2.0.19",
"ts-node": "^10.9.1",
"typescript": "^4.7.4"
}
}
codegen.yml
schema: './src/**/*.graphql'
emitLegacyCommonJSImports: false
generates:
./src/graphql/:
preset: graphql-modules
presetConfig:
baseTypesPath: ../generated-types/graphql.ts # Where to create the complete schema types
filename: generated-types/module-types.ts # Where to create each module types
plugins:
- add:
content: '/* eslint-disable */'
- typescript
- typescript-resolvers
tsconfig.json
{
"extends": "#tsconfig/node18-strictest-esm/tsconfig.json",
"ts-node": {
"esm": true
},
"include": ["src/**/*"],
"exclude": ["node_modules", "**/*.spec.ts"]
}
Node
v18.7.0

Receiving "Error: Can't walk dependency graph: ENOENT: no such file or directory" when run the test

I am trying to apply cucumber BDD with my cypress. But getting below error.
Error: Can't walk dependency graph: ENOENT: no such file or directory, lstat 'C:\Users\admin\LegrandRX_Cucumber\process'
required by C:\Users\admin\LegrandRX_Cucumber\node_modules\cypress-cucumber-preprocessor\lib\getStepDefinitionsPaths.js
Here is my cypress.json file
{
"reporter": "cypress-mochawesome-reporter",
"reporterOptions": {
"reportDir": "cypress/Reports",
"charts": true,
"overwrite": false,
"html": false,
"json": true,
"reportPageTitle": "Legrande Cypress",
"reportFilename": "Legrande Cypress Test Report",
"embeddedScreenshots": true,
"inlineAssets": true
},
"defaultCommandTimeout": 30000,
"retries": {
"runMode": 1,
"openMode": 1
},
"video": false,
"scrollBehavior": "nearest",
"testFiles": "**/*.{feature,features}",
"chromeWebSecurity": false,
}
And Here is my package.json file
{
"name": "cypressautomation",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"delete:reportFolder": "rm -rf mochawesome-report/",
"test:cli": "npm run delete:reportFolder && cypress run",
"merge:reports": "mochawesome-merge mochawesome-report/*.json > cypress-combined-report.json",
"create:html:report": "npm run merge:reports && marge --reportDir TestReport cypress-combined-report.json",
"cy:run": "cypress run",
"record-test": "cypress run --record --key 18415255-c402-40f0-b983-ab9c3bdf3dc4"
},
"cypress-cucumber-preprocessor": {
"nonGlobalStepDefinitions": true
},
"reporter": "cypress-mochawesome-reporter",
"reporterOptions": {
"reportDir": "cypress/Reports",
"charts": true,
"reportPageTitle": "My Test Suite",
"embeddedScreenshots": true,
"inlineAssets": true
},
"video": false,
"author": "weblylab",
"license": "ISC",
"devDependencies": {
"cypress": "^9.5.0",
"cypress-cucumber-preprocessor": "^4.3.1",
"cypress-file-upload": "^5.0.2",
"cypress-mochawesome-reporter": "^2.2.0",
"cypress-slack-reporter": "^1.2.1",
"cypress-xpath": "^1.6.1",
"faker": "^5.5.3",
"i": "^0.3.6",
"mocha": "^8.4.0",
"mochawesome": "^6.2.2",
"mochawesome-merge": "^4.2.0",
"mochawesome-report-generator": "^5.2.0",
"tsconfig-paths": "^3.9.0"
},
"dependencies": {
"#auth0/auth0-spa-js": "^1.13.6",
"#types/bluebird": "^3.5.33",
"#types/lodash": "^4.14.168",
"chai": "^4.3.0",
"cypress-iframe": "^1.0.1",
"cypress-skip-test": "^1.0.0",
"delay": "^5.0.0",
"Faker": "^0.7.2",
"lodash": "^4.17.21",
"moment": "^2.29.1",
"resolve-url": "^0.2.1",
"save": "^2.4.0",
"source-map-resolve": "^0.6.0",
"urix": "^0.1.0",
"xlsx": "^0.17.0"
}
}
My folder structure, .js file and .feature file
And in my index.js file
const cucumber = require('cypress-cucumber-preprocessor').default
module.exports = (on, config) => {
on('file:preprocessor', cucumber())
}
Any idea what's wrong here?

Issue in path of deployed MERN app on heroku

getting Error: ENOENT: no such file or directory, stat '/app/client/build/index.html'
package.json
"name": "google-contacts-backend",
"version": "1.0.0",
"private": true,
"scripts": {
"start": "node ./bin/www",
"dev": "nodemon ./bin/www",
"test": "nyc _mocha --timeout 10000 --exit --report lcovonly -- -R spec",
"lint": "eslint --fix --config .eslintrc.json \"**/*.js\"",
"heroku-postbuild": "cd client && npm install --only=dev && npm install && npm run build"
},
"dependencies": {
"axios": "^0.19.2",
"bcrypt": "^3.0.6",
"codacy-coverage": "^3.4.0",
"cookie-parser": "~1.4.3",
"cors": "^2.8.5",
"debug": "~2.6.9",
"dotenv": "^8.2.0",
"express": "~4.16.0",
"express-jwt": "^5.3.1",
"express-validator": "^6.2.0",
"googleapis": "^58.0.0",
"jsonwebtoken": "^8.5.1",
"mocha-lcov-reporter": "^1.3.0",
"moment": "^2.24.0",
"morgan": "~1.9.0",
"nodemailer": "^6.3.1"
},
"devDependencies": {
"chai": "^4.2.0",
"chai-http": "^4.3.0",
"eslint": "^6.5.1",
"mocha": "^6.2.2",
"nodemon": "^1.19.4",
"nyc": "^14.1.1"
}
}```
server.js
```app.get("*", (req, res) => {
res.sendFile(path.join(__dirname, "client", "build", "index.html"));
});
when I tried to check client folder directly in heroku bach, it was empty.

CFBundleIdentifier Collision while uploading a macOS app developed with Electron and built with electron-builder

I am currently developing an Electron app and I am able to generate the .app and .pkg for the macOS operating systems. Although I can run it from the .app generated, when I try to upload the .pkg (mas) I get the following error on AppStore Connect:
CFBundleIdentifier Collision -
The Info.plist CFBundleIdentifier value 'org.phantomjs' of 'phantomjs'
is already in use by another application.
I have tried updating Electron to the latest stable version (2.0.9), and updating electron-builder to the latest version (20.28.4). I've tried searching for the org.phantomjs string in the resulting .app and I am unable to find a Info.plist with that Bundle Identifier
Here I attach my package.json in case it is useful:
{
"name": "myAppName",
"version": "0.0.1",
"author": "Me <me#mymail.com>",
"description": "My Description",
"license": "MIT",
"main": "./dist/electron/main.js",
"repository": {
"type": "git",
"url": "git+https://github.com/****.git"
},
"scripts": {
"build": "node .electron-vue/build.js && electron-builder",
"build:dir": "node .electron-vue/build.js && electron-builder --dir",
"build:clean": "cross-env BUILD_TARGET=clean node .electron-vue/build.js",
"build:web": "cross-env BUILD_TARGET=web node .electron-vue/build.js",
"dev": "node .electron-vue/dev-runner.js",
"lint": "eslint --ext .js,.vue -f ./node_modules/eslint-friendly-formatter src",
"lint:fix": "eslint --ext .js,.vue -f ./node_modules/eslint-friendly-formatter --fix src",
"pack": "npm run pack:main && npm run pack:renderer",
"pack:main": "cross-env NODE_ENV=production webpack --progress --colors --config .electron-vue/webpack.main.config.js",
"pack:renderer": "cross-env NODE_ENV=production webpack --progress --colors --config .electron-vue/webpack.renderer.config.js",
"postinstall": "npm run lint:fix"
},
"build": {
"productName": "myAppName",
"appId": "this.is.a.real.appid",
"buildVersion": "5",
"directories": {
"output": "build"
},
"files": [
"dist/electron/**/*"
],
"dmg": {
"contents": [
{
"x": 410,
"y": 150,
"type": "link",
"path": "/Applications"
},
{
"x": 130,
"y": 150,
"type": "file"
}
]
},
"mac": {
"icon": "build/icons/icon.icns",
"category": "public.app-category.developer-tools",
"target": [
{
"target": "mas"
}
]
},
"mas": {
"entitlements": "build/entitlements.mas.plist",
"entitlementsInherit": "build/entitlements.mas.inherit.plist",
"icon": "build/icons/icon.icns",
"category": "public.app-category.developer-tools"
},
"win": {
"icon": "build/icons/icon.ico",
"target": [
{
"target": "nsis"
},
{
"target": "appx"
}
]
},
"linux": {
"icon": "build/icons"
},
"fileAssociations": [
{
"ext": "myExtension",
"name": "My Project",
"description": "File containing a My Project.",
"icon": "build/icons/Project.icns",
"role": "Editor",
"isPackage": true
}
],
"copyright": "Copyright © 2018 Me"
},
"dependencies": {
"#appshuttle.io/bell": "0.0.12",
"#appshuttle.io/pollock": "0.0.28",
"#appshuttle.io/turing": "0.0.16",
"#fortawesome/fontawesome-svg-core": "^1.2.2",
"#fortawesome/free-brands-svg-icons": "^5.0.13",
"#fortawesome/free-regular-svg-icons": "^5.0.13",
"#fortawesome/free-solid-svg-icons": "^5.0.13",
"#fortawesome/vue-fontawesome": "0.1.1",
"axios": "^0.16.1",
"electron-updater": "^3.0.3",
"email-validator": "^2.0.4",
"grunt": "^1.0.3",
"nedb": "^1.8.0",
"p5": "^0.6.1",
"path": "^0.12.7",
"spectre.css": "^0.5.3",
"vue": "^2.3.3",
"vue-color": "^2.4.6",
"vue-electron": "^1.0.6",
"vue-router": "^2.5.3",
"vuedraggable": "^2.16.0",
"vuex": "^2.3.1"
},
"devDependencies": {
"babel-core": "^6.26.3",
"babel-eslint": "^7.2.3",
"babel-loader": "^7.1.5",
"babel-plugin-transform-runtime": "^6.23.0",
"babel-preset-env": "^1.7.0",
"babel-preset-stage-0": "^6.24.1",
"babel-register": "^6.24.1",
"babili-webpack-plugin": "^0.1.2",
"cfonts": "^1.2.0",
"chalk": "^2.4.1",
"copy-webpack-plugin": "^4.5.2",
"cross-env": "^5.2.0",
"css-loader": "^0.28.11",
"del": "^3.0.0",
"devtron": "^1.4.0",
"electron": "^2.0.0",
"electron-builder": "20.28.4",
"electron-debug": "^2.0.0",
"electron-devtools-installer": "^2.2.4",
"eslint": "^4.19.1",
"eslint-config-standard": "^10.2.1",
"eslint-friendly-formatter": "^3.0.0",
"eslint-loader": "^1.9.0",
"eslint-plugin-html": "^3.1.1",
"eslint-plugin-import": "^2.13.0",
"eslint-plugin-node": "^5.1.1",
"eslint-plugin-promise": "^3.8.0",
"eslint-plugin-standard": "^3.1.0",
"extract-text-webpack-plugin": "^3.0.0",
"file-loader": "^0.11.2",
"html-webpack-plugin": "^2.30.1",
"mini-css-extract-plugin": "^0.4.1",
"multispinner": "^0.2.1",
"node-loader": "^0.6.0",
"node-sass": "^4.9.2",
"sass-loader": "^6.0.7",
"style-loader": "^0.18.2",
"url-loader": "^0.5.9",
"vue-html-loader": "^1.2.4",
"vue-loader": "^15.4.0",
"vue-style-loader": "^3.0.1",
"vue-template-compiler": "^2.4.2",
"webpack": "^3.12.0",
"webpack-dev-server": "^2.7.1",
"webpack-hot-middleware": "^2.22.3"
}
}
Thanks so much in advance!
Found a solution (As mentioned by #countravioli in this Github Issue):
I found that there was a file called app.asar.unpacked that contained multiple Bundle Identifiers once the .pkg was created and signed. Deleting this file in the .app and then creating a .pkg didn't work for me so I used a Build Hook as proposed in the Github Issue. To prevent the file to being inserted to the .pkg file. To do this, I added a hook to the build section of my package.json at the end of the rest of its contents:
package.json
{ //package.json Root ...
build: {
// build content ...
"afterPack": "./afterPack.js"
}
}
An then created a file called afterPack.js in the folder where my package.json is located with the following contents:
const fs = require('fs');
const fse = require('fs-extra');
const path = require('path');
module.exports = function (params) {
const unpackFile = path.join(params.appOutDir, 'YOUR_APP_NAME.app/Contents/Resources/app.asar.unpacked');
console.log('EXISTS?', fs.existsSync(unpackFile));
console.log("REMOVE", unpackFile);
fse.removeSync(unpackFile);
};
I was able to upload the package to AppStore Connect without any issue.

Electron start script error

i am running a webpack project and running this script
My package.json looks like this
{
"name": "collab-ui",
"version": "0.0.10",
"author": {
"name": "some-name",
"email": "some-emailId"
},
"main": "electron.js",
"scripts": {
"start": "rimraf debug && npm outdated && webpack --watch",
"http": "rimraf debug && npm outdated && webpack --watch",
"release": "rimraf dist && webpack --bail --progress --profile",
"elecstart": "rimraf debug && webpack && electron .",
"elecrel": "electron-packager . XorChat --all",
},
"devDependencies": {
"#types/jquery": "2.0.41",
"api-ai-javascript": "^2.0.0-beta.21",
"autoprefixer": "~6.7.7",
"awesome-typescript-loader": "~3.1.2",
"browser-sync": "~2.18.8",
"browser-sync-webpack-plugin": "~1.1.4",
"css-loader": "~0.27.3",
"custom-event-polyfill": "~0.3.0",
"electron": "^1.7.9",
"electron-packager": "^9.1.0",
"es6-promise": "~4.1.1",
"extract-text-webpack-plugin": "~2.1.0",
"file-loader": "~0.10.1",
"html-loader": "~0.4.5",
"html-webpack-plugin": "~2.28.0",
"html5-notification": "~3.0.0",
"http-proxy-middleware": "~0.17.4",
"import-glob-loader": "~1.1.0",
"knockout": "~3.4.2",
"live-server": "~1.2.0",
"node-sass": "~4.5.0",
"open-browser-webpack-plugin": "~0.0.5",
"postcss-loader": "~1.3.3",
"qrcode-generator": "~1.3.1",
"resolve-url-loader": "~2.1.0",
"rimraf": "~2.6.1",
"sass-loader": "~6.0.3",
"socket.io-client": "~2.0.3",
"store": "~2.0.12",
"style-loader": "~0.14.1",
"ts-loader": "~2.0.2",
"typescript": "~2.2.1",
"url-loader": "~0.5.8",
"webpack": "~2.2.1",
"webpack-dev-middleware": "~1.10.1",
"webpack-dev-server": "~2.4.2",
"webpack-hot-middleware": "~2.17.1",
"webpack-stream": "~3.2.0",
"webrtc-adapter": "^6.0.2",
"uuid": "^3.1.0"
}
}
My electron.js looks like this
const electron = require('electron');
const { app, BrowserWindow } = electron;
app.commandLine.appendSwitch("ignore-certificate-errors");
app.on('ready', () => {
let win = new BrowserWindow({ width: 800, height: 600 });
win.loadURL(`file://${__dirname}/debug/index.html`);
win.webContents.openDevTools();
})
But after running npm run elecstart, i am getting this error
Any clue,why i am getting this error. i am running on windows 10 64bit, 8 gb ram(FYI), but after running the script the window error box comes as shown in the image and after i close it , the script halts.I am suspecting some JS error to be in there, as it is not able to find some symbol or some configuration is missing. Any help is appreciated.

Resources