Skip to content

Commit 66873cc

Browse files
committed
bridge: wire up with sonar
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
1 parent d3965e0 commit 66873cc

File tree

6 files changed

+22
-10
lines changed

6 files changed

+22
-10
lines changed

client/data-bridge/jest.config.js

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,5 @@ module.exports = {
3131
'jest-watch-typeahead/filename',
3232
'jest-watch-typeahead/testname',
3333
],
34-
collectCoverageFrom: [
35-
'src/**/*.{ts,vue}',
36-
'!src/@types/**',
37-
'!src/datamodel/**',
38-
'!src/definitions/**',
39-
'!src/mock-data/**',
40-
'!src/mock-entry.ts',
41-
],
4234
clearMocks: true,
4335
};

client/data-bridge/jest.config.unit.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,13 @@ module.exports = require( './jest.config' );
33
module.exports.testMatch = [
44
'**/tests/unit/**/*.spec.(js|jsx|ts|tsx)|**/__tests__/*.(js|jsx|ts|tsx)',
55
];
6+
7+
module.exports.collectCoverageFrom = [
8+
'src/**/*.{ts,vue}',
9+
'!src/@types/**',
10+
'!src/datamodel/**',
11+
'!src/definitions/**',
12+
'!src/mock-data/**',
13+
'!src/mock-entry.ts',
14+
];
15+
module.exports.coverageReporters = [ 'lcov' ];

client/data-bridge/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"test:integration": "vue-cli-service test:unit -c ./jest.config.integration.js",
1616
"test:e2e": "vue-cli-service test:unit -c ./jest.config.e2e.js",
1717
"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",
18+
"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",
1819
"selenium-test": "wdio tests/selenium/wdio.conf.js",
1920
"storybook": "start-storybook",
2021
"build-storybook": "build-storybook"
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
sonar.projectName=Data Bridge
2+
sonar.sources=src
3+
sonar.tests=tests
4+
sonar.javascript.lcov.reportPaths=coverage/lcov.info
5+
sonar.exclusions=dist/**/*,node_modules/**/*,tests/**/*

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"selenium-test:repo": "wdio repo/tests/selenium/wdio.conf.js",
1313
"selenium-test:bridge": "npm --prefix client/data-bridge run selenium-test",
1414
"test": "grunt test && npm run test:bridge && npm run test:tainted-ref",
15+
"test:unit": "npm --prefix client/data-bridge run-script test-unit-coverage",
1516
"test:bridge": "npm --prefix client/data-bridge test",
1617
"test:tainted-ref": "npm --prefix view/lib/wikibase-tainted-ref test",
1718
"fix": "grunt fix"

sonar-project.properties

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1-
sonar.tests=client/data-bridge/tests,client/tests,data-access/tests,lib/tests,repo/tests,view/lib/wikibase-tainted-ref/tests,view/tests
2-
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/**/*
1+
sonar.tests=client/tests,data-access/tests,lib/tests,repo/tests,view/lib/wikibase-tainted-ref/tests,view/tests
2+
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/**/*
33
sonar.sources=client,data-access,lib,repo,view
4+
5+
sonar.modules=bridge
6+
bridge.sonar.projectBaseDir=client/data-bridge

0 commit comments

Comments
 (0)