lib/common.js
function(callback) {
      var errName;
      try {
        if (self._covered) {
          // If coverage is request, we want the testModule to reference the
          // code instrumented by istanbul in lib-cov/ instead of any local code in lib/.
          // This passage looks for variables assigned to by require('lib/*')
          // and sets a value for the variable which is the equivalent module in lib-cov.

          var fullModuleName = path.resolve(testModule);
          if (!fullModuleName.match(/\.js$/)) {
            fullModuleName = fullModuleName + '.js';
          }
          var requirements = requiredAs(fullModuleName);

          // for every requirement in lib/, rewrite to lib-cov/
          var newRequirements = underscore.map(requirements, function(req) {
            if (req.source.match(/node_modules/) || !req.source.match(/lib\//)) {
              return undefined;
            }
            req.source = path.resolve(path.dirname(fullModuleName), req.source);
            req.source = req.source.replace(/lib\//, 'lib-cov/');

            return req;
          });

          exportedFunctions = rewire(fullModuleName);

          underscore.each(newRequirements.filter(function(i) { return i; }), function(nr) {
            exportedFunctions.__set__(nr.name, require(nr.source));
          });
        } else {
          exportedFunctions = require(testModule);
        }
      }
      catch (err) {
        if (err.message.indexOf(testModule) !== -1 &&
            err.message.match(/cannot find module/i)) {
            errName = 'file_does_not_exist';
          }
          else {
            errName = 'uncaught_exception';
          }

          test = new Test(errName, null);
          test._markAsFailed(err);
          self._reportTestResult(test.getResultObject());
          callback(err);
          return;
      }

      exportedFunctionsNames = Object.keys(exportedFunctions);
      exportedFunctionsNames = exportedFunctionsNames.filter(isValidTestFunctionName);
      testsLen = exportedFunctionsNames.length;
      initializeFunc = exportedFunctions[constants.TEST_FILE_INITIALIZE_FUNCTION_NAME];
      finalizeFunc = exportedFunctions[constants.TEST_FILE_FINALIZE_FUNCTION_NAME];
      setUpFunc = exportedFunctions[constants.SETUP_FUNCTION_NAME];
      tearDownFunc = exportedFunctions[constants.TEARDOWN_FUNCTION_NAME];

      callback();
    }
function(callback) {
      var errName;
      try {
        if (self._covered) {
          // If coverage is request, we want the testModule to reference the
          // code instrumented by istanbul in lib-cov/ instead of any local code in lib/.
          // This passage looks for variables assigned to by require('lib/*')
          // and sets a value for the variable which is the equivalent module in lib-cov.

          var fullModuleName = path.resolve(testModule);
          if (!fullModuleName.match(/\.js$/)) {
            fullModuleName = fullModuleName + '.js';
          }
          var requirements = requiredAs(fullModuleName);

          // for every requirement in lib/, rewrite to lib-cov/
          var newRequirements = underscore.map(requirements, function(req) {
            if (req.source.match(/node_modules/) || !req.source.match(/lib\//)) {
              return undefined;
            }
            req.source = path.resolve(path.dirname(fullModuleName), req.source);
            req.source = req.source.replace(/lib\//, 'lib-cov/');

            return req;
          });

          exportedFunctions = rewire(fullModuleName);

          underscore.each(newRequirements.filter(function(i) { return i; }), function(nr) {
            exportedFunctions.__set__(nr.name, require(nr.source));
          });
        } else {
          exportedFunctions = require(testModule);
        }
      }
      catch (err) {
        if (err.message.indexOf(testModule) !== -1 &&
            err.message.match(/cannot find module/i)) {
            errName = 'file_does_not_exist';
          }
          else {
            errName = 'uncaught_exception';
          }

          test = new Test(errName, null);
          test._markAsFailed(err);
          self._reportTestResult(test.getResultObject());
          callback(err);
          return;
      }

      exportedFunctionsNames = Object.keys(exportedFunctions);
      exportedFunctionsNames = exportedFunctionsNames.filter(isValidTestFunctionName);
      testsLen = exportedFunctionsNames.length;
      initializeFunc = exportedFunctions[constants.TEST_FILE_INITIALIZE_FUNCTION_NAME];
      finalizeFunc = exportedFunctions[constants.TEST_FILE_FINALIZE_FUNCTION_NAME];
      setUpFunc = exportedFunctions[constants.SETUP_FUNCTION_NAME];
      tearDownFunc = exportedFunctions[constants.TEARDOWN_FUNCTION_NAME];

      callback();
    }
function ( callback ) { var errName ; try { if ( self . _covered ) { // If coverage is request, we want the testModule to reference the // code instrumented by istanbul in lib-cov/ instead of any local code in lib/. // This passage looks for variables assigned to by require('lib/*') // and sets a value for the variable which is the equivalent module in lib-cov. var fullModuleName = path . resolve ( testModule ) ; if ( ! fullModuleName . match ( / \.js$ / ) ) { fullModuleName = fullModuleName + '.js' ; } var requirements = requiredAs ( fullModuleName ) ; // for every requirement in lib/, rewrite to lib-cov/ var newRequirements = underscore . map ( requirements , function ( req ) { if ( req . source . match ( / node_modules / ) || ! req . source . match ( / lib\/ / ) ) { return undefined ; } req . source = path . resolve ( path . dirname ( fullModuleName ) , req . source ) ; req . source = req . source . replace ( / lib\/ / , 'lib-cov/' ) ; return req ; } ) ; exportedFunctions = rewire ( fullModuleName ) ; underscore . each ( newRequirements . filter ( function ( i ) { return i ; } ) , function ( nr ) { exportedFunctions . __set__ ( nr . name , require ( nr . source ) ) ; } ) ; } else { exportedFunctions = require ( testModule ) ; } } catch ( err ) { if ( err . message . indexOf ( testModule ) !== - 1 && err . message . match ( / cannot find module / i ) ) { errName = 'file_does_not_exist' ; } else { errName = 'uncaught_exception' ; } test = new Test ( errName , null ) ; test . _markAsFailed ( err ) ; self . _reportTestResult ( test . getResultObject ( ) ) ; callback ( err ) ; return ; } exportedFunctionsNames = Object . keys ( exportedFunctions ) ; exportedFunctionsNames = exportedFunctionsNames . filter ( isValidTestFunctionName ) ; testsLen = exportedFunctionsNames . length ; initializeFunc = exportedFunctions [ constants . TEST_FILE_INITIALIZE_FUNCTION_NAME ] ; finalizeFunc = exportedFunctions [ constants . TEST_FILE_FINALIZE_FUNCTION_NAME ] ; setUpFunc = exportedFunctions [ constants . SETUP_FUNCTION_NAME ] ; tearDownFunc = exportedFunctions [ constants . TEARDOWN_FUNCTION_NAME ] ; callback ( ) ; }
Require the test file
Require the test file