How to use the jsdom/lib/old-api.jsdom 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 endlessm / eos-knowledge-lib / docs / framework / tutorial / code / cc-ingester2 / index.js View on Github external
const lastModified = $('meta[property="article:modified_time"]')
        .attr('content');

    // Wordpress distinguishes predefined "categories" and free-form "tags".
    // We are likely to make Wordpress categories into featured sets, and
    // Wordpress tags non-featured. For now, we will mark the tag IDs of
    // Wordpress tags with "tag:".
    const wpCategory = $('meta[property="article:section"]')
        .attr('content');
    const wpTags = $('meta[property="article:tag"]')
        .map(function () { return $(this).attr('content'); })
        .get();
    const tags = wpTags.map(t => `tag:${t}`);
    tags.unshift(wpCategory);

    const dom = JSDOM.jsdom($.html(), {
        features: {ProcessExternalResources: false},
    });
    const facts = rules.against(dom);
    const html = facts.get('content')
        .filter(fnode => fnode.scoreFor('paragraphish') > 0)
        .map(fnode => fnode.element.outerHTML).join('');

    // Load the DOM back into Cheerio
    $ = Cheerio.load('<article>');
    $('article').append(html);

    const postAsset = new Libingester.BlogArticle();
    postAsset.set_title(title);
    postAsset.set_synopsis(synopsis);
    postAsset.set_canonical_uri(link);
    if (lastModified)</article>
github endlessm / eos-knowledge-lib / docs / framework / tutorial / code / cc-ingester / index.js View on Github external
const lastModified = $('meta[property="article:modified_time"]')
        .attr('content');

    // Wordpress distinguishes predefined "categories" and free-form "tags".
    // We are likely to make Wordpress categories into featured sets, and
    // Wordpress tags non-featured. For now, we will mark the tag IDs of
    // Wordpress tags with "tag:".
    const wpCategory = $('meta[property="article:section"]')
        .attr('content');
    const wpTags = $('meta[property="article:tag"]')
        .map(function () { return $(this).attr('content'); })
        .get();
    const tags = wpTags.map(t =&gt; `tag:${t}`);
    tags.unshift(wpCategory);

    const dom = JSDOM.jsdom($.html(), {
        features: {ProcessExternalResources: false},
    });
    const facts = rules.against(dom);
    const html = facts.get('content')
        .filter(fnode =&gt; fnode.scoreFor('paragraphish') &gt; 0)
        .map(fnode =&gt; fnode.element.outerHTML).join('');

    // Load the DOM back into Cheerio
    $ = Cheerio.load('<article>');
    $('article').append(html);

    const postAsset = new Libingester.BlogArticle();
    postAsset.set_title(title);
    postAsset.set_synopsis(synopsis);
    postAsset.set_canonical_uri(link);
    if (lastModified)</article>
github formsy / formsy-react / testrunner.js View on Github external
import testrunner from 'nodeunit/lib/reporters/default';
import { jsdom } from 'jsdom/lib/old-api';

global.document = jsdom();
global.window = global.document.defaultView;
global.navigator = global.window.navigator;

testrunner.run(['tests'], {
  error_prefix: '\u001B[31m',
  error_suffix: '\u001B[39m',
  ok_prefix: '\u001B[32m',
  ok_suffix: '\u001B[39m',
  bold_prefix: '\u001B[1m',
  bold_suffix: '\u001B[22m',
  assertion_prefix: '\u001B[35m',
  assertion_suffix: '\u001B[39m',
}, (err) => {
  if (err) {
    process.exit(1);
  }
github rbartoli / threesixty / test / setup.js View on Github external
import { jsdom } from 'jsdom/lib/old-api'

const document = jsdom('', {
  features: {
    FetchExternalResources : ['img']
  }
})

global.document = document
global.window = document.defaultView
global.navigator = global.window.navigator
global.Image = global.window.Image
global.MouseEvent = global.window.MouseEvent

Object.keys(document.defaultView).forEach((property) =&gt; {
  if (typeof global[property] === 'undefined') {
    global[property] = document.defaultView[property]
  }
})
github mozilla / fathom / test / testing.js View on Github external
function staticDom(html) {
    return jsdom(html, {features: {ProcessExternalResources: false,
                                   FetchExternalResources: false}});
}
github nordnet / nordnet-component-kit / test / setup.jsdom.js View on Github external
import { jsdom } from 'jsdom/lib/old-api';

global.document = jsdom('<div id="app"></div>');
global.window = document.defaultView;
global.navigator = global.window.navigator;
github mozilla / fathom / utilsForBackend.js View on Github external
function staticDom(html) {
    return jsdom(html, {features: {ProcessExternalResources: false,
                                   FetchExternalResources: false}});
}