jest-sonar
Advanced tools
Comparing version 0.2.15 to 0.2.16
@@ -5,2 +5,9 @@ # Changelog | ||
### [0.2.16](https://github.com/sh33dafi/jest-sonar/compare/v0.2.15...v0.2.16) (2023-04-21) | ||
### Features | ||
* added ability to override options via env ([04d333a](https://github.com/sh33dafi/jest-sonar/commit/04d333a50513915c488d3f77d1741e552f10aa9b)) | ||
### [0.2.15](https://github.com/sh33dafi/jest-sonar/compare/v0.2.14...v0.2.15) (2022-12-11) | ||
@@ -7,0 +14,0 @@ |
{ | ||
"name": "jest-sonar", | ||
"version": "0.2.15", | ||
"version": "0.2.16", | ||
"description": "A sonar reporter for jest", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -13,2 +13,3 @@ # jest-sonar | ||
Using yarn: | ||
```bash | ||
@@ -19,2 +20,3 @@ $ yarn add -D jest-sonar | ||
Using npm: | ||
```bash | ||
@@ -27,2 +29,3 @@ $ npm i -D jest-sonar | ||
Configure Jest in your `jest.config` file and add `jest-sonar` to the list of reporters. | ||
```javascript | ||
@@ -41,24 +44,30 @@ module.exports = { | ||
| Option | Description | Default | Accepted values | | ||
|-------------------|-----------------------------------------------------|-----------------------|--------------------------| | ||
| outputDirectory | The directory to which the report should be written | The projects root dir | string | | ||
| outputName | The name of the report | sonar-report.xml | string | | ||
| reportedFilePath | Should the path be relative or absolute | 'relative' | 'relative' or 'absolute' | | ||
| relativeRootDir | The root directory for the relative path | jest `rootDir` | string | | ||
You can set these options when defining the reporter in `jest.config`: | ||
```javascript | ||
module.exports = { | ||
... | ||
reporters: ['default', ['jest-sonar', { | ||
outputDirectory: 'my/custom/directory', | ||
outputName: 'my-new-report-name.xml', | ||
reportedFilePath: 'absolute' | ||
}]], | ||
... | ||
} | ||
| Option | Environment override | Description | Default | Accepted values | | ||
| ---------------- | ----------------------------- | --------------------------------------------------- | --------------------- | ------------------------ | | ||
| outputDirectory | JEST_SONAR_OUTPUT_DIR | The directory to which the report should be written | The projects root dir | string | | ||
| outputName | JEST_SONAR_OUTPUT_NAME | The name of the report | sonar-report.xml | string | | ||
| reportedFilePath | JEST_SONAR_REPORTED_FILE_PATH | Should the path be relative or absolute | 'relative' | 'relative' or 'absolute' | | ||
| relativeRootDir | JEST_SONAR_RELATIVE_ROOT_DIR | The root directory for the relative path | jest `rootDir` | string | | ||
``` | ||
You can set these options when defining the reporter in `jest.config`: | ||
```javascript | ||
module.exports = { | ||
... | ||
reporters: ['default', ['jest-sonar', { | ||
outputDirectory: 'my/custom/directory', | ||
outputName: 'my-new-report-name.xml', | ||
reportedFilePath: 'absolute' | ||
}]], | ||
... | ||
} | ||
``` | ||
Or you can override these options via environment variables. Environment variables will always take precedence over options set via `jest.config` | ||
```bash | ||
$ JEST_SONAR_OUTPUT_DIR=./specialDir/ npm run jest | ||
``` | ||
## Contribution | ||
@@ -70,3 +79,4 @@ | ||
### Creating a pull request | ||
### Creating a pull request | ||
1. Fork the repo on GitHub | ||
@@ -73,0 +83,0 @@ 2. Clone and make changes on your machine |
@@ -6,2 +6,8 @@ const fs = require('fs'); | ||
const REPORTED_FILEPATH_ABSOLUTE = 'absolute'; | ||
const ENV_OPTIONS_MAP = { | ||
JEST_SONAR_OUTPUT_NAME: 'outputName', | ||
JEST_SONAR_OUTPUT_DIR: 'outputDirectory', | ||
JEST_SONAR_REPORTED_FILE_PATH: 'reportedFilePath', | ||
JEST_SONAR_RELATIVE_ROOT_DIR: 'relativeRootDir' | ||
}; | ||
@@ -51,6 +57,17 @@ class JestSonar { | ||
}, | ||
options | ||
options, | ||
this.getEnvOptions() | ||
); | ||
} | ||
getEnvOptions() { | ||
const options = {}; | ||
for (let name in ENV_OPTIONS_MAP) { | ||
if (process.env[name]) { | ||
options[ENV_OPTIONS_MAP[name]] = process.env[name]; | ||
} | ||
} | ||
return options; | ||
} | ||
createDirectory(pathToCreate) { | ||
@@ -57,0 +74,0 @@ pathToCreate.split(path.sep).reduce((prevPath, folder) => { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
20962
199
87
4