Skip to content

Commit

Permalink
Merge pull request vokal#6 from jrit/master
Browse files Browse the repository at this point in the history
parse sparse info correctly
  • Loading branch information
jrit committed Mar 9, 2016
2 parents fada843 + 7165e85 commit 2079681
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 5 deletions.
11 changes: 11 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,14 @@ language: node_js
node_js:
- "0.10"
- "0.12"
- "node"
env:
global:
- REPO_OWNER=vokal
- REPO_NAME=cobertura-parse
install:
- npm install -g istanbul
- npm install
script:
- chmod +x run-build.sh
- ./run-build.sh
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cobertura-parse",
"version": "1.0.3",
"version": "1.0.4",
"description": "Parse cobertura coverage to JSON, based on output from lcov-parse",
"main": "source/index.js",
"scripts": {
Expand Down
16 changes: 16 additions & 0 deletions run-build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/bash

npm run testcover

RESULT=$?

COMMIT="${TRAVIS_COMMIT_RANGE##*...}"

if [ $RESULT == 0 ]; then
echo "publish coverage for $COMMIT"
curl -F coverage=@coverage/lcov.info "https://cvr.vokal.io/coverage?owner=$REPO_OWNER&repo=$REPO_NAME&commit=$COMMIT&coveragetype=lcov"
else
curl -X POST "https://cvr.vokal.io/coverage/abort?owner=$REPO_OWNER&repo=$REPO_NAME&commit=$COMMIT"
fi

exit $RESULT
8 changes: 4 additions & 4 deletions source/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ var unpackage = function ( packages )
title: c.$.name,
file: c.$.filename,
functions: {
found: c.methods[ 0 ].method ? c.methods[ 0 ].method.length : 0,
found: c.methods && c.methods[ 0 ].method ? c.methods[ 0 ].method.length : 0,
hit: 0,
details: !c.methods[ 0 ].method ? [] : c.methods[ 0 ].method.map( function ( m )
details: !c.methods || !c.methods[ 0 ].method ? [] : c.methods[ 0 ].method.map( function ( m )
{
return {
name: m.$.name,
Expand All @@ -45,9 +45,9 @@ var unpackage = function ( packages )
} )
},
lines: {
found: c.lines[ 0 ].line ? c.lines[ 0 ].line.length : 0,
found: c.lines && c.lines[ 0 ].line ? c.lines[ 0 ].line.length : 0,
hit: 0,
details: !c.lines[ 0 ].line ? [] : c.lines[ 0 ].line.map( function ( l )
details: !c.lines || !c.lines[ 0 ].line ? [] : c.lines[ 0 ].line.map( function ( l )
{
return {
line: Number( l.$.number ),
Expand Down
25 changes: 25 additions & 0 deletions test/assets/sample2.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version="1.0"?>
<!DOCTYPE coverage SYSTEM "http://cobertura.sourceforge.net/xml/coverage-04.dtd">
<coverage>
<sources>
<source>ios</source>
</sources>
<packages>
<package name="Headers">
<classes>
<class filename="NSException.h" name="NSException.h">
<methods />
<lines>
<line branch="false" hits="0" number="102" />
<line branch="false" hits="0" number="103" />
</lines>
</class>
</classes>
</package>
<package name="Headers2">
<classes>
<class filename="NSException.h" name="NSException.h" />
</classes>
</package>
</packages>
</coverage>
16 changes: 16 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,20 @@ describe( "parseFile", function ()
done();
} );
} );

it( "should parse a sparse file", function ( done )
{
parse.parseFile( path.join( __dirname, "assets", "sample2.xml" ), function ( err, result )
{
assert.equal( err, null );
assert.equal( result.length, 2 );
assert.equal( result[ 0 ].functions.found, 0 );
assert.equal( result[ 0 ].functions.hit, 0 );
assert.equal( result[ 0 ].lines.found, 2 );
assert.equal( result[ 0 ].lines.hit, 0 );
assert.equal( result[ 0 ].functions.details.length, 0 );
assert.equal( result[ 0 ].lines.details.length, 2 );
done();
} );
} );
} );

0 comments on commit 2079681

Please sign in to comment.