How to use the jsdom.defaultLevel function in jsdom

To help you get started, we’ve selected a few jsdom examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github facebook / jest / src / lib / jsdom-compat.js View on Github external
} else {
              // In case there was no suitable raise function to use, we
              // still want to throw a meaningful Error (another
              // improvement over the original NOT_IMPLEMENTED).
              throw new Error(message);
            }
          }
        };
      }
    }
  };
}

var jsdom = require('jsdom');
var define = require('jsdom/lib/jsdom/level2/html').define;
var elements = jsdom.defaultLevel;

function _getTimeRangeDummy() {
  return {
    length: 0,
    start: function() { return 0; },
    end: function() { return 0; }
  };
}

if (elements && !elements.HTMLMediaElement) {

  define('HTMLMediaElement', {
    _init: function() {
      this._muted = this.defaultMuted;
      this._volume = 1.0;
      this.readyState = 0;
github arrix / node-readability / lib / readability.js View on Github external
function createDocWithHTML5() {
			var browser = jsdom.browserAugmentation(jsdom.defaultLevel, docOptions);
			var doc = new browser.HTMLDocument();
			var parser = new HTML5.Parser({document: doc});
			parser.parse(html);
			return doc;
		}
github arrix / node-readability / lib / readability.js View on Github external
(function() {
	//hack for older versions of jsdom when features can't be disabled by API
	var core = jsdom.defaultLevel;
	//disable loading frames
	delete core.HTMLFrameElement.prototype.setAttribute;

	//disable script evaluation
	delete core.HTMLScriptElement.prototype.init;
})();
github davglass / yui-repl / lib / repl.js View on Github external
var jsdom = require('jsdom');

//Turn off all the things we don't want.
jsdom.defaultDocumentFeatures = {
    //Don't bring in outside resources
    FetchExternalResources   : false,
    //Don't process them
    ProcessExternalResources : false,
    //Don't expose Mutation events (for performance)
    MutationEvents           : false,
    //Do not use their implementation of QSA
    QuerySelector            : false
};

var dom = jsdom.defaultLevel;
//Hack in focus and blur methods so they don't fail when a YUI widget calls them
dom.Element.prototype.blur = function() {};
dom.Element.prototype.focus = function() {};


exports.startPrompt = function(Y, YUI) {

    var prompt = 'YUI@' + Y.version + '> ';
    len = prompt.length;
    prompt = 'YUI'.magenta + '@'.white + Y.version.yellow + '> '.white;
    var debug = Y.config.debug;


    var repl = replServer.start(prompt);
github fgnass / express-jsdom / lib / express-jsdom.js View on Github external
cache = {},
  stack;

var baseDir = (function() {
  var p = module.parent;
  while (p && p.id != '.') {
    p = p.parent;
  }
  return Path.dirname(p.filename);
}());

/**
 * Monkey-patch jsdom's internal raise method to actually raise an error
 * instead of just collecting it.
 */
jsdom.defaultLevel.Node.prototype.raise = function(type, message, data) {
  if (data && data.error) throw data.error;
  throw new Error(message);
};

/**
 * Creates a new jsdom document.
 */
function createNewDocument(url, html) {
  var document = jsdom.jsdom(html, null, {
    url: url,
    features : {
      FetchExternalResources: false,
      ProcessExternalResources: false,
      MutationEvents: false,
      QuerySelector: true
    },