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

Commit

Permalink
Merge pull request #21 from fintory/develop
Browse files Browse the repository at this point in the history
release
  • Loading branch information
iduuck authored Feb 11, 2019
2 parents 5dceba7 + e8fbc78 commit 016729c
Show file tree
Hide file tree
Showing 11 changed files with 2,777 additions and 86 deletions.
72 changes: 57 additions & 15 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,21 +1,63 @@
version: 2
jobs:
build:
docker:
- image: circleci/node:11.8.0
aliases:
- &restore-node-cache
keys:
# bump version for cache invalidation
- v1-dependencies-{{ checksum "yarn.lock" }}

- &save-node-cache
key: v1-dependencies-{{ checksum "yarn.lock" }}
paths:
- node_modules/

- &install-node-dependencies |
yarn install

working_directory: ~/flow-cov
- &restore-eslint-cache
keys:
- v2-eslint- # the cache has to be restored for every revision

- &save-eslint-cache
key: v2-eslint-{{ .Revision }}
paths:
- .eslintcache

defaults: &defaults
working_directory: ~/flow-cov
docker:
- image: circleci/node:8

jobs:
test-smoke:
<<: *defaults
steps:
- checkout
- restore_cache:
keys:
- v1-dependencies-{{ checksum "package.json" }}
- v1-dependencies-
- run: yarn install
- save_cache:
paths:
- node_modules
key: v1-dependencies-{{ checksum "package.json" }}

- restore_cache: *restore-node-cache
- run: *install-node-dependencies
- save_cache: *save-node-cache
- restore-cache: *restore-eslint-cache
- run: yarn lint
- save_cache: *save-eslint-cache
- run: yarn test

release:
<<: *defaults
steps:
- checkout
- restore_cache: *restore-node-cache
- run: *install-node-dependencies
- save_cache: *save-node-cache
- run: npx semantic-release

workflows:
version: 2

build:
jobs:
- test-smoke
- release:
requires:
- test-smoke
filters:
branches:
only: master
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
node_modules/
coverage/
output.json
22 changes: 21 additions & 1 deletion bin/index.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
#!/usr/bin/env node

const program = require('commander')
const chalk = require('chalk')
const pkg = require('../package.json')
const logError = require('./utils/logError')

program
.version(pkg.version)
.option('-t, --threshold <number>', 'Specify a custom threshold')
.option('-r, --reporters <reporters>', 'Specify custom reporters (multiple allowed with comma)')
.option('-c, --concurrency <numberOfFiles>', 'Number of files that are handled at a time')
.option('--no-progress', 'Use this flag to hide the progress bar')
.option('-t, --threshold <number>', 'Specify a custom threshold')
.option('-P, --pretty', 'Prettify the output (only with `json` reporter)')
.option('-v, --verbose', 'Run `flow-cov` in verbose mode')
.parse(process.argv)

