Skip to content

Commit

Permalink
bridge: wire up with sonar
Browse files Browse the repository at this point in the history
Allow sonar to access the bridge coverage.
Apparently codehealth jobs invoke `--if-present test:unit`, not the
complete `test` script, so redirect this script to bridge as well.
See
https://sonarcloud.io/documentation/analysis/coverage/#test-execution
https://www.npmjs.com/package/jest-sonar-reporter

In order to run coverage only for this codehealth job and to not have
that overhead in the normal CI, an extra specialised script is added to
the data-bridge package.json.

The jest coverage creates absolute paths in lcov.info. However, the
tests are run in a docker-container whereas the analysis is performed
outside of it and therefore the paths don't match. Since an option to
create relative paths in lcov.info is not yet available[0], this uses
sed to manually make the paths relative.

Also, it seems that collecting coverage is only really useful for unit
tests and so the coverage related configuration has been moved there.

This patch tries to use the multi module functionality of sonar in order
to split up the sonar configuration. It seems promising so far, but
whether it really works as intended can probably only be seen after it
has been merged into master.

[0]: gotwarlost/istanbul#771
[1]: https://docs.sonarqube.org/display/SONARQUBE51/Analyzing+with+SonarQube+Runner#AnalyzingwithSonarQubeRunner-Multi-moduleProject

Change-Id: Ic2954e35c7c053eae1ba958751334dc23d2f3f3a
  • Loading branch information
wiese committed Oct 30, 2019
1 parent d3965e0 commit 66873cc
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 10 deletions.
8 changes: 0 additions & 8 deletions client/data-bridge/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,5 @@ module.exports = {
'jest-watch-typeahead/filename',
'jest-watch-typeahead/testname',
],
collectCoverageFrom: [
'src/**/*.{ts,vue}',
'!src/@types/**',
'!src/datamodel/**',
'!src/definitions/**',
'!src/mock-data/**',
'!src/mock-entry.ts',
],
clearMocks: true,
};
10 changes: 10 additions & 0 deletions client/data-bridge/jest.config.unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,13 @@ module.exports = require( './jest.config' );
module.exports.testMatch = [
'**/tests/unit/**/*.spec.(js|jsx|ts|tsx)|**/__tests__/*.(js|jsx|ts|tsx)',
];

module.exports.collectCoverageFrom = [
'src/**/*.{ts,vue}',
'!src/@types/**',
'!src/datamodel/**',
'!src/definitions/**',
'!src/mock-data/**',
'!src/mock-entry.ts',
];
module.exports.coverageReporters = [ 'lcov' ];
1 change: 1 addition & 0 deletions client/data-bridge/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"test:integration": "vue-cli-service test:unit -c ./jest.config.integration.js",
"test:e2e": "vue-cli-service test:unit -c ./jest.config.e2e.js",
"test:distnodiff": "npm run build:app -- --dest /tmp/dist && npm run build:init -- --dest /tmp/dist && diff -q ./dist/data-bridge.common.js /tmp/dist/data-bridge.common.js && diff -q ./dist/data-bridge.init.js /tmp/dist/data-bridge.init.js",
"test-unit-coverage": "vue-cli-service test:unit -c ./jest.config.unit.js --coverage && sed -i 's|SF:/src/client/data-bridge/|SF:|g' coverage/lcov.info",
"selenium-test": "wdio tests/selenium/wdio.conf.js",
"storybook": "start-storybook",
"build-storybook": "build-storybook"
Expand Down
5 changes: 5 additions & 0 deletions client/data-bridge/sonar-project.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
sonar.projectName=Data Bridge
sonar.sources=src
sonar.tests=tests
sonar.javascript.lcov.reportPaths=coverage/lcov.info
sonar.exclusions=dist/**/*,node_modules/**/*,tests/**/*
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"selenium-test:repo": "wdio repo/tests/selenium/wdio.conf.js",
"selenium-test:bridge": "npm --prefix client/data-bridge run selenium-test",
"test": "grunt test && npm run test:bridge && npm run test:tainted-ref",
"test:unit": "npm --prefix client/data-bridge run-script test-unit-coverage",
"test:bridge": "npm --prefix client/data-bridge test",
"test:tainted-ref": "npm --prefix view/lib/wikibase-tainted-ref test",
"fix": "grunt fix"
Expand Down
7 changes: 5 additions & 2 deletions sonar-project.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
sonar.tests=client/data-bridge/tests,client/tests,data-access/tests,lib/tests,repo/tests,view/lib/wikibase-tainted-ref/tests,view/tests
sonar.exclusions=client/data-bridge/dist/**/*,client/data-bridge/node_modules/**/*,client/data-bridge/tests/**/*,client/tests/**/*,data-access/tests/**/*,lib/tests/**/*,repo/tests/**/*,view/lib/wikibase-tainted-ref/dist/**/*,view/lib/wikibase-tainted-ref/node_modules/**/*,view/lib/wikibase-tainted-ref/tests/**/*,view/tests/**/*
sonar.tests=client/tests,data-access/tests,lib/tests,repo/tests,view/lib/wikibase-tainted-ref/tests,view/tests
sonar.exclusions=client/data-bridge/**/*,client/tests/**/*,data-access/tests/**/*,lib/tests/**/*,repo/tests/**/*,view/lib/wikibase-tainted-ref/dist/**/*,view/lib/wikibase-tainted-ref/node_modules/**/*,view/lib/wikibase-tainted-ref/tests/**/*,view/tests/**/*
sonar.sources=client,data-access,lib,repo,view

sonar.modules=bridge
bridge.sonar.projectBaseDir=client/data-bridge

0 comments on commit 66873cc

Please sign in to comment.