dylanb / gulp-coverage

Gulp coverage reporting for Node.js that is independent of the test runner
MIT License
60 stars 12 forks source link

cover.js - TypeError: Reduce of empty array with no initial value #41

Closed blbigelow closed 8 years ago

blbigelow commented 9 years ago

/Users/bbigelow/work/DAW/scriptsure_platform/node_modules/gulp-coverage/contrib/cover.js:519 splintered.reduce(function(p, c) { ^ TypeError: Reduce of empty array with no initial value at Array.reduce (native) at getSegments (/Users/bbigelow/work/DAW/scriptsure_platform/node_modules/gulp-coverage/contrib/cover.js:519:16) at /Users/bbigelow/work/DAW/scriptsure_platform/node_modules/gulp-coverage/contrib/cover.js:828:28 at Array.forEach (native) at /Users/bbigelow/work/DAW/scriptsure_platform/node_modules/gulp-coverage/contrib/cover.js:811:14 at Array.forEach (native) at CoverageSession.allStats (/Users/bbigelow/work/DAW/scriptsure_platform/node_modules/gulp-coverage/contrib/cover.js:796:31) at Transform._flush (/Users/bbigelow/work/DAW/scriptsure_platform/node_modules/gulp-coverage/index.js:76:31) at Transform. (/Users/bbigelow/work/DAW/scriptsure_platform/node_modules/gulp-coverage/node_modules/through2/node_modules/readable-stream/lib/_stream_transform.js:135:12) at Transform.g (events.js:199:16) at Transform.emit (events.js:129:20) at finishMaybe (/Users/bbigelow/work/DAW/scriptsure_platform/node_modules/gulp-coverage/node_modules/through2/node_modules/readable-stream/lib/_stream_writable.js:371:12) at endWritable (/Users/bbigelow/work/DAW/scriptsure_platform/node_modules/gulp-coverage/node_modules/through2/node_modules/readable-stream/lib/_stream_writable.js:378:3) at Transform.Writable.end (/Users/bbigelow/work/DAW/scriptsure_platform/node_modules/gulp-coverage/node_modules/through2/node_modules/readable-stream/lib/_stream_writable.js:356:5) at DestroyableTransform.onend (/Users/bbigelow/work/DAW/scriptsure_platform/node_modules/gulp-jasmine/node_modules/through2/node_modules/readable-stream/lib/_stream_readable.js:523:10) at DestroyableTransform.g (events.js:199:16)

dylanb commented 9 years ago

Can you provide some context as to the code that was being instrumented when this happened?

blbigelow commented 9 years ago

Sorry late night had to put something down so I didn't forget to do it.

I was debugging through and found it was failing while processing this file:

/**
 * Organization API paths
 * @module routes/v1.0/organization
 * Created by ii on 6/17/2015.
 * @ignore
 */
var express = require('express');
var router = express.Router();
var models = require('../../models');
var Organization = models.Organization;
var constants = require('../../lib/constants');
var util = require('util');
var http_status = require( '../../lib/http_constants' );

/**
 * @api {get} /v1.0/organization/:id GetOrganization
 * @apiName GetOrganization
 * @apiDescription Get the organization.
 * @apiGroup Organizations
 * @apiVersion 1.0.0
 *
 * @apiParam {Number} id of the organization
 *
 */
router.get('/:id', function (req, res) {

    //var id = req.params.id;

    if(req.params){
        Organization.findById(req.params.id).then(function(organization){

            if(organization != null){
                res.status(200).send(organization);
            }else {
                res.status(http_status.NOT_FOUND_404).send({'error': 'Organization with ID: not found'});
            }
        });
    } else {
        res.status(http_status.NOT_FOUND_404).send();
    }

});

/**
 * @api {get} /v1.0/organization GetOrganizations
 * @apiName GetOrganizations
 * @apiDescription Get the organization.
 * @apiGroup Organizations
 * @apiVersion 1.0.0
 *
 * @apiParam {Number} id of the organization
 *
 */
router.get('/', function(req, res) {
    Organization.findAll().then(function(organization){
        if(vendor) {
            res.status(http_status.OK_200).send(organization);
        } else {
            res.status(http_status.NOT_FOUND_404).send({'error': 'No items found'});
        }
    }).catch(function(error){
        res.status(http_status.BAD_REQUEST_400).send(error);
    });
});

/**
 * @api {post} /v1.0/organization CreateOrganization
 * @apiName CreateOrganization
 * @apiDescription Create a new organization.
 * @apiGroup Organization
 * @apiVersion 1.0.0
 *
 * @apiParam {String} name name of the Organization.
 * @apiParam {String} agreement  agreement for Organization
 * @apiParam {String} contactInfo contact info for Organization.
 *
 * @apiSuccess {Number} ID ID of the Organization.
 * @apiSuccess {String} name name of the Organization.
 * @apiSuccess {String} agreement  agreement for Organization
 * @apiSuccess {String} contactInfo contact info for Organization.
 *
 */
router.post('/', function (req, res) {

    var organization = Organization.build({
        name: req.body.name,
        agreement: req.body.agreement,
        contactInfo: req.body.contactInfo
    });

    organization.save()
        .then(function(organization) {
            res.status(200).send(organization);
        })
        .catch(function(error){
            res.status(400).send(error);
        });

});

/**
 * @api {put} /v1.0/organization UpdateOrganization
 * @apiName UpdateOrganization
 * @apiDescription Update the Organization.
 * @apiGroup Organization
 * @apiVersion 1.0.0
 *
 * @apiParam {Number} ID ID of the Organization.
 *
 * @apiSuccess {Number} ID ID of the Organization.
 * @apiSuccess {String} name name of the Organization.
 * @apiSuccess {String} agreement  agreement for Organization
 * @apiSuccess {String} contactInfo contact info for Organization.
 *
 */
router.put('/:id', function (req, res) {

    Organization.findById(req.params.id)
        .then(function(organization){

            organization.updateAttributes({
                name: req.body.name == undefined ? organization.name : req.body.name,
                agreement: req.body.agreement == undefined ? organization.agreement : req.body.agreement,
                contactInfo: req.body.contactInfo == undefined ? organization.contactInfo : req.body.contactInfo
            })
                .then(function(organization){
                    res.status(200).send(organization)
                })
                .catch(function(error){
                    if(error){
                        res.status(400).send(error);
                    }
                });
        })
        .catch(function(error){
            res.status(400).send(error);
        });
});

router.delete('/:id', function(req, res){

    Organization.destroy({where: {id: req.params.id}})
        .then(function (affectedRows) {
            console.log("affected rows: " + affectedRows);
            res.status(204);
            res.end();
        })
        .catch(function (error) {
            res.status(404).json({'error': NOTFOUNDERROR});
        });
});

module.exports = router;
blbigelow commented 9 years ago

I hacked this in this morning, but I have no context of what this could break or what its actually trying to do. https://github.com/blbigelow/gulp-coverage/commit/6007f22de988f7f3241f474b25a61628ac0e4995

dylanb commented 9 years ago

Thanks for the hacking. I will look into this.