Skip to content

Commit

Permalink
Add optional support for SonarQube Integration (PatrickJS#1881)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
tsukhu authored and PatrickJS committed Mar 1, 2018
1 parent ba9f1e1 commit 8ed468e
Show file tree
Hide file tree
Showing 8 changed files with 21,325 additions and 4 deletions.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ lib-cov
# Coverage directory used by tools like istanbul
coverage

# SonarQube sonar-scanner temp directory
.scannerwork

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

Expand All @@ -39,6 +42,9 @@ npm-debug.log
# Coverage #
/coverage/

# Generic Unit Sonar Reports #
/reports/

# Typing #
/src/typings/tsd/
/typings/
Expand Down
33 changes: 33 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ Once you have those, you should install these globals with `npm install --global
* `karma` (`npm install --global karma-cli`)
* `protractor` (`npm install --global protractor`)
* `typescript` (`npm install --global typescript`)
* `tslint` (`npm install --global [email protected]`)

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

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

### Optional Integration with SonarQube (for continous code quality)
Assuming you have SonarQube 5.5.6 (LTS) installed
* 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
* Install sonar-scanner globally
```bash
npm install --global sonar-scanner
```
* Install the [Karma plugin for sonarqube](https://www.npmjs.com/package/karma-sonarqube-unit-reporter) as a dev dependency
```bash
npm install karma-sonarqube-unit-reporter --save-dev
```
* Sonar Host URL configuration:
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
```
sonar.host.url=<Sonar Host URL and Port>
```
* Run the unit tests with sonar reporter enabled
```bash
npm run test:sonar
```
* The test results collected in the results folder in the sonar compatible format
* Push results to SonarCube
```bash
sonar-scanner
```
* If working with SonarQube 6.x it supports [Generic Test Data](https://docs.sonarqube.org/display/SONAR/Generic+Test+Data)
* Modify the [karma.conf.js](config/karma.config.js) to set the appropriate version of the sonarQube
```es6
sonarQubeUnitReporter: {
sonarQubeVersion: '6.x',
}
```
___

enjoy — [**PatrickJS**](https://twitter.com/gdi2290)
Expand Down
30 changes: 28 additions & 2 deletions config/karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ module.exports = function (config) {
* available reporters: https://npmjs.org/browse/keyword/karma-reporter
*/
reporters: ['mocha', 'coverage', 'remap-coverage'],

/**
* Web server port.
*/
Expand Down Expand Up @@ -135,9 +135,35 @@ module.exports = function (config) {
* Continuous Integration mode
* if true, Karma captures browsers, runs the tests and exits
*/
singleRun: true
singleRun: true,
/**
* For slower machines you may need to have a longer browser
* wait time . Uncomment the line below if required.
*/
// browserNoActivityTimeout: 30000

};

// Optional Sonar Qube Reporter
if (process.env.SONAR_QUBE) {

// SonarQube reporter plugin configuration
configuration.sonarQubeUnitReporter = {
sonarQubeVersion: '5.x',
outputFile: 'reports/ut_report.xml',
overrideTestDescription: true,
testPath: 'src/app',
testFilePattern: '.spec.ts',
useBrowserName: false
};

// Additional lcov format required for
// sonarqube
configuration.remapCoverageReporter.lcovonly = './coverage/coverage.lcov';

configuration.reporters.push('sonarqubeUnit');
}

if (process.env.TRAVIS) {
configuration.browsers = [
'ChromeTravisCi'
Expand Down
2 changes: 1 addition & 1 deletion config/webpack.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ module.exports = function (options) {
/**
* The (\\|\/) piece accounts for path separators in *nix and Windows
*/
/angular(\\|\/)core(\\|\/)@angular/,
/\@angular(\\|\/)core(\\|\/)esm5/,
helpers.root('src'), // location of your src
{
/**
Expand Down
Loading

0 comments on commit 8ed468e

Please sign in to comment.