Skip to content

Commit

Permalink
ci: produce jest xml reports only in azure pipelines (#10160)
Browse files Browse the repository at this point in the history
* test: do not report coverage unless in CI

In #10128, we added test report tasks to Azure pipelines. Unfortunately,
this adds some additional overhead and coverage type stuff in _local_
development that we probably don't want.

This PR addresses this issue, and conditionally detects whether running
in CI. If running in CI (e.g. Azure Pipelines, Circle, etc.) it will add
the additional coverage reporter and coverage functionality.

Note: this is currently blocked by watson/ci-info#22

* add GENERATE_JEST_REPORT env var and use it with azure pipelines

* use var to hold normalized (boolean) val from env var
  • Loading branch information
pieh authored and DSchau committed Nov 27, 2018
1 parent 41575f8 commit aca36fe
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 3 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ lib-cov

# Coverage directory used by tools like istanbul
coverage
junit.xml

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt
Expand Down
2 changes: 2 additions & 0 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ steps:
- script: yarn bootstrap

- script: yarn test
env:
GENERATE_JEST_REPORT: true

- task: PublishTestResults@2
displayName: "Publish Test Results"
Expand Down
5 changes: 3 additions & 2 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const builtTestsDirs = pkgs
const distDirs = pkgs.map(p => path.join(p, `dist`))
const ignoreDirs = [].concat(gatsbyBuildDirs, builtTestsDirs, distDirs)
const coverageDirs = pkgs.map(p => path.join(p, `src/**/*.js`))
const useCoverage = !!process.env.GENERATE_JEST_REPORT

module.exports = {
notify: true,
Expand All @@ -31,7 +32,7 @@ module.exports = {
moduleNameMapper: {
"^highlight.js$": `<rootDir>/node_modules/highlight.js/lib/index.js`,
},
collectCoverage: true,
collectCoverage: useCoverage,
coverageReporters: [`json-summary`, `text`, `html`, `cobertura`],
coverageThreshold: {
global: {
Expand All @@ -42,5 +43,5 @@ module.exports = {
},
},
collectCoverageFrom: coverageDirs,
reporters: [`default`, `jest-junit`],
reporters: [`default`].concat(useCoverage ? `jest-junit` : []),
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
"glob": "^7.1.1",
"husky": "1.1.1",
"jest": "^23.5.0",
"jest-junit": "^5.0.0",
"jest-cli": "^23.5.0",
"jest-junit": "^5.0.0",
"lerna": "^3.3.0",
"lint-staged": "^8.0.4",
"npm-run-all": "4.1.5",
Expand Down

0 comments on commit aca36fe

Please sign in to comment.