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 786 forks source link

Fail when using MongoDB mapreduce #604

Open mkcedward opened 8 years ago

mkcedward commented 8 years ago

I am trying to run mapReduce via Mongoose against my MongoDB and it is passed when only using mocha to run test case. However, it got error from MongoDB when using istanbul. It got the following exception. Any hints on this issue?

/* Exception Message */ [conn1] ReferenceError: cov_jaRS0vu3yfRncVPF44UeNw is not defined :_funcs1@:1:23 [conn1] mr failed, removing collection :: caused by :: 139 ReferenceError:cov_jaRS0vu3yfRncVPF44UeNw is not defined :_funcs1@:1:23

thevojacek commented 8 years ago

We are having exactly same issue in our development. When we are running unit tests with istanbul, all the tested units which runs mapReduce using Node.JS MongoDB driver fails with same exception message as described above.

We would be grateful for any hints on this issue.

mkcedward commented 8 years ago

I further search for root cause. Somebody mentioned that it is caused by istanbul implementations (https://github.com/Automattic/mongoose/issues/2293).

//Quoted Start// Yeah this is entirely due to how mapReduce works with istanbul - mongodb stringifies your functions to pass them to the mongodb server. Istanbul transforms your code in order to do coverage properly, which is bad because mongodb doesn't know what "__cov_9tvxKQzOKv6vn95EmDGJ3A" is. Just define your map/reduce functions as strings rather than as functions and it should work: //Quoted End//

pinussilvestrus commented 8 years ago

I already got this mongo map reduce error in my mocha tests. Is there another solution than overriding mongos map/reduce functions?