Skip to content
This repository has been archived by the owner on Aug 4, 2020. It is now read-only.

Commit

Permalink
chore(project): ask for args if coverageDirectory is not default
Browse files Browse the repository at this point in the history
  • Loading branch information
Olavo Parno committed Mar 25, 2019
1 parent fa6b732 commit 99bd036
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 18 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

| Statements | Branches | Functions | Lines | Build Status | Built By | We Love |
| -----------|----------|-----------|-------| ------------ | -------- | ------- |
| ![Statements](https://img.shields.io/badge/Coverage-75.95%25-red.svg "Make me better!") | ![Branches](https://img.shields.io/badge/Coverage-71.74%25-red.svg "Make me better!") | ![Functions](https://img.shields.io/badge/Coverage-80%25-yellow.svg "Make me better!") | ![Lines](https://img.shields.io/badge/Coverage-75.95%25-red.svg "Make me better!") | ![BuildStatus](https://img.shields.io/badge/Build-Passing-brightgreen.svg "Building Status") | ![BuiltBy](https://img.shields.io/badge/TypeScript-Lovers-black.svg "img.shields.io") | ![ForTheBadge](https://img.shields.io/badge/Using-Badges-red.svg "ForTheBadge")
| ![Statements](https://img.shields.io/badge/Coverage-97.42%25-brightgreen.svg "Make me better!") | ![Branches](https://img.shields.io/badge/Coverage-97.37%25-brightgreen.svg "Make me better!") | ![Functions](https://img.shields.io/badge/Coverage-100%25-brightgreen.svg "Make me better!") | ![Lines](https://img.shields.io/badge/Coverage-97.42%25-brightgreen.svg "Make me better!") | ![BuildStatus](https://img.shields.io/badge/Build-Passing-brightgreen.svg "Building Status") | ![BuiltBy](https://img.shields.io/badge/TypeScript-Lovers-black.svg "img.shields.io") | ![ForTheBadge](https://img.shields.io/badge/Using-Badges-red.svg "ForTheBadge")

### TL;DR

Expand Down
21 changes: 4 additions & 17 deletions src/helper/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,9 @@ export default class Helper {
})
this.getBuildStatus()
} else {
console.log('\x1b[1m\x1b[31m', 'Error: ' + coveragePath + ' file not found.')
console.log('\x1b[1m\x1b[32m', 'Do you have Jest installed? If so, is it properly configured?')
console.log('\x1b[1m\x1b[31m', 'Error: ' + coveragePath + ' file not found. Is it at the default location?')
console.log('\x1b[1m\x1b[33m', 'Do you have Jest installed? If so, is it properly configured? If you do, then run me')
console.log('\x1b[1m\x1b[33m', 'by passing args i.e. npm run jest-badges-readme --coverageDir=\'my-custom-coverage-folder\'')
returnValue = false
}
return returnValue
Expand Down Expand Up @@ -81,26 +82,12 @@ export default class Helper {
private getCoveragePath = (path: string): string => {
let coveragePath: string = path
const args = yargs('coverageDir', {}).argv

if (args.coverageDir && (args.coverageDir as string).length > 0) {
coveragePath = `${args.coverageDir as string}/coverage-summary.json`
return coveragePath
}

let jestConfig
const packageJson = require('../../package.json')

if (fs.existsSync('./jestconfig.json')) {
jestConfig = require('../../jestconfig.json')
} else if (fs.existsSync('./jest.config.js')) {
jestConfig = require('../../jest.config.js')
}

if (packageJson.jest && packageJson.jest.coverageDirectory) {
coveragePath = `${packageJson.jest.coverageDirectory.replace('<rootDir>', '.')}/coverage-summary.json`
}
if (jestConfig && jestConfig.coverageDirectory) {
coveragePath = `${jestConfig.coverageDirectory.replace('<rootDir>', '.')}/coverage-summary.json`
}
return coveragePath
}

Expand Down

0 comments on commit 99bd036

Please sign in to comment.