2.3.1 • Published 7 months ago

@casualbot/jest-sonar-reporter v2.3.1

Weekly downloads
-
License
MIT
Repository
github
Last release
7 months ago

Jest Sonar Reporter

Quality Gate Status Maintainability Rating

@casualbot/jest-sonar-scanner is a custom results processor for Jest derived from Christian W. original work here.

It has been updated to be usable as a reporter in the jest.config, as well as, provide the ability to output relative paths for the generated XML file.

Installation

Using npm:

npm install --save-dev @casualbot/jest-sonar-reporter

Using yarn:

yarn add --dev @casualbot/jest-sonar-reporter

Usage

In your jest config add the following entry:

{
  "reporters": [ "default", "@casualbot/jest-sonar-reporter" ]
}

Then simply run:

jest

For your Continuous Integration you can simply do:

jest --ci --reporters=default --reporters=@casualbot/jest-sonar-reporter

Usage as testResultsProcessor (deprecated)

The support for testResultsProcessor is only kept for legacy reasons and might be removed in the future. You should therefore prefer to configure @casualbot/jest-sonar-reporter as a reporter.

Should you still want to, add the following entry to your jest config:

{
  "testResultsProcessor": "@casualbot/jest-sonar-reporter"
}

Then simply run:

jest

For your Continuous Integration you can simply do:

jest --ci --testResultsProcessor="@casualbot/jest-sonar-reporter"

Configuration

@casualbot/jest-sonar-reporter offers several configurations based on environment variables or a @casualbot/jest-sonar-reporter key defined in package.json or a reporter option. Environment variable and package.json configuration should be strings. Reporter options should also be strings exception for suiteNameTemplate, classNameTemplate, titleNameTemplate that can also accept a function returning a string.

Environment Variable NameReporter Config NameDescriptionDefaultPossible Injection Values
JEST_SUITE_NAMEsuiteNamename attribute of <testsuites>"jest tests"N/A
JEST_SONAR_OUTPUT_DIRoutputDirectoryDirectory to save the output.process.cwd()N/A
JEST_SONAR_OUTPUT_NAMEoutputNameFile name for the output."jest-report.xml"N/A
JEST_SONAR_OUTPUT_FILEoutputFileFullpath for the output. If defined, outputDirectory and outputName will be overriddenundefinedN/A
JEST_SONAR_56_FORMATformatForSonar56Will generate the xml report for Sonar 5.6falseN/A
JEST_SONAR_RELATIVE_PATHSrelativePathsWill use relative paths when generating the xml reportfalseN/A
JEST_SONAR_UNIQUE_OUTPUT_NAMEuniqueOutputNameCreate unique file name for the output jest-sonar-report-${uuid}.xml, overrides outputNamefalseN/A
JEST_SONAR_SUITE_NAMEsuiteNameTemplateTemplate string for name attribute of the <testsuite>."{title}"{title}, {filepath}, {filename}, {displayName}
JEST_SONAR_CLASSNAMEclassNameTemplateTemplate string for the classname attribute of <testcase>."{classname} {title}"{classname}, {title}, {suitename}, {filepath}, {filename}, {displayName}
JEST_SONAR_TITLEtitleTemplateTemplate string for the name attribute of <testcase>."{classname} {title}"{classname}, {title}, {filepath}, {filename}, {displayName}
JEST_SONAR_ANCESTOR_SEPARATORancestorSeparatorCharacter(s) used to join the describe blocks." "N/A
JEST_SONAR_ADD_FILE_ATTRIBUTEaddFileAttributeAdd file attribute to the output. This config is primarily for Circle CI. This setting provides richer details but may break on other CI platforms. Must be a string."false"N/A
JEST_SONAR_INCLUDE_CONSOLE_OUTPUTincludeConsoleOutputAdds console output to any testSuite that generates stdout during a test run.falseN/A
JEST_SONAR_INCLUDE_SHORT_CONSOLE_OUTPUTincludeShortConsoleOutputAdds short console output (only message value) to any testSuite that generates stdout during a test run.falseN/A
JEST_SONAR_REPORT_TEST_SUITE_ERRORSreportTestSuiteErrorsReports test suites that failed to execute altogether as error. Note: since the suite name cannot be determined from files that fail to load, it will default to file path.falseN/A
JEST_SONAR_NO_STACK_TRACEnoStackTraceOmit stack traces from test failure reports, similar to jest --noStackTracefalseN/A
JEST_USE_PATH_FOR_SUITE_NAMEusePathForSuiteNameDEPRECATED. Use suiteNameTemplate instead. Use file path as the name attribute of <testsuite>"false"N/A

You can configure these options via the command line as seen below:

JEST_SUITE_NAME="Jest JUnit Unit Tests" JEST_SONAR_OUTPUT_DIR="./artifacts" jest

Or you can also define a @casualbot/jest-sonar-reporter key in your package.json. All are string values.

{
  ...,
  "jest": {
    "rootDir": ".",
    "testResultsProcessor": "@casualbot/jest-sonar-reporter"
  },
  "@casualbot/jest-sonar-reporter": {
    "suiteName": "jest tests",
    "outputDirectory": "coverage",
    "outputName": "jest-report.xml",
    "uniqueOutputName": "false",
    "classNameTemplate": "{classname}-{title}",
    "titleTemplate": "{classname}-{title}",
    "ancestorSeparator": " › ",
    "usePathForSuiteName": "true",
    "relativePaths": "true"
  }
}

Or you can define your options in your reporter configuration.

// jest.config.js
{
    reporters: [
        'default', 
        [ 
            '@casualbot/jest-sonar-reporter',
            {
                relativePaths: true,
                outputName: 'sonar-report.xml',
                outputDirectory: 'coverage'
            }
        ]
    ],
}
2.3.0

7 months ago

2.3.1

7 months ago

2.2.7

1 year ago

2.2.6

1 year ago

2.2.5

2 years ago

2.2.4

2 years ago

2.2.3

2 years ago

2.2.2

2 years ago

2.2.1

2 years ago

1.2.1

2 years ago

1.2.0

2 years ago

1.1.0

2 years ago

1.0.0

2 years ago