Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ability to specify multiple file types in testFilePattern section. #35

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,13 +117,14 @@ module.exports = function(config) {

By default, the description of the jasmine tests used as the path attribute in the generated xml. If this is not the case with your tests, you can use the following options to automagically find the right path values. It is the recommended way to use this plugin but to be backward compatible it is not enabled by default.

`testFilePattern` can be specified as single pattern as `testFilePattern:'.spec.js'` or array of patterns `testFilePattern: ['.spec.js', '.spec.ts']`.
```
sonarQubeUnitReporter: {
sonarQubeVersion: 'LATEST',
outputFile: 'reports/ut_report.xml',
overrideTestDescription: true,
testPaths: ['./test', './moreTests'],
testFilePattern: '.spec.js',
testFilePattern: ['.spec.js', '.spec.ts'],
useBrowserName: false
},
```
Expand All @@ -135,4 +136,4 @@ sonarQubeUnitReporter: {
##### Build

* npm install
* npm build
* npm build
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "karma-sonarqube-unit-reporter",
"version": "0.0.18",
"version": "0.0.21",
"description": "A Karma plugin. Report results in sonar-unit-tests xml format.",
"main": "index.js",
"files": [
Expand All @@ -13,7 +13,7 @@
},
"repository": {
"type": "git",
"url": "https://github.com/tornaia/karma-sonarqube-unit-reporter.git"
"url": "https://github.com/swapnilfarande/karma-sonarqube-unit-reporter.git"
},
"keywords": [
"junit",
Expand Down
13 changes: 11 additions & 2 deletions src/file-util.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,18 @@ function findFilesInDir (startPath, filter) {
if (filename !== 'node_modules') {
results = results.concat(findFilesInDir(filename, filter))
}
} else if (filename.endsWith(filter)) {
results.push(filename)
} else {
if (Array.isArray(filter)) {
filter.forEach((f) => {
if (filename.endsWith(f)) {
results.push(filename)
}
})
} else if (filename.endsWith(filter)) {
results.push(filename)
}
}
}
return results
}