1+ var grunt = require ( 'grunt' ) ;
2+
3+ module . exports = function ( ) {
4+ var ROOT = require ( 'path' ) . normalize ( __dirname + '/../..' ) ;
5+ var done = this . async ( ) ;
6+ var uncoveredExpressionCount = 0 ;
7+ var uncoveredLineCount = 0 ;
8+
9+ require ( 'fs' ) . createReadStream ( ROOT + '/coverage.log' )
10+ . pipe ( require ( 'coverify/parse' ) ( function ( error , results ) {
11+ if ( error ) grunt . fatal ( error ) ;
12+
13+ Object . keys ( results )
14+ . sort ( function ( a , b ) {
15+ if ( results [ a ] . length > results [ b ] . length ) return - 1 ;
16+ if ( results [ a ] . length < results [ b ] . length ) return 1 ;
17+ return 0 ;
18+ } )
19+ . forEach ( function ( path ) {
20+ if ( results [ path ] . length === 0 ) return ;
21+ var relativePath = path . replace ( ROOT , '' ) ;
22+ uncoveredExpressionCount += results [ path ] . length ;
23+ grunt . log . error ( results [ path ] . length + ' expressions not covered ' + relativePath ) ;
24+
25+ results [ path ] . forEach ( function ( c ) {
26+ uncoveredLineCount += c . code . split ( '\n' ) . length ;
27+ // console.log(
28+ // 'https://github.com/' + process.env.TRAVIS_REPO_SLUG + '/blob/' + process.env.TRAVIS_BRANCH + relativePath + '#L' + (c.lineNum+1) + '-L' + (c.lineNum+1 + c.code.split('\n').length)
29+ // );
30+ console . log (
31+ 'txmt://open?url=' + encodeURIComponent ( 'file://' + path ) + '&line=' + ( c . lineNum + 1 ) + '&column=' + ( c . column [ 0 ] + 2 )
32+ ) ;
33+ // console.log(c.code.split('\n').map(function(line){return '\t' + line}).join('\n'))
34+ } ) ;
35+ console . log ( '' ) ;
36+ } ) ;
37+
38+ Object . keys ( results ) . sort ( ) . forEach ( function ( path ) {
39+ if ( results [ path ] . length > 0 ) return ;
40+ var relativePath = path . replace ( ROOT , '' ) ;
41+ grunt . log . ok ( '100% coverage ' + relativePath ) ;
42+ } ) ;
43+
44+ if ( uncoveredExpressionCount > 0 ) grunt . log . error ( uncoveredExpressionCount + ' expressions not covered' ) ;
45+ if ( uncoveredLineCount > 0 ) grunt . log . error ( uncoveredLineCount + ' lines not covered' ) ;
46+ done ( ) ;
47+ } ) ) ;
48+ }
0 commit comments