![]() I used Docker for this because it was the quickest way.įirst, set your memory allocation for Docker to at least 4GB for the Sonar container to be able to run correctly. Next, I used this docker-compose file from. This will start a SonarQube instance using Postgres on Open that URL in a browser, log in with admin/admin, and make sure everything is looking good. ![]() There should be a wizard that guides you through creating a security token for your user. Analyzing your React application with Sonar Tools If not, you can always do so in Administration > Security and creating a Sonar user just for project analysis (this is probably a good idea anyway). You’ll need a couple tools to simplify this process. Yarn add -D jest-sonar-reporter Sonar Configuration Install sonarqube-scanner and jest-sonar-reporter into your React project using either yarn or npm. I was expecting to do a bunch of configuration within Sonar itself, but it can all be contained within your React project. const sonarqubeScanner = require("sonarqube-scanner") In the root of your project (at the same level as your package.json) create a file named sonar-project.js with the following contents. "sonar.testExecutionReportPaths": "reports/test-report.xml",Įach of these settings is a standard Sonar configuration property, but they weren’t immediately clear to me. ![]() serverUrl is the URL to your SonarQube instance.token is the security token assigned to your Sonar user.sonar.sources is the base directory for all of your code.This is where your React application lives (in my case the *.tsx files). sonar.exclusions is everything you do not want Sonar to analyze.īy default, CRA puts _tests_ within the src directory.The most important one for me is that we don’t want to be analysis on our tests. In fact, if there is overlap between sonar.sources and sonar.tests then Sonar will throw an indexing error. ![]() So I exclude anything in any _tests_ folder. sonar.tests is the location of all of your tests.is a comma separated list of all files that should be treated as test files.īy default, CRA puts this in /src/_tests_.Ts tests, but they all follow the standard jest pattern of * is the path to the test coverage output file from jest.sonar.testExecutionReportPaths is the path to the jest-sonar-reporter output file.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |