Permalink
Browse files

documented the sandbox function

  • Loading branch information...
1 parent 5ba6f99 commit cf2f52929fbdd5f2024e68e5e75183248d5c1fd4 @caolan committed Sep 25, 2010
Showing with 29 additions and 1 deletion.
  1. +16 −0 README.md
  2. +13 −1 lib/utils.js
View
@@ -323,6 +323,22 @@ For a reference implementation of a test runner, see lib/testrunner.js in the
nodeunit project directory.
+Sandbox utility
+---------------
+
+This is a function which evaluates JavaScript files in a sandbox and returns the
+context. The sandbox function can be used for testing client-side code or private
+un-exported functions within a module.
+
+ var sandbox = require('nodeunit').utils.sandbox;
+ var example = sandbox('example.js');
+
+__sandbox(files, sandbox)__ - Evaluates JavaScript files in a sandbox, returning
+the context. The first argument can either be a single filename or an array of
+filenames. If multiple filenames are given their contents are concatenated before
+evalution. The second argument is an optional context to use for the sandbox.
+
+
Running the nodeunit Tests
--------------------------
View
@@ -75,7 +75,19 @@ exports.modulePaths = function (paths, callback) {
}, callback);
};
-exports.sandbox = function (files, sandbox) {
+/**
+ * Evaluates JavaScript files in a sandbox, returning the context. The first
+ * argument can either be a single filename or an array of filenames. If
+ * multiple filenames are given their contents are concatenated before
+ * evalution. The second argument is an optional context to use for the sandbox.
+ *
+ * @param files
+ * @param {Object} sandbox
+ * @return {Object}
+ * @api public
+ */
+
+exports.sandbox = function (files, /*optional*/sandbox) {
var source, script, result;
if (!(files instanceof Array)) {
files = [files];

1 comment on commit cf2f529

Contributor

azatoth commented on cf2f529 Sep 25, 2010

That sounds good; By the way, I've posted an question at http://groups.google.com/group/nodejs/browse_thread/thread/86a76fbc14758290# regarding the lack of global objects; though I've not getting any replies.

Please sign in to comment.