incubator-couchdb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jason Smith <...@iriscouch.com>
Subject Re: [jira] [Commented] (COUCHDB-1397) Function expressions, evals in SpiderMonkey
Date Mon, 06 Feb 2012 01:05:53 GMT
On Mon, Feb 6, 2012 at 8:04 AM, Jason Smith <jhs@iriscouch.com> wrote:
> ## Unit testing
>
> It's imperfect for unit testing; however I think a hypothetical NPM
> package would be fine. It could convert the ddoc functions to
> JavaScript functions in a similar fashion. (Below is the first API
> that popped into my head, no doubt we could make better.)
>
> var assert = require('assert')
>  , couch = require('mock-couchdb')
>
> var ddoc = couch.load_ddoc({views: {people: {map: "function(doc) {
> emit(doc.name, 1) }"}}})
>
> var emitted
> ddoc.on('emit', function(key, val) { emitted = key })
> ddoc.views.people.map({name:"Bob"})
> assert.equal(emitted, "Bob")
>
> --
> Iris Couch

Failing all of that, my personal second choice would be to put all of
those functions in their own CommonJS module.

// map
module.exports = function(doc) {
    var couch = require('couch')
    couch.emit(doc.name, 1)
}

-- 
Iris Couch

Mime
View raw message