Expand All @@ -18,6 +21,19 @@ async function run() {
const runCoverageTool = require('../lib')
const config = {}

if (!program.progress) {
process.env.SILENT = true
}

if (program.verbose) {
console.log(chalk.red('ATTENTION!'))
console.log(chalk.red(`You are currently running in ${chalk.bold('verbose')} mode.`))
console.log(chalk.red(`The output is possibly not valid for piping, etc.`))
console.log('')

process.env.DEBUG = true
}

if (program.threshold) {
config.threshold = parseInt(program.threshold)
}
Expand All @@ -30,6 +46,10 @@ async function run() {
config.reporters = program.reporters.split(',')
}

if (program.pretty) {
config.pretty = program.pretty
}

const report = await runCoverageTool(config)

if (report.coverageSatisfied) {
Expand Down
13 changes: 12 additions & 1 deletion lib/collectFlowCoverage.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
const flow = require('flow-bin')
const ProgressBar = require('progress')
const Promise = require('bluebird')
const { execFileSync } = require('child_process')
const { genCheckFlowStatus } = require('flow-annotation-check')

let bar

const handleFile = async (config, filePath) => {
try {
const cov = execFileSync(flow, ['coverage', filePath, '--json'], {
Expand All @@ -15,6 +18,8 @@ const handleFile = async (config, filePath) => {
const status = await genCheckFlowStatus(flow, filePath)
const satisfied = locs === 0 || coveragePercentage >= config.threshold

if (bar && !process.env.SILENT) bar.tick()

return {
file,
status,
Expand All @@ -30,5 +35,11 @@ const handleFile = async (config, filePath) => {
}

module.exports = async function collectFlowCoverage(config, files) {
return Promise.map(files, file => handleFile(config, file), { concurrency: config.concurrency })
if (!process.env.SILENT) {
bar = new ProgressBar(':current/:total [:bar]', { total: files.length, clear: true })
}

return Promise.map(files, file => handleFile(config, file), {
concurrency: config.concurrency,
})
}
36 changes: 36 additions & 0 deletions lib/reporters/__test__/json.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
const report = {
filesCoverage: [],
coverage: 100,
coverageSatisfied: true,
flowPassed: true,
config: { threshold: 90 },
}

describe('jsonReporter', () => {
beforeEach(() => {
global.console = { log: () => {} }
})

test('returns the right reporterName', () => {
const reporter = require('../json')
const response = reporter(report)

expect(response.reporterName).toBe('json')
})

test('returns valid stringified json', () => {
const reporter = require('../json')
const response = reporter(report)

expect(() => JSON.parse(response.contents)).not.toThrow()
expect(JSON.parse(response.contents).coverageSatisfied).toEqual(true)
})

test('works with a pretty option', () => {
const reporter = require('../json')
const response = reporter({ ...report, config: { ...report.config, pretty: true } })

expect(() => JSON.parse(response.contents)).not.toThrow()
expect(JSON.parse(response.contents).coverageSatisfied).toEqual(true)
})
})
3 changes: 3 additions & 0 deletions lib/reporters/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
const textReporter = require('./text')
const jsonReporter = require('./json')

module.exports = function launchReporter(type, report) {
switch (type) {
case 'json':
return jsonReporter(report)
case 'text':
return textReporter(report)
default:
Expand Down
10 changes: 10 additions & 0 deletions lib/reporters/json.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module.exports = function jsonReporter(report) {
const contents = JSON.stringify(report, null, report.config.pretty ? 2 : 0)

console.log(contents)

return {
reporterName: 'json',
contents,
}
}
4 changes: 2 additions & 2 deletions lib/utils/logger.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module.exports = function log(message) {
const { DEBUG } = process.env
if (DEBUG && (DEBUG === 'true' || DEBUG === true)) {
const { DEBUG, SILENT } = process.env
if (!SILENT && (DEBUG && (DEBUG === 'true' || DEBUG === true))) {
console.log(message)
}
}
11 changes: 9 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,15 @@
"commander": "^2.19.0",
"fast-glob": "^2.2.6",
"flow-annotation-check": "^1.10.1",
"flow-bin": "^0.92.0"
"flow-bin": "^0.92.0",
"progress": "^2.0.3"
},
"devDependencies": {
"@semantic-release/changelog": "^3.0.2",
"@semantic-release/git": "^7.0.8",
"@semantic-release/github": "^5.2.10",
"@semantic-release/npm": "^5.1.4",
"@semantic-release/release-notes-generator": "^7.1.4",
"babel-eslint": "^10.0.1",
"eslint": "5.13.0",
"eslint-config-airbnb": "17.1.0",
Expand All @@ -37,6 +43,7 @@
"eslint-plugin-prettier": "^3.0.1",
"eslint-plugin-react": "^7.11.0",
"jest": "^24.0.0",
"prettier-eslint": "^8.8.2"
"prettier-eslint": "^8.8.2",
"semantic-release": "^15.13.3"
}
}
9 changes: 9 additions & 0 deletions release.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module.exports = {
plugins: [
'@semantic-release/github',
'@semantic-release/git',
'@semantic-release/npm',
'@semantic-release/release-notes-generator',
'@semantic-release/changelog',
],
}
Loading

0 comments on commit 016729c

Please sign in to comment.