gotwarlost / istanbul

Yet another JS code coverage tool that computes statement, line, function and branch coverage with module loader hooks to transparently add coverage when running tests. Supports all JS coverage use cases including unit tests, server side functional tests and browser tests. Built for scale.
Other
8.7k stars 788 forks source link

Failed to generate coverage report. #475

Open marktyers opened 9 years ago

marktyers commented 9 years ago
npm ERR! Linux 3.19.0-26-generic
npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "run" "coverage"
npm ERR! node v4.2.1
npm ERR! npm  v2.14.7
npm ERR! code ELIFECYCLE
npm ERR! taxi@1.0.0 coverage: `istanbul cover -x **/spec/** -x **index.js** --include-all-sources jasmine-node spec`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the taxi@1.0.0 coverage script 'istanbul cover -x **/spec/** -x **index.js** --include-all-sources jasmine-node spec'.
npm ERR! This is most likely a problem with the taxi package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     istanbul cover -x **/spec/** -x **index.js** --include-all-sources jasmine-node spec
npm ERR! You can get their info via:
npm ERR!     npm owner ls taxi
npm ERR! There is likely additional logging output above.

0 info it worked if it ends with ok
1 verbose cli [ '/usr/local/bin/node', '/usr/local/bin/npm', 'run', 'coverage' ]
2 info using npm@2.14.7
3 info using node@v4.2.1
4 verbose run-script [ 'precoverage', 'coverage', 'postcoverage' ]
5 info precoverage taxi@1.0.0
6 info coverage taxi@1.0.0
7 verbose unsafe-perm in lifecycle true
8 info taxi@1.0.0 Failed to exec coverage script
9 verbose stack Error: taxi@1.0.0 coverage: `istanbul cover -x **/spec/** -x **index.js** --include-all-sources jasmine-node spec`
9 verbose stack Exit status 1
9 verbose stack     at EventEmitter.<anonymous> (/usr/local/lib/node_modules/npm/lib/utils/lifecycle.js:214:16)
9 verbose stack     at emitTwo (events.js:87:13)
9 verbose stack     at EventEmitter.emit (events.js:172:7)
9 verbose stack     at ChildProcess.<anonymous> (/usr/local/lib/node_modules/npm/lib/utils/spawn.js:24:14)
9 verbose stack     at emitTwo (events.js:87:13)
9 verbose stack     at ChildProcess.emit (events.js:172:7)
9 verbose stack     at maybeClose (internal/child_process.js:818:16)
9 verbose stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:211:5)
10 verbose pkgid taxi@1.0.0
11 verbose cwd /home/marktyers/Documents/305CDE/labs/07 NodeJS Testing/01 Unit Testing/taxi
12 error Linux 3.19.0-26-generic
13 error argv "/usr/local/bin/node" "/usr/local/bin/npm" "run" "coverage"
14 error node v4.2.1
15 error npm  v2.14.7
16 error code ELIFECYCLE
17 error taxi@1.0.0 coverage: `istanbul cover -x **/spec/** -x **index.js** --include-all-sources jasmine-node spec`
17 error Exit status 1
18 error Failed at the taxi@1.0.0 coverage script 'istanbul cover -x **/spec/** -x **index.js** --include-all-sources jasmine-node spec'.
18 error This is most likely a problem with the taxi package,
18 error not with npm itself.
18 error Tell the author that this fails on your system:
18 error     istanbul cover -x **/spec/** -x **index.js** --include-all-sources jasmine-node spec
18 error You can get their info via:
18 error     npm owner ls taxi
18 error There is likely additional logging output above.
19 verbose exit [ 1, true ]

var sync = require('sync-request');

var home

exports.setHome = (location, callback) => {
    const loc = getLatLon(location)
    home = getLatLon(location)
    var latLng = home.split(',')
    callback({lat:parseFloat(latLng[0]), lng:parseFloat(latLng[1])})
}

exports.getFare = function(destination, callback) {
    var dest = getLatLon(destination)
    const data = getRouteData(home, dest) // this is making the live API call
    var distance = data.routes[0].legs[0].distance.value
    var duration = data.routes[0].legs[0].duration.value
    var cost = calculateFare(distance, duration)
    callback({distance: distance, duration: duration, cost:parseFloat(cost)})
}

/* this function returns API data but the data won't vary between calls. We could get away without mocking this call. */
function getLatLon(address) {
    var url = 'https://maps.googleapis.com/maps/api/geocode/json?region=uk&address='
    var res = sync('GET', url+address)
    data = JSON.parse(res.getBody().toString('utf8'))
    var loc = data.results[0].geometry.location
    return loc.lat.toFixed(6)+','+loc.lng.toFixed(6)
}

/* this function also returns live API data but this data will vary continously based on time of day and traffic conditions. This means it will require mocking in tests. by storing the function in a private variable we can substitute for a different function when testing. Because we are replacing the code block it will never be called by our test suite so we flag the code coverage tool to ignore it. */
/* istanbul ignore next */
var getRouteData = function(start, end) {
    var url = 'https://maps.googleapis.com/maps/api/directions/json?origin='
    url = url+start+'&destination='+end
    console.log(url)
    const res = sync('GET', url)
    return JSON.parse(res.getBody().toString('utf8'))
}

function calculateFare(distance, duration) {
    var cost = distance/127*0.2
    return cost.toFixed(2)
}
Dakuan commented 9 years ago

I'm also finding this, but only when using npm run. If I exec the command directly from bash everything is fine.