karma-sonarqube-unit-reporter
karma-sonarqube-unit-reporter copied to clipboard
Support regexps for testFilePattern
Hello,
I'm using your plugin in an hybrid angularJS/angular6 app, so I have both .spec.ts and .spec.js.
Unfortunately, in file-util.js, there is:
} else if (filename.endsWith(filter)) { results.push(filename) }
It would be really nice to change that to .matches(), so regex would be supported !
Thanks,
Especially as in index.js there is:
var testFilePattern = reporterConfig.testFilePattern || '(.spec.ts|.spec.js)'
Hi Guys, Even I'm facing this issue with react application. Any plans for this change?
@kiran8910 no jest for react?
There is an easy hack, at the top of your karma.config.js file (or any other loaded in the browser), add this override:
// Override of string.endWith to workaround sonarqubeUnit unable to use regex in testFilePattern
String.prototype.endsWith = function(regex)
if (regex.startsWith("regex:")) {
return this.match(/.*(.spec.ts|.spec.js)$/);
}
// original implementation
if (this.length < regex.length) {
return false;
}
return this.lastIndexOf(regex) === this.length - regex.length;
};
and then in your sonarQubeUnitReporter
config block, add
sonarQubeUnitReporter: {
[...]
testFilePattern: "regex:"
},
Not super clean, but it works.
Thanks for the update.