1.0.2 • Published 2 years ago

@skodaflow/cypress-execution-sonar-reporter v1.0.2

Weekly downloads
-
License
SEE LICENSE IN eu...
Repository
-
Last release
2 years ago

cypress-execution-sonar-reporter

Cypress test execution reporter for SonarQube, code base is taken over: https://github.com/mmouterde/mocha-sonarqube-reporter

Usage

You need to have authenticated access to registry https://devops.skoda.vwgroup.com/projects/WFA/_packaging/skodaflow-npm/npm/registry/

npm install --save-dev @skodaflow/cypress-execution-sonar-reporter

cypress.json

{
	...
	"reporter": "@skodaflow/cypress-execution-sonar-reporter",
	"reporterOptions": {
		"output": "cypress/results/TEST-web-library.sonar.xml"
	},
	...
}

Multireporters

In this case is used mocha-multi-reporters as example of usage https://www.npmjs.com/package/mocha-multi-reporters

cypress.json

{
	...
	"reporter": "mocha-multi-reporters",
	  "reporterOptions": {
		"configFile": "cypress-reporters.json"
	  },
	...
}

cypress-reporters.json

{
	"reporterEnabled": "mocha-junit-reporter, @skodaflow/cypress-execution-sonar-reporter",
	"mochaJunitReporterReporterOptions": {
		"mochaFile": "cypress/results/TEST-web-library.junit.xml",
		"toConsole": false,
		"attachments": true
	},
	"skodaflowCypressExecutionSonarReporterReporterOptions": {
		"output": "cypress/results/TEST-web-library.sonar.xml",
		"useFullFilePath": true,
		"pathPrefix": "packages/web-library"
	}
}

In this example is used packages/web-library as root directory for tested project in Lerna monorepo structure. It is not needed to use pathPrefix if you have a single package application (no monorepo with multiple packages).

Output

cypress/results/TEST-web-library.sonar.xml

<testExecutions version="1">
<file path="packages/web-library/__tests__/components/button.test.tsx">
<testCase name="Button - Primary: has label" duration="530"/>
<testCase name="Button - Primary: visual-default" duration="799">
<failure message="Snapshot images do not match."><![CDATA[Error: Snapshot images do not match.
    at Context.logMessage (http://localhost:8080/__cypress/src/static/js/0.chunk.js:14195:13)
    at getRet (http://localhost:8080/__cypress/runner/cypress_runner.js:170262:20)
    at tryCatcher (http://localhost:8080/__cypress/runner/cypress_runner.js:26492:23)
    at Function.Promise.attempt.Promise.try (http://localhost:8080/__cypress/runner/cypress_runner.js:23766:29)
    at Context.thenFn (http://localhost:8080/__cypress/runner/cypress_runner.js:170280:63)
    at Context.then (http://localhost:8080/__cypress/runner/cypress_runner.js:170732:21)
    at Context.<anonymous> (http://localhost:8080/__cypress/runner/cypress_runner.js:187034:23)
    at http://localhost:8080/__cypress/runner/cypress_runner.js:185727:17
    at tryCatcher (http://localhost:8080/__cypress/runner/cypress_runner.js:26492:23)]]></failure>
</testCase>
</file>
</testExecutions>

Use this file as input for SonarQube in PR pipeline:

sonar.sources=packages/web-library/src
sonar.tests=packages/web-library/__tests__
sonar.testExecutionReportPaths=packages/web-library/cypress/results/TEST-web-library.sonar.xml

Options

NameDescription
outputfull file path used for report
useFullFilePathuse full test file path in report
pathPrefixtest file path prefix in case of deeper project structure
1.0.2

2 years ago

1.0.1

2 years ago