From 16577da96d0cb43b7733a3a04c21aa9ac72bdb64 Mon Sep 17 00:00:00 2001 From: John Christopher Anderson Date: Thu, 25 Feb 2010 01:20:07 +0000 Subject: commonjs require for show list etc via Mikeal Rogers. closes COUCHDB-658 git-svn-id: https://svn.apache.org/repos/asf/couchdb/trunk@916076 13f79535-47bb-0310-9956-ffa450edef68 --- share/www/script/test/design_docs.js | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'share/www') diff --git a/share/www/script/test/design_docs.js b/share/www/script/test/design_docs.js index 9318d2bc..efc2e718 100644 --- a/share/www/script/test/design_docs.js +++ b/share/www/script/test/design_docs.js @@ -38,6 +38,13 @@ function() { var designDoc = { _id:"_design/test", // turn off couch.js id escaping? language: "javascript", + whatever : { + stringzone : "exports.string = 'plankton';", + commonjs : { + whynot : "exports.test = require('../stringzone')", + upper : "exports.testing = require('./whynot').test.string.toUpperCase()" + } + }, views: { all_docs_twice: {map: "function(doc) { emit(doc.integer, null); emit(doc.integer, null) }"}, no_docs: {map: "function(doc) {}"}, @@ -50,9 +57,11 @@ function() { reduce:"function (keys, values) { return \"" + makebigstring(16) + "\"; };"} }, shows: { - simple: "function() {return 'ok'};" + simple: "function() {return 'ok'};", + requirey : "function() { var lib = require('whatever/commonjs/upper'); return lib.testing; };" } - } + }; + var xhr = CouchDB.request("PUT", "/test_suite_db_a/_design/test", {body: JSON.stringify(designDoc)}); var resp = JSON.parse(xhr.responseText); @@ -74,6 +83,11 @@ function() { T(xhr.status == 200); TEquals("ok", xhr.responseText, 'query server used wrong ddoc'); + // test commonjs require + var xhr = CouchDB.request("GET", "/test_suite_db/_design/test/_show/requirey"); + T(xhr.status == 200); + TEquals("PLANKTON", xhr.responseText); + // test that we get design doc info back var dinfo = db.designInfo("_design/test"); TEquals("test", dinfo.name); -- cgit v1.2.3