How to use the jsdom/lib/old-api.js.env 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 sjwilliams / scrollstory / bin / buildIndex.js View on Github external
}, function(err, html) {
  if (err) {
    console.log('something went wrong', err);
  } else {
    env(html, function(err, window){
      var $ = require('jquery')(window);

      $('h2, h1', '.content').each(function(){
        $(this).nextUntil('h2').wrapAll('<section></section>');
        $(this).prependTo($(this).next('section'));
      });

      var html = '\n' + $('html')[0].outerHTML;
      // console.log(html);
      console.log(beautify(html));
    });
  }
});
github newmips / newmips / utils / jsDomHelper.js View on Github external
return new Promise(function(resolve, reject) {
		var fileData = helpers.readFileSyncWithCatch(fileName);

		if(typeof fileData !== "undefined"){
			// Comment `dust` elements. We need to comment them to allow jsdom to parse the file correctly
			fileData = fileData.replace(/({[&lt;@^:#\/].+?})/g, '');
			// Replace {@__ key=""} in placeholder by {@__ key=||} to avoid jsDom to fail parsing
			fileData = fileData.replace(/placeholder='(.+?)(")(.+?)(")(.+?)'/g, "placeholder='$1|$3|$5'");

			jsdom.env({
				html: fileData,
				src: [jquery],
				done: function (err, window) {
					if(err)
						return reject(err);
					resolve(window.$);
				}
			});

		} else {
			var err = new Error();
			err.message = "Unable to read the file: " + fileName.split("/workspace/").pop();
			reject(err);
		}
	});
}
github certsimple / rosetta-stone / html-to-json.js View on Github external
module.exports = function(originalHTML, cb){
	jsdom.env(originalHTML, ["http://code.jquery.com/jquery.js"], function (errors, window) {
		var $ = window.$;
		var data = {}
		var firstSection = $('h2').each(function(sectionIndex, sectionElement){
			var $sectionElement = $(sectionElement)
			var sectionTitle = $sectionElement.text()
			log('\n\nMAKING SECTION AND TABLE FOR', sectionTitle)
			data[sectionTitle] = {}
			var currentRow = 0
			var currentCell = 0
			var rowName
			var previousCellContents;
			$sectionElement.nextUntil('h2').each(function(nonSectionIndex, element){
				var $element = $(element)
				var elementText = $element.text()
				if ( $element.is('h3') ) {
					// We're done with previous row, so add it
github mthenw / frontail / test / app.js View on Github external
beforeEach((done) =&gt; {
    io = new events.EventEmitter();
    const html = '<title></title><div class="topbar"></div>'
      + '<div class="log"></div><button id="pauseBtn" type="button"></button>'
      + '<input id="filter" type="test">';
    const ansiup = fs.readFileSync('./web/assets/ansi_up.js', 'utf-8');
    const src = fs.readFileSync('./web/assets/app.js', 'utf-8');

    jsdom.env({
      html,
      url: 'http://localhost?filter=line.*',
      src: [ansiup, src],
      onload: (domWindow) =&gt; {
        window = domWindow;

        initApp();
        done();
      }
    });
  });
github gdotdesign / elm-spec / bin / lib / runner.js View on Github external
<title>Elm-Spec</title>
            
          
        `

        var libContents = `
          window.requestAnimationFrame = setTimeout;
          window._elmSpecTestId = ${testId};
        `
        var libFile = temp.openSync({ suffix: '.js' }).path
        fs.writeFileSync(libFile, libContents)

        jsdom.env({
          virtualConsole: jsdom.createVirtualConsole().sendTo(console),
          cookieJar: jsdom.createCookieJar(),
          url: 'http://localhost:8080/',
          html: html,
          scripts: [
            'file:///' + libFile,
            'file:///' + filename
          ],
          done: (err, window) =&gt; {
            if (err) {
              console.log(`Something went wrong on initialization: ${err}`.red)
              process.exit(1)
            }

            window.sessionStorage = new LocalStorage(temp.mkdirSync())
            window.localStorage = new LocalStorage(temp.mkdirSync())
github artsy / benv / index.js View on Github external
var env = {
    html: "",
    done: function(errs, w) {
      global.window = w;
      domGlobals.forEach(function(varName) {
        global[varName] = w[varName] || function(){};
      });
      if (callback) callback();
    }
  };
  if (options !== undefined) {
    for(var key in options) {
      env[key] = options[key];
    }
  }
  jsdom.env(env);
}
github baseljs / basel / lib / crud.js View on Github external
fs.readFile(template, 'utf8', function(error, data) {
	    jsdom.env(data, function (errors, window) {
	        var $ = require('jquery')(window);

	        $('.basel-controller').attr('ng-controller',options.controller);
	        $('.modal-title').text(options.name_);

	        var headTable = $('.basel-table-head').append($('')).find('tr');
	        var bodyTable = $('.basel-table-body').append($('').attr('dir-paginate','item in items | filter: search | itemsPerPage: 10')).find('tr');
	        var form = $('.basel-form');

	        for(var i = 0 ; i &lt; fields.length ; i++){
	        	var field = fields[i];
	        	headTable.append(''+field.name+'');
	        	bodyTable.append('{{item.'+field.name+'}}');

	        	var input = $('<input>').attr({
	        		type:'text',
github artsy / benv / index.js View on Github external
module.exports.render = function(filename, data, callback) {
  if (!window) throw Error('You must run benv.setup first.');
  if (!filename.match('.jade') && !filename.match('.pug')) throw Error('Could not identify template type');
  var fullPath = path.resolve(path.dirname(module.parent.filename), filename);

  var engine = filename.match('.jade') ? require('jade') : require('pug');

  var html = engine.compile(
    fs.readFileSync(fullPath),
    { filename: fullPath }
  )(data);

  jsdom.env(html, function(err, w) {
    var scriptEls = w.document.getElementsByTagName('script');
    Array.prototype.forEach.call(scriptEls, function(el) {
      el.parentNode.removeChild(el);
    });
    var bodyHtml = w.document.getElementsByTagName('body')[0].innerHTML;
    document.getElementsByTagName('body')[0].innerHTML = bodyHtml;
    if (callback) callback();
  });
}
github fuhaiq / umbrella / umbrella-beans / BeanstalkdService.js View on Github external
      (html, next) => jsdom.env({html: html, src: [jquery], done: next}),
      (window, next) => {
github mmanela / chutzpah / Chutzpah / ChutzpahJSRunners / JsDom / chutzpahRunner.js View on Github external
const loadPagePromise = new Promise(function (resolve, reject) {

            jsdom.env({
                url: testFile,
                virtualConsole: virtualConsole,
                userAgent: userAgent, 
                resourceLoader: function (resource, callback) {
                    var href = resource.url.href;
                    return resource.defaultFetch((err, body) => {
                        if (err) {
                            let errorText = error.message;
                            if (!ignoreResourceLoadingError) {
                                chutzpahFunctions.onError(errorText);
                            }
                            chutzpahFunctions.rawLog("!!_!! Resource Error for " + href + " with error " + errorText);

                            return callback(err);
                        }