Return-Path: Delivered-To: apmail-couchdb-user-archive@www.apache.org Received: (qmail 38144 invoked from network); 3 Nov 2009 12:06:27 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 3 Nov 2009 12:06:27 -0000 Received: (qmail 25863 invoked by uid 500); 3 Nov 2009 12:06:26 -0000 Delivered-To: apmail-couchdb-user-archive@couchdb.apache.org Received: (qmail 25778 invoked by uid 500); 3 Nov 2009 12:06:26 -0000 Mailing-List: contact user-help@couchdb.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: user@couchdb.apache.org Delivered-To: mailing list user@couchdb.apache.org Received: (qmail 25767 invoked by uid 500); 3 Nov 2009 12:06:26 -0000 Delivered-To: apmail-incubator-couchdb-user@incubator.apache.org Received: (qmail 25763 invoked by uid 99); 3 Nov 2009 12:06:26 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 03 Nov 2009 12:06:26 +0000 X-ASF-Spam-Status: No, hits=-0.0 required=10.0 tests=SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of gurdiga@gmail.com designates 216.239.58.189 as permitted sender) Received: from [216.239.58.189] (HELO gv-out-0910.google.com) (216.239.58.189) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 03 Nov 2009 12:06:12 +0000 Received: by gv-out-0910.google.com with SMTP id c6so718991gvd.17 for ; Tue, 03 Nov 2009 04:05:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:from:date:message-id :subject:to:content-type; bh=Y/kK2RIOabs6ssw//zTYySer7B3+k5CKfpU5ODJYIjw=; b=F/TNZbZLOFpbZBfGt+kOpinQQfmo5r/XzqZg8Ongdx1O862a9BEbDhHsd/T/VxTSpe 6DlWO3joxg0cZbR2RP9o3x4z1x51MTztt9MKf/94+tPBxSJs7bc4OG7OfYOydWIty0Hd NiyDkxosPUKb9O92wWJ5PDF2emtJVnvz3IAQI= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:from:date:message-id:subject:to:content-type; b=bx6fAFHQFEoKhlkKFL1VaLJI4+oHl66J0CLH2/RGg+PwGwhNuGun4Itr53FeGNAG93 w045GvtV7pXHrJcLuHC58UUQHhMx6X7mX4ykSMaamkQlB/1mtPFo5MahCy+vhNxPEJ8P OEH0wCJZCYxfmbzdwvUCBsrP/rDgZcdLSOnNk= MIME-Version: 1.0 Received: by 10.239.184.168 with SMTP id y40mr615838hbg.194.1257249952159; Tue, 03 Nov 2009 04:05:52 -0800 (PST) From: Vlad GURDIGA Date: Tue, 3 Nov 2009 14:05:32 +0200 Message-ID: Subject: Testing shows and lists To: couchdb-user@incubator.apache.org Content-Type: text/plain; charset=UTF-8 X-Virus-Checked: Checked by ClamAV on apache.org Hello! How would someone test the application code inside shows and lists? Is there any recommended way or some best-practice? The actual page is probably more practical to test inside the browser with something like QUnit. But, before uploading the show to CouchDB I'd like to make sure it does not throw syntactical or other errors like undefined variable/function/whatever. If you get it to CouchDB in an "unstable" state it's pretty uncomfortable to find what's broken even from the logs when you have a page built up from more than a couple page components (with CouchApp macro-instructions like // !code and // !json). You can TDD the code you use all over the application by separating it into a library*. But how would you make sure that the page components and the other code that build up the page do actually glue up together nicely before uploading it? * http://github.com/gurdiga/cozy/tree/master/lib/ Why before? Because it is an earlier feedback, and it is probably *a lot* faster to run it from command line with SpiderMonkey. Now,if you feed the show, which is an anonymous function to js, it only checks for syntactic correctness, because it does not actually run that function. You can try to kinda monkey-patch the function by adding "(" before and ")()" after the function body with a little shell script like this: #!/bin/sh echo "(" cat $1 echo ")();" and then use it like: $ ./mokey-patch.sh ./shows/page.js | js -w -s This way you would have that function ran and you'd find out that you need to mock up the "doc" and "req" variables if you have references to them in your code. When it comes to lists you get one more layer to penetrate: the code that you'll write is given as a closure to the "provides" function, and running the main list function with js does not actually run the code in the closure unless you will try to import somehow the original "provides" function from the CouchDB code, which seamed kinda scary to me and I abandoned this idea. The way which I ended up with was to kinda "export" the application code into a separate file named like "page.app.js" in which I have all my application code and which I inject back to the show file before "couchapp push" to CouchDB. Having it separate gives me the ability to make sure it runs before I get it on-line. Of course I have to fake all the data I get as arguments to the main function, but this turned out not to be that hard*. * http://github.com/gurdiga/cozy/blob/master/shows/book.app.js#L1 The bad thing about my "approach" is that I get almost *twice as much code* uploaded to CouchDB as is actually ran by the show/list because the *.app.js is preprocessed by CouchApp and all the "// !code" macros are expanded. It is functional, it works, but it does not feel quite right. =( I'm kinda stuck here for now, so any good ideas are welcome. :)