selfapi.js
function (baseUrl, callback) {
    var self = this;
    var tests = [];

    // Export own request handler examples as test functions.
    for (var method in self.handlers) {
      var handler = self.handlers[method];
      if (!handler.examples) {
        throw (
          'Handler ' + method.toUpperCase() + ' ' + this.path +
            ' does not have examples!'
        );
      }
      handler.examples.forEach(function (example) {
        var test =
          self.testHandlerExample.bind(self, baseUrl, method, handler, example);
        tests.push(test);
      });
    }

    // Don't hang when there are no children.
    var pendingChildren = Object.keys(self.children).length;
    if (pendingChildren === 0) {
      callback(tests);
      return;
    }

    // Export children's request handler test functions recursively.
    var childBaseUrl = url.parse(String(baseUrl));
    childBaseUrl.pathname = normalizePath(self.path, childBaseUrl.pathname);
    childBaseUrl = url.format(childBaseUrl);
    for (var path in self.children) {
      self.children[path].exportAllTests(childBaseUrl, function (childTests) {
        tests = tests.concat(childTests);
        pendingChildren--;
        if (pendingChildren === 0) {
          callback(tests);
        }
      });
    }
  }
function (baseUrl, callback) {
    var self = this;
    var tests = [];

    // Export own request handler examples as test functions.
    for (var method in self.handlers) {
      var handler = self.handlers[method];
      if (!handler.examples) {
        throw (
          'Handler ' + method.toUpperCase() + ' ' + this.path +
            ' does not have examples!'
        );
      }
      handler.examples.forEach(function (example) {
        var test =
          self.testHandlerExample.bind(self, baseUrl, method, handler, example);
        tests.push(test);
      });
    }

    // Don't hang when there are no children.
    var pendingChildren = Object.keys(self.children).length;
    if (pendingChildren === 0) {
      callback(tests);
      return;
    }

    // Export children's request handler test functions recursively.
    var childBaseUrl = url.parse(String(baseUrl));
    childBaseUrl.pathname = normalizePath(self.path, childBaseUrl.pathname);
    childBaseUrl = url.format(childBaseUrl);
    for (var path in self.children) {
      self.children[path].exportAllTests(childBaseUrl, function (childTests) {
        tests = tests.concat(childTests);
        pendingChildren--;
        if (pendingChildren === 0) {
          callback(tests);
        }
      });
    }
  }
function ( baseUrl , callback ) { var self = this ; var tests = [ ] ; // Export own request handler examples as test functions. for ( var method in self . handlers ) { var handler = self . handlers [ method ] ; if ( ! handler . examples ) { throw ( 'Handler ' + method . toUpperCase ( ) + ' ' + this . path + ' does not have examples!' ) ; } handler . examples . forEach ( function ( example ) { var test = self . testHandlerExample . bind ( self , baseUrl , method , handler , example ) ; tests . push ( test ) ; } ) ; } // Don't hang when there are no children. var pendingChildren = Object . keys ( self . children ) . length ; if ( pendingChildren === 0 ) { callback ( tests ) ; return ; } // Export children's request handler test functions recursively. var childBaseUrl = url . parse ( String ( baseUrl ) ) ; childBaseUrl . pathname = normalizePath ( self . path , childBaseUrl . pathname ) ; childBaseUrl = url . format ( childBaseUrl ) ; for ( var path in self . children ) { self . children [ path ] . exportAllTests ( childBaseUrl , function ( childTests ) { tests = tests . concat ( childTests ) ; pendingChildren -- ; if ( pendingChildren === 0 ) { callback ( tests ) ; } } ) ; } }
Export all request handler examples as self-test functions.
Export all request handler examples as self - test functions .