Skip to content

Commit 8ed468e

Browse files
tsukhuPatrickJS
authored andcommitted
Add optional support for SonarQube Integration (PatrickJS#1881)
* PR for 1859 fix * SonarCube Integration * Sonar Unit Test results support * SonarQube readme instructions updated * Update README.md * TS lint should use the local application specific version instead of expecting a global version , also added tslint support independent of SonarQube Server providing the linting * Reverting to SonarQube handling the linting * updated angular 5 * upstream merge * Fix for Webpack warning ./node_modules/@angular/core/esm5/core.js error in tests * Made SonarQube optional * Updated based on review comments from @gdi2290 * Minor readme update * README Fix * Update README.md * Added back package lock * added yarn lock
1 parent ba9f1e1 commit 8ed468e

File tree

8 files changed

+21325
-4
lines changed

8 files changed

+21325
-4
lines changed

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ lib-cov
1515
# Coverage directory used by tools like istanbul
1616
coverage
1717

18+
# SonarQube sonar-scanner temp directory
19+
.scannerwork
20+
1821
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
1922
.grunt
2023

@@ -39,6 +42,9 @@ npm-debug.log
3942
# Coverage #
4043
/coverage/
4144

45+
# Generic Unit Sonar Reports #
46+
/reports/
47+
4248
# Typing #
4349
/src/typings/tsd/
4450
/typings/

README.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ Once you have those, you should install these globals with `npm install --global
145145
* `karma` (`npm install --global karma-cli`)
146146
* `protractor` (`npm install --global protractor`)
147147
* `typescript` (`npm install --global typescript`)
148+
* `tslint` (`npm install --global [email protected]`)
148149

149150
## Installing
150151
* `fork` this repo
@@ -466,6 +467,38 @@ starter kit in production on [Netlify](https://www.netlify.com/):
466467

467468
[![Deploy to Netlify](https://www.netlify.com/img/deploy/button.svg)](https://app.netlify.com/start/deploy?repository=https://github.com/AngularClass/angular-starter)
468469

470+
### Optional Integration with SonarQube (for continous code quality)
471+
Assuming you have SonarQube 5.5.6 (LTS) installed
472+
* Setup SonarQube with the [Sonar Typescript plugin](https://github.com/Pablissimo/SonarTsPlugin#installation) and the Generic Test Coverage plugin https://docs.sonarqube.org/display/PLUG/Generic+Test+Coverage
473+
* Install sonar-scanner globally
474+
```bash
475+
npm install --global sonar-scanner
476+
```
477+
* Install the [Karma plugin for sonarqube](https://www.npmjs.com/package/karma-sonarqube-unit-reporter) as a dev dependency
478+
```bash
479+
npm install karma-sonarqube-unit-reporter --save-dev
480+
```
481+
* Sonar Host URL configuration:
482+
Update [`sonar-project.properties`](sonar-project.properties) file for the property `sonar.host.url` to point to your SonarQube server. By default this assumes that the SonarQube server is running locally using the default port
483+
```
484+
sonar.host.url=<Sonar Host URL and Port>
485+
```
486+
* Run the unit tests with sonar reporter enabled
487+
```bash
488+
npm run test:sonar
489+
```
490+
* The test results collected in the results folder in the sonar compatible format
491+
* Push results to SonarCube
492+
```bash
493+
sonar-scanner
494+
```
495+
* If working with SonarQube 6.x it supports [Generic Test Data](https://docs.sonarqube.org/display/SONAR/Generic+Test+Data)
496+
* Modify the [karma.conf.js](config/karma.config.js) to set the appropriate version of the sonarQube
497+
```es6
498+
sonarQubeUnitReporter: {
499+
sonarQubeVersion: '6.x',
500+
}
501+
```
469502
___
470503

471504
enjoy — [**PatrickJS**](https://twitter.com/gdi2290)

config/karma.conf.js

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ module.exports = function (config) {
9393
* available reporters: https://npmjs.org/browse/keyword/karma-reporter
9494
*/
9595
reporters: ['mocha', 'coverage', 'remap-coverage'],
96-
96+
9797
/**
9898
* Web server port.
9999
*/
@@ -135,9 +135,35 @@ module.exports = function (config) {
135135
* Continuous Integration mode
136136
* if true, Karma captures browsers, runs the tests and exits
137137
*/
138-
singleRun: true
138+
singleRun: true,
139+
/**
140+
* For slower machines you may need to have a longer browser
141+
* wait time . Uncomment the line below if required.
142+
*/
143+
// browserNoActivityTimeout: 30000
144+
139145
};
140146

147+
// Optional Sonar Qube Reporter
148+
if (process.env.SONAR_QUBE) {
149+
150+
// SonarQube reporter plugin configuration
151+
configuration.sonarQubeUnitReporter = {
152+
sonarQubeVersion: '5.x',
153+
outputFile: 'reports/ut_report.xml',
154+
overrideTestDescription: true,
155+
testPath: 'src/app',
156+
testFilePattern: '.spec.ts',
157+
useBrowserName: false
158+
};
159+
160+
// Additional lcov format required for
161+
// sonarqube
162+
configuration.remapCoverageReporter.lcovonly = './coverage/coverage.lcov';
163+
164+
configuration.reporters.push('sonarqubeUnit');
165+
}
166+
141167
if (process.env.TRAVIS) {
142168
configuration.browsers = [
143169
'ChromeTravisCi'

config/webpack.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ module.exports = function (options) {
211211
/**
212212
* The (\\|\/) piece accounts for path separators in *nix and Windows
213213
*/
214-
/angular(\\|\/)core(\\|\/)@angular/,
214+
/\@angular(\\|\/)core(\\|\/)esm5/,
215215
helpers.root('src'), // location of your src
216216
{
217217
/**

0 commit comments

Comments
 (0)