spec/precompiler.js
function mockRequireUglify(loadError, callback) {
    var Module = require('module');
    var _resolveFilename = Module._resolveFilename;
    delete require.cache[require.resolve('uglify-js')];
    delete require.cache[require.resolve('../dist/cjs/precompiler')];
    Module._resolveFilename = function(request, mod) {
      if (request === 'uglify-js') {
        throw loadError;
      }
      return _resolveFilename.call(this, request, mod);
    };
    try {
      callback();
    } finally {
      Module._resolveFilename = _resolveFilename;
      delete require.cache[require.resolve('uglify-js')];
      delete require.cache[require.resolve('../dist/cjs/precompiler')];
    }
  }
function mockRequireUglify(loadError, callback) {
    var Module = require('module');
    var _resolveFilename = Module._resolveFilename;
    delete require.cache[require.resolve('uglify-js')];
    delete require.cache[require.resolve('../dist/cjs/precompiler')];
    Module._resolveFilename = function(request, mod) {
      if (request === 'uglify-js') {
        throw loadError;
      }
      return _resolveFilename.call(this, request, mod);
    };
    try {
      callback();
    } finally {
      Module._resolveFilename = _resolveFilename;
      delete require.cache[require.resolve('uglify-js')];
      delete require.cache[require.resolve('../dist/cjs/precompiler')];
    }
  }
function mockRequireUglify ( loadError , callback ) { var Module = require ( 'module' ) ; var _resolveFilename = Module . _resolveFilename ; delete require . cache [ require . resolve ( 'uglify-js' ) ] ; delete require . cache [ require . resolve ( '../dist/cjs/precompiler' ) ] ; Module . _resolveFilename = function ( request , mod ) { if ( request === 'uglify-js' ) { throw loadError ; } return _resolveFilename . call ( this , request , mod ) ; } ; try { callback ( ) ; } finally { Module . _resolveFilename = _resolveFilename ; delete require . cache [ require . resolve ( 'uglify-js' ) ] ; delete require . cache [ require . resolve ( '../dist/cjs/precompiler' ) ] ; } }
Mock the Module.prototype.require-function such that an error is thrown, when "uglify-js" is loaded.

The function cleans up its mess when "callback" is finished

@param {Error} loadError the error that should be thrown if uglify is loaded
@param {function} callback a callback-function to run when the mock is active.
Mock the Module . prototype . require - function such that an error is thrown when uglify - js is loaded .