switch to nyc and rewrite coverage module
This commit is contained in:
parent
3f307b5257
commit
68f56ede58
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,5 +1,6 @@
|
||||
node_modules
|
||||
.hubot_history
|
||||
.nyc_output
|
||||
matrix-data
|
||||
config/
|
||||
coverage/
|
||||
|
35
package.json
35
package.json
@ -8,9 +8,15 @@
|
||||
"async": "^2.6.1",
|
||||
"chai": "^4.1.2",
|
||||
"cheerio": "^1.0.0-rc.2",
|
||||
"coffee-coverage": "^3.0.0",
|
||||
"coffeescript": "^1.9.2",
|
||||
"fast-levenshtein": "^2.0.6",
|
||||
"mocha": "^5.2.0",
|
||||
"mock-fs": "^4.5.0",
|
||||
"nyc": "^13.0.0",
|
||||
"moment": "^2.22.2",
|
||||
"needle": "^2.2.1",
|
||||
"nock": "^9.3.3",
|
||||
"valid-url": "^1.0.9",
|
||||
"hubot": "^2.19.0",
|
||||
"hubot-bitcoin": "^1.0.3",
|
||||
"hubot-diagnostics": "0.0.2",
|
||||
@ -26,17 +32,26 @@
|
||||
"hubot-scripts": "^2.17.2",
|
||||
"hubot-shipit": "^0.2.1",
|
||||
"hubot-matrix": "git+https://maxwell.ydns.eu/git/rnhmjoj/hubot-matrix.git",
|
||||
"hubot-youtube": "^1.1.0",
|
||||
"mocha": "^5.2.0",
|
||||
"mochawesome": "^3.0.1",
|
||||
"moment": "^2.22.2",
|
||||
"needle": "^2.2.1",
|
||||
"nock": "^9.3.3",
|
||||
"valid-url": "^1.0.9"
|
||||
"hubot-youtube": "^1.1.0"
|
||||
},
|
||||
"scripts": {
|
||||
"coverage": "mocha test/*.coffee --require coffeescript/register --require coffee-coverage/register -R mochawesome --reporter-options reportDir=coverage,reportFilename=coverage scripts/",
|
||||
"test": "mocha test/*.coffee --require coffeescript/register"
|
||||
"test": "nyc mocha test/*.coffee; true"
|
||||
},
|
||||
"nyc": {
|
||||
"include": [
|
||||
"scripts/*.coffee"
|
||||
],
|
||||
"extension": [ ".coffee" ],
|
||||
"require": [
|
||||
"coffeescript/register"
|
||||
],
|
||||
"reporter": [
|
||||
"json-summary",
|
||||
"html"
|
||||
],
|
||||
"sourceMap": true,
|
||||
"instrument": true,
|
||||
"cache": true
|
||||
},
|
||||
"engines": {
|
||||
"node": "0.10.x"
|
||||
|
45
scripts/coverage.coffee
Normal file
45
scripts/coverage.coffee
Normal file
@ -0,0 +1,45 @@
|
||||
# Description:
|
||||
# shows integrity tests coverage
|
||||
#
|
||||
# Dependencies:
|
||||
# None
|
||||
#
|
||||
# Configuration:
|
||||
# None
|
||||
#
|
||||
# Commands:
|
||||
# hubot (mostrami la) copertura (dei test)
|
||||
#
|
||||
# Author:
|
||||
# Enrico Fasoli (fazo96)
|
||||
|
||||
moment = require 'moment'
|
||||
path = require 'path'
|
||||
fs = require 'fs'
|
||||
|
||||
module.exports = (robot) ->
|
||||
robot.respond /(?:mostrami la )?(?:copertura|coverage)(?: dei test)?/i, (res) ->
|
||||
url = 'https://maxwell.ydns.eu/asjon/coverage'
|
||||
file = 'coverage/coverage-summary.json'
|
||||
|
||||
try
|
||||
report = JSON.parse (fs.readFileSync file, 'utf8')
|
||||
catch err
|
||||
if err.code is 'ENOENT'
|
||||
return res.send 'report non disponibile. forse \
|
||||
non è ancora stato generato?'
|
||||
else
|
||||
return res.send "errore nel leggere il report:\n#{err}"
|
||||
|
||||
files = []
|
||||
for name, file of report
|
||||
if name isnt "total"
|
||||
files.push "- #{path.basename name} is covered at #{file.lines.pct}%"
|
||||
|
||||
res.send """
|
||||
=== Coverage: #{report.total.lines.pct}%
|
||||
#{files.join '\n'}
|
||||
|
||||
HTML report: #{url}
|
||||
JSON report: #{url}/coverage-final.json
|
||||
"""
|
@ -1,37 +0,0 @@
|
||||
# Description:
|
||||
# integrazione con drone.io e funzioni annesse
|
||||
#
|
||||
# Dependencies:
|
||||
# None
|
||||
#
|
||||
# Configuration:
|
||||
# None
|
||||
#
|
||||
# Commands:
|
||||
# hubot (mostrami la) copertura (dei test)
|
||||
#
|
||||
# Author:
|
||||
# Enrico Fasoli (fazo96)
|
||||
|
||||
moment = require 'moment'
|
||||
|
||||
module.exports = (robot) ->
|
||||
robot.respond /(?:mostrami la )?(?:copertura|coverage)(?: dei test)?/i, (res) ->
|
||||
url = 'https://drone.io/github.com/fazo96/asjon/files/coverage/coverage.'
|
||||
robot.http(url+'json')
|
||||
.get() (err, resp, body) ->
|
||||
try
|
||||
report = JSON.parse body
|
||||
catch e
|
||||
if /^404/g.test body
|
||||
return res.send 'Coverage report non disponibile (404) forse \
|
||||
non è ancora stato generato?'
|
||||
return res.send 'Errore: '+e+'\n\nRisposta del server: '+body
|
||||
unless report?.files?.push? and report?.coverage?.toFixed?
|
||||
return res.send 'Errore: informazioni insufficienti'
|
||||
t = '=== Coverage: ' + report.coverage.toFixed(0) + '%'
|
||||
t += report.files.map (f) ->
|
||||
'\n - ' + f.filename + ' is covered at ' + f.coverage.toFixed(0) + '%'
|
||||
t += '\nHTML report: '+url+'html'
|
||||
t += '\nJSON report: '+url+'json'
|
||||
res.send t
|
@ -1,23 +1,20 @@
|
||||
nock = require 'nock'
|
||||
expect = require("chai").should()
|
||||
mock = require 'mock-fs'
|
||||
|
||||
Asjon = require './asjon-testing.coffee'
|
||||
asjon = undefined
|
||||
|
||||
describe 'modulo drone', ->
|
||||
describe 'modulo coverage', ->
|
||||
before (done) ->
|
||||
# Inizializzo robot
|
||||
Asjon (assa) ->
|
||||
asjon = assa
|
||||
after asjon.after
|
||||
afterEach asjon.clear
|
||||
require('../scripts/drone.coffee')(asjon.robot)
|
||||
require('../scripts/coverage.coffee')(asjon.robot)
|
||||
done()
|
||||
|
||||
it 'dovrebbe rispondere quando interrogato', (done) ->
|
||||
nock('https://drone.io')
|
||||
.get('/github.com/fazo96/asjon/files/coverage/coverage.json')
|
||||
.reply 200, { coverage: 0, files: [] }
|
||||
questions = [
|
||||
"asjon mostrami la copertura dei test"
|
||||
"asjon copertura dei test"
|
||||
@ -27,32 +24,40 @@ describe 'modulo drone', ->
|
||||
acc = 0
|
||||
asjon.receive (e,l) ->
|
||||
acc++
|
||||
if acc is questions.length then done()
|
||||
if acc is questions.length
|
||||
done()
|
||||
questions.map (q) -> asjon.send q
|
||||
|
||||
it 'dovrebbe reagire correttamente a un errore', (done) ->
|
||||
nock('https://drone.io')
|
||||
.get('/github.com/fazo96/asjon/files/coverage/coverage.json')
|
||||
.reply 200, 'invalid answer'
|
||||
it 'dovrebbe reagire correttamente ad un errore di parsing', (done) ->
|
||||
# broken report
|
||||
mock
|
||||
'coverage/coverage-summary.json': '{'
|
||||
|
||||
asjon.receive (e,l) ->
|
||||
l.join().should.match /^Errore: SyntaxError: Unexpected token/g
|
||||
l.join().should.match /^errore nel leggere il report:\nSyntaxError/g
|
||||
done()
|
||||
asjon.send 'asjon coverage'
|
||||
|
||||
it 'dovrebbe reagire correttamente quando il report non è disponibile (404)', (done) ->
|
||||
nock('https://drone.io')
|
||||
.get('/github.com/fazo96/asjon/files/coverage/coverage.json')
|
||||
.reply 404, '404 page not found'
|
||||
it 'dovrebbe reagire correttamente quando il report non è disponibile', (done) ->
|
||||
# missing report
|
||||
mock
|
||||
'coverage/coverage-summary.json':
|
||||
mock.symlink path: '/no-such-file'
|
||||
asjon.receive (e,l) ->
|
||||
l.join().should.match /^Coverage report non disponibile/g
|
||||
l.join().should.match /^report non disponibile/g
|
||||
done()
|
||||
asjon.send 'asjon coverage'
|
||||
|
||||
it 'dovrebbe parsare correttamente il report json', (done) ->
|
||||
nock('https://drone.io')
|
||||
.get('/github.com/fazo96/asjon/files/coverage/coverage.json')
|
||||
.replyWithFile 200, __dirname+'/coverage.json'
|
||||
# fake report
|
||||
mock
|
||||
'coverage/coverage-summary.json': JSON.stringify
|
||||
total: lines: pct: 73.11
|
||||
'a/b.coffee': lines: pct: 92.12
|
||||
'a/c.coffee': lines: pct: 81.67
|
||||
|
||||
asjon.receive (e,l) ->
|
||||
l.join().should.match /^=== Coverage: /g
|
||||
mock.restore()
|
||||
done()
|
||||
asjon.send 'asjon coverage'
|
3031
test/coverage.json
3031
test/coverage.json
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user