switch to nyc and rewrite coverage module

This commit is contained in:
Michele Guerini Rocco 2018-06-21 01:10:22 +02:00
parent 3f307b5257
commit 68f56ede58
Signed by: rnhmjoj
GPG Key ID: 91BE884FBA4B591A
6 changed files with 96 additions and 3098 deletions

1
.gitignore vendored
View File

@ -1,5 +1,6 @@
node_modules node_modules
.hubot_history .hubot_history
.nyc_output
matrix-data matrix-data
config/ config/
coverage/ coverage/

View File

@ -8,9 +8,15 @@
"async": "^2.6.1", "async": "^2.6.1",
"chai": "^4.1.2", "chai": "^4.1.2",
"cheerio": "^1.0.0-rc.2", "cheerio": "^1.0.0-rc.2",
"coffee-coverage": "^3.0.0",
"coffeescript": "^1.9.2", "coffeescript": "^1.9.2",
"fast-levenshtein": "^2.0.6", "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": "^2.19.0",
"hubot-bitcoin": "^1.0.3", "hubot-bitcoin": "^1.0.3",
"hubot-diagnostics": "0.0.2", "hubot-diagnostics": "0.0.2",
@ -26,17 +32,26 @@
"hubot-scripts": "^2.17.2", "hubot-scripts": "^2.17.2",
"hubot-shipit": "^0.2.1", "hubot-shipit": "^0.2.1",
"hubot-matrix": "git+https://maxwell.ydns.eu/git/rnhmjoj/hubot-matrix.git", "hubot-matrix": "git+https://maxwell.ydns.eu/git/rnhmjoj/hubot-matrix.git",
"hubot-youtube": "^1.1.0", "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"
}, },
"scripts": { "scripts": {
"coverage": "mocha test/*.coffee --require coffeescript/register --require coffee-coverage/register -R mochawesome --reporter-options reportDir=coverage,reportFilename=coverage scripts/", "test": "nyc mocha test/*.coffee; true"
"test": "mocha test/*.coffee --require coffeescript/register" },
"nyc": {
"include": [
"scripts/*.coffee"
],
"extension": [ ".coffee" ],
"require": [
"coffeescript/register"
],
"reporter": [
"json-summary",
"html"
],
"sourceMap": true,
"instrument": true,
"cache": true
}, },
"engines": { "engines": {
"node": "0.10.x" "node": "0.10.x"

45
scripts/coverage.coffee Normal file
View 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
"""

View File

@ -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

View File

@ -1,23 +1,20 @@
nock = require 'nock'
expect = require("chai").should() expect = require("chai").should()
mock = require 'mock-fs'
Asjon = require './asjon-testing.coffee' Asjon = require './asjon-testing.coffee'
asjon = undefined asjon = undefined
describe 'modulo drone', -> describe 'modulo coverage', ->
before (done) -> before (done) ->
# Inizializzo robot # Inizializzo robot
Asjon (assa) -> Asjon (assa) ->
asjon = assa asjon = assa
after asjon.after after asjon.after
afterEach asjon.clear afterEach asjon.clear
require('../scripts/drone.coffee')(asjon.robot) require('../scripts/coverage.coffee')(asjon.robot)
done() done()
it 'dovrebbe rispondere quando interrogato', (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 = [ questions = [
"asjon mostrami la copertura dei test" "asjon mostrami la copertura dei test"
"asjon copertura dei test" "asjon copertura dei test"
@ -27,32 +24,40 @@ describe 'modulo drone', ->
acc = 0 acc = 0
asjon.receive (e,l) -> asjon.receive (e,l) ->
acc++ acc++
if acc is questions.length then done() if acc is questions.length
done()
questions.map (q) -> asjon.send q questions.map (q) -> asjon.send q
it 'dovrebbe reagire correttamente a un errore', (done) -> it 'dovrebbe reagire correttamente ad un errore di parsing', (done) ->
nock('https://drone.io') # broken report
.get('/github.com/fazo96/asjon/files/coverage/coverage.json') mock
.reply 200, 'invalid answer' 'coverage/coverage-summary.json': '{'
asjon.receive (e,l) -> 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() done()
asjon.send 'asjon coverage' asjon.send 'asjon coverage'
it 'dovrebbe reagire correttamente quando il report non è disponibile (404)', (done) -> it 'dovrebbe reagire correttamente quando il report non è disponibile', (done) ->
nock('https://drone.io') # missing report
.get('/github.com/fazo96/asjon/files/coverage/coverage.json') mock
.reply 404, '404 page not found' 'coverage/coverage-summary.json':
mock.symlink path: '/no-such-file'
asjon.receive (e,l) -> asjon.receive (e,l) ->
l.join().should.match /^Coverage report non disponibile/g l.join().should.match /^report non disponibile/g
done() done()
asjon.send 'asjon coverage' asjon.send 'asjon coverage'
it 'dovrebbe parsare correttamente il report json', (done) -> it 'dovrebbe parsare correttamente il report json', (done) ->
nock('https://drone.io') # fake report
.get('/github.com/fazo96/asjon/files/coverage/coverage.json') mock
.replyWithFile 200, __dirname+'/coverage.json' '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) -> asjon.receive (e,l) ->
l.join().should.match /^=== Coverage: /g l.join().should.match /^=== Coverage: /g
mock.restore()
done() done()
asjon.send 'asjon coverage' asjon.send 'asjon coverage'

File diff suppressed because it is too large Load Diff