Skip to content
This repository has been archived by the owner on Mar 7, 2023. It is now read-only.

Commit

Permalink
fix: filter Sonar config "sources" list to only include directories t…
Browse files Browse the repository at this point in the history
…hat exist
  • Loading branch information
mdeanjones committed Dec 19, 2022
1 parent 855d597 commit 217e40e
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
9 changes: 8 additions & 1 deletion packages/ember-cli-sonarqube/lib/report-metrics.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,15 @@ const logProgress = require('./utils/log-progress');
function getSonarConfiguration(config) {
const pkgJson = JSON.parse(fs.readFileSync(path.join(config.projectRoot, 'package.json'), 'utf8'));

const sources = (Array.isArray(pkgJson.keywords) && pkgJson.keywords.includes('ember-addon'))
let sources = (Array.isArray(pkgJson.keywords) && pkgJson.keywords.includes('ember-addon'))
? 'addon,addon-test-support,public'
: 'app,public';

sources = sources
.split(',')
.filter((src) => fs.existsSync(path.join(config.projectRoot, src)))
.join(',');

const executionReport = fs.existsSync(config.reporterOut) ? config.reporterOut : undefined;

const eslintReports = [config.codeLintOut, config.tmplLintOut]
Expand Down Expand Up @@ -83,3 +88,5 @@ module.exports = function reportSonarMetrics(config) {
sonarqubeScanner(sonarConfig, resolve);
});
}

module.exports.getSonarConfiguration = getSonarConfiguration;
20 changes: 20 additions & 0 deletions test-packages/__tests__/get-sonar-configuration-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
const { getConfiguration } = require('@nsf-open/ember-cli-sonarqube/lib/configuration');
const { getSonarConfiguration } = require('@nsf-open/ember-cli-sonarqube/lib/report-metrics');
const { getTestPackage } = require('./test-helpers');


describe('getSonarConfiguration', function () {
const testPackage = getTestPackage('my-addon');

afterEach(function () {
jest.resetModules();
return testPackage.reset();
});

it('filters the sources list to only directories that exist', function () {
const cliConfig = getConfiguration(testPackage.toPath(), { 'dry-run': true });
const sonarConfig = getSonarConfiguration(cliConfig);

expect(sonarConfig.options['sonar.sources']).toEqual('addon');
});
});

0 comments on commit 217e40e

Please sign in to comment.