I am using nodejs Project repository and the test cases are written in the Jasmine framework. On sonarqube dashboard, I cant see the unit test count block.
Sonar-template-configurations was written as below:
sonar.projectKey={{sonar_projectKey}}
sonar.projectName={{sonar_projectName}}
sonar.host.url={{{sonar_host_url}}}
sonar.javascript.environments = node
# Source code for analysis
sonar.sources=.
sonar.tests = .
sonar.test.inclusions = **/*.spec.js
# Exclusions
sonar.exclusions=test/**
# Reports
sonar.ts.tslint.configPath=tslint.json
sonar.javascript.lcov.reportPaths=coverage/lcov.info
sonar.javascript.coverage.lcovReportPath=coverage/lcov.info
sonar.junit.reportsPath= unit_test_results.xml
sonar.testExecutionReportPaths=unit_test_results.xml
sonar.log.level=DEBUG
sonar.verbose=true
Script used in package.json as below for generating report and running test cases:
"scripts": {
"start": "nodemon --verbose --ignore '/meta.conf/**' --ignore '/data/**' app.js",
"test": "nyc ./node_modules/jasmine-xml-reporter/bin/jasmine.js --junitreport --filePrefix=unit_test_results",
"coverage": "nyc --reporter=lcov --reporter=text-lcov npm test"
},
Does anyone know the solution for it, to show the Unit tests block on the sonarqube dashboard?
Thanks.
Related
In almost all of the docs I've come across so far, most of the time I have seen the start and the dev script being used for a similar kind of functionality. following are 2 examples:
1.
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node index",
"dev": "nodemon index"
},
"scripts": {
"dev": "webpack-dev-server --inline --progress --config build/webpack.dev.conf.js",
"start": "npm run dev",
So, please help me in understanding, what exactly is the difference between the two in package.json file used for NodeJs. Under what circumstances does mentioning the 2 at the same time make sense.
P.S: I'm new to javascript and node.js. Hence please forgive in case of a silly mistake. Thanks in advance :)
Start is a script handled by default by npm. You can use it without the keyword run:
npm start
dev is a custom script, the name has no significance fr npm. You need to use the keyword run:
# npm run <script name>
npm run dev
documentation for start: https://docs.npmjs.com/cli/v6/commands/npm-start
documentation for run-script: https://docs.npmjs.com/cli/v6/commands/npm-run-script
In other words, start will override the default npm command. By default, npm will run node index.js on start. The start script always exists even if you don't declare it. That is not the case for dev.
All my tests are under test folder and when I give npm test all the tests are getting executed. Now I am trying to run my test scripts by file or by it's describe. I have the following in my package.json
"scripts": {
"test": "set NODE_ENV=test&& nyc --reporter=html --reporter=text mocha 'test/**/*.js' --exit --timeout 7000"}
When I give npm test --grep 'filename / describe / it' it is not picking up the given input instead I'm getting the following warning Warning: Cannot find any files matching pattern "given filename / describe /it" even though given input matches.
My filename pattern is filename.test.js and the folder structure is like test\***\filename.test.js
Can anyone guide me on what I'm missing on this.
You need to include the grep option within the npm command:
"scripts": {
"test": "set NODE_ENV=test&& nyc --reporter=html --reporter=text mocha 'test/**/*.js' --exit --timeout 7000 --grep"
}
Then call it with:
npm run test <name of test>
I tried several commands but nothing seems to work. Either it escapes all or runs none.
#TestFeature
Feature: Test Feature
Testing sample feature
Background: Logging in
#manual
Scenario: A
Given
Scenario Outline: B
I want to run Test Feature and skip the scenarios marked manual. I tried -
npx cypress run --env TAGS=#TestFeature and not #manual --browser chrome
But it doesn't work. Also tried similar combinations, but none work.
You are able to use #tags in Feature Files and get Cypress to run selected tests only. You need to be careful to escape inverted commas. The following worked for me (running tests tagged with #accessibility tag):
package.json
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"cypress:open": "cypress open",
"cypress:run": "cypress run",
"test:accessibility": "./node_modules/.bin/cypress-tags run -e TAGS=\"#accessibility\"",
"test": "cypress run --spec \"**/*.feature\"",
"eject": "react-scripts eject"
},
Then at the command prompt:
cypress-tags run -e TAGS="#accessibility"
You can use the #focus tag. See https://www.npmjs.com/package/cypress-cucumber-preprocessor
#focus
Scenario: Opening a search engine page
npx cypress run --spec cypress/integration/TestCases/Testsite.feature --env "TAGS=#smoke" --browser chrome",
As far as I know it isn't currently not possible to run tests with a tag. You could create an issue for this in github ( https://github.com/cypress-io/cypress/issues ) to let them implement it.
As a work around we choose to create smoketests and featuretests. The smoketests are in a seperate directory which enables us to only run those test scenario's in stead of the whole test suite. You can do so by running the tests with this command:
npx cypress run --spec /cypress/smoketest/*
This is part of my project.json
"scripts": {
"prestart": "babel-node buildScripts/startMsg.js",
"start": "npm-run-all --parallel security-check open:src lint:watch",
"open:src": "babel-node buildScripts/srcServer.js",
"lint": "esw webpack.config.* src buildScripts --color",
"lint:watch": "npm run lint -- --watch",
"security-check": "nsp check",
"localtunnel": "lt --port 3000",
"share": "npm-run-all --parallel open:src localtunnel"
}
When I run my tasks manually like:
"nsp check" or "npm run lint -- --watch"
it works fine I see output in the console.
Problem is when I'm running my whole app "npm start" or "npm run lint:watch" these tasks are seems not running although I'm not getting any errors in the console and app seems to run fine I'm getting expected content.
What could be the problem here? and what is the difference if run nsp check or npm run security-check shouldn't the same thing happened?
Example when what shows my console when I execute these two above:
console output
I am using a bare npm ( no grunt/gulp) approach to develop my new MEAN project.
My config is like the following:
File package.json:
...
"start": "nodemon ./bin/www",
"lint": "jshint **/*.js",
"test": "mocha --recursive",
"dependencies": {
...
},
"devDependencies": {
...
},
Before starting, I run an npm start and nodemon starts monitoring my project tree for changes, triggering a restart after each source file change.
So far so good.
But what if I'd like to include - say - the lint and/or the test stages on each restart?
I didn't find any clue nor in the nodemon page nor in the npm one...
So you should have a definition of the start in your package.json to first run lint, then test then the actual run server.
You can find an example in following post:
http://substack.net/task_automation_with_npm_run
you should run the 'npm run monitor' command to start the monitoring and the restart should call the npm run start script.
but basically you want to have (based on your package.json)
"scripts": {
"start": "npm run lint & npm run test & node ./myfile.js",
"lint": "jshint **/*.js",
"test": "mocha --recursive",
"monitor": "nodemon ./bin/www"
.....