Skip to content

Commit

Permalink
Merge pull request #38 from smartprocure/feature/browser-result-parser
Browse files Browse the repository at this point in the history
Feature/browser result parser
  • Loading branch information
daedalus28 authored Nov 1, 2017
2 parents 474d5bf + b26e659 commit 4961157
Show file tree
Hide file tree
Showing 10 changed files with 538 additions and 4 deletions.
1 change: 1 addition & 0 deletions .dutirc.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"recommendedPrReviewers": 1,
"lintResultsPath": ".",
"testResultsPath": ".",
"browserResultsPath": ".",
"disallowedStrings": ["#ISSUEID"],
"autoFix": {
"extensions": [".js"]
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 0.8.0

- Add browser test result parser (karma).
- Add prettier configuration.

## 0.7.1

- Fix default configuration not loading properly
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 10 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@
"bin": {
"duti": "bin/duti"
},
"version": "0.7.1",
"version": "0.8.0",
"main": "src/index.js",
"repository": {
"type": "git",
"url": "git+ssh://[email protected]/smartprocure/duti.git"
},
"license": "MIT",
"engines": {
"node": ">=8.0.0"
Expand All @@ -30,6 +34,11 @@
"sourceType": "module"
}
},
"prettier": {
"singleQuote": true,
"semi": false,
"trailingComma": "es5"
},
"dependencies": {
"bluebird": "^3.5.0",
"cosmiconfig": "^2.2.2",
Expand Down
8 changes: 7 additions & 1 deletion src/dangerfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@ let Promise = require('bluebird')
let cosmiconfig = require('cosmiconfig')
let defaultConfig = require('../.dutirc.json')
let duties = require('./duties')
let { getLintResults, getTestResults, log } = require('./utils')
let {
getLintResults,
getTestResults,
getBrowserResults,
log,
} = require('./utils')

let explorer = cosmiconfig('duti', { rcExtensions: true })

Expand All @@ -28,6 +33,7 @@ schedule(async () => {
message: log(message),
lintResults: await getLintResults({ config }),
testResults: await getTestResults({ config }),
browserResults: await getBrowserResults({ config }),
})
)
})
47 changes: 47 additions & 0 deletions src/duties/browserResults.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
let _ = require('lodash/fp')

let hasBrowserErrors = ({ browserResults, fail, message }) => {
if (_.isNil(browserResults)) {
message('Could not find any browser results.')
return
}

let { result, summary } = browserResults

if (result && summary) {
let { error, failed, exitCode } = summary
if (error === false && failed === 0 && exitCode === 0) {
message('Your PR has no browser errors. Great job!')
return
}

if (failed > 0) {
_.flow(
// Flatten test results into one array.
_.values,
_.flatten,
// Filter by failed tests.
_.reject({ success: true }),
// Format error log.
_.map(
f => `\nSuite: ${f.suite}\nDescription: ${f.description}\n${f.log}\n`
),
_.concat([`Your PR has ${failed} failed browser tests:`]),
_.join('\n'),
fail
)(result)
return
}

// All other cases: error is not false, exitCode is not 0 etc.
fail('Browser test error. Please see CI logs for more details.')
} else {
message(
'Incorrect browser result format. Please see CI logs for more details.'
)
}
}

module.exports = {
hasBrowserErrors: hasBrowserErrors,
}
36 changes: 36 additions & 0 deletions src/duties/browserResults.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/* eslint-env jest */

let browser = require('./browserResults')
let browserHelpers = require('../test-data/browser-results')

describe('browser results', () => {
it('fails if they have errors', () => {
let fail = jest.fn()
let message = jest.fn()
let browserResults = browserHelpers.failing
browser.hasBrowserErrors({ browserResults, fail, message })

expect(fail).toHaveBeenCalled()
expect(message).not.toHaveBeenCalled()
})

it('doesnt fail if it is passing', () => {
let fail = jest.fn()
let message = jest.fn()
let browserResults = browserHelpers.passing
browser.hasBrowserErrors({ browserResults, fail, message })

expect(message).toHaveBeenCalled()
expect(fail).not.toHaveBeenCalled()
})

it('doesnt fail but message should be called if data is incorrect', () => {
let fail = jest.fn()
let message = jest.fn()
let browserResults = {}
browser.hasBrowserErrors({ browserResults, fail, message })

expect(message).toHaveBeenCalled()
expect(fail).not.toHaveBeenCalled()
})
})
11 changes: 10 additions & 1 deletion src/duties/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,14 @@ let lint = require('./lint')
let testResults = require('./testResults')
let library = require('./library')
let autoFix = require('./autoFix')
let browserResults = require('./browserResults')

module.exports = Object.assign({}, pr, lint, testResults, library, autoFix)
module.exports = Object.assign(
{},
pr,
lint,
testResults,
browserResults,
library,
autoFix
)
Loading

0 comments on commit 4961157

Please sign in to comment.