I've found some questions on SO specific to version for jest unit test to publish its result in VSTS build Test Results tab. But no proper solution is found.
Open the report from the web portal by going to Test Plans>Progress Report. The report shows you the status of the test plan you last accessed. However, using the filter bar, you can select one or more test plans in the project.
Select the Execute tab in a test suite and then select a test case. Select More options or right-click to open the context menu. Select View test result. Select the test case within a test suite and then choose to view the test details pane.
Where to put test files. Unit tests run against specific lines of code. So it makes sense to place them right next to that code. Integration tests run against many lines of code in many files.
Jest is an open source JavaScript unit testing framework, used by Facebook to test all JavaScript code including React applications. Jest is built on top of Jasmine.
I've used a different approach, b/c after some research I found that the Jest testResultsProcessor property is deprecated. I'm using the jest-junit package for test reports (which has been worked on more recently than the jest-trx-results-processor, fwiw):
Add jest-junit to package.json
Eg yarn add -D jest-junit
or npm add --save-dev jest-junit
Add a VSTS task to run Jest using the jest-junit results reporter
I used the Yarn task, but you can alternately use the npm task. I used these task arguments:
jest --ci --reporters=jest-junit --reporters=default --coverage --coverageReporters=cobertura --coverageReporters=html
because I also wanted code coverage. To skip code coverage reporting, use these (npm or yarn) task arguments:
jest --ci --reporters=jest-junit --reporters=default
Note that --reporters=default
is there b/c I wanted the default stdout in my build log.
Add a Publish Test Results task
Since we're using the default path, the test results file will be written to ~/junit.xml
(Optional) Add a publish code coverage task, too
If you're running code coverage, you might as well add a task for publishing the code coverage results, too:
If you're using a YAML pipeline, here's equivalent YAML (note that we're using the yarn task instead of npm tasks, but that can be changed):
- task: geeklearningio.gl-vsts-tasks-yarn.yarn-task.Yarn@2 displayName: 'Install dependencies' inputs: Arguments: install --no-progress - task: geeklearningio.gl-vsts-tasks-yarn.yarn-task.Yarn@2 displayName: 'Unit tests' inputs: Arguments: 'test --ci --reporters=jest-junit --reporters=default --coverage --coverageReporters=cobertura' continueOnError: true # Test failures should be published before failing the build - task: PublishTestResults@2 displayName: 'Publish Jest Unit Test Results' inputs: testResultsFiles: junit.xml mergeTestResults: true testRunTitle: 'Jest Unit Tests' failTaskOnFailedTests: true - task: PublishCodeCoverageResults@1 displayName: 'Publish code coverage from Jest tests' inputs: codeCoverageTool: Cobertura summaryFileLocation: '$(System.DefaultWorkingDirectory)/coverage/cobertura-coverage.xml' # reportDirectory: '$(System.DefaultWorkingDirectory)/coverage' failIfCoverageEmpty: true
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With