src/jsdom.js
function fromSource(src, options) {
    const config = {
        features: {
            FetchExternalResources: ['script'],
            ProcessExternalResources: ['script']
        },
        virtualConsole: jsdom.createVirtualConsole().sendTo(console),
        userAgent: options.userAgent
    };

    // The htmlroot option allows root-relative URLs (starting with a slash)
    // to be used for all resources. Without it, root-relative URLs are
    // looked up relative to file://, so will not be found.
    if (options.htmlroot) {
        config.resourceLoader = function(resource, callback) {
            // See whether raw attribute value is root-relative.
            const src = resource.element.getAttribute('src');
            if (src.indexOf('/') === 0) {
                resource.url.pathname = path.join(options.htmlroot, src);
            }

            return resource.defaultFetch(callback);
        };
    }

    if (options.inject) {
        config.onload = function(window) {
            if (typeof options.inject === 'function') {
                options.inject(window);
            } else {
                require(path.join(__dirname, options.inject))(window);
            }
        };
    }

    return new Promise((resolve, reject) => {
        jsdom.env(src, config, (err, res) => {
            if (err) {
                return reject(err);
            }
            return resolve(res);
        });
    }).then((result) => {
        return new Promise((resolve) => {
            setTimeout(() => resolve(result), options.timeout);
        });
    });
}
function fromSource(src, options) {
    const config = {
        features: {
            FetchExternalResources: ['script'],
            ProcessExternalResources: ['script']
        },
        virtualConsole: jsdom.createVirtualConsole().sendTo(console),
        userAgent: options.userAgent
    };

    // The htmlroot option allows root-relative URLs (starting with a slash)
    // to be used for all resources. Without it, root-relative URLs are
    // looked up relative to file://, so will not be found.
    if (options.htmlroot) {
        config.resourceLoader = function(resource, callback) {
            // See whether raw attribute value is root-relative.
            const src = resource.element.getAttribute('src');
            if (src.indexOf('/') === 0) {
                resource.url.pathname = path.join(options.htmlroot, src);
            }

            return resource.defaultFetch(callback);
        };
    }

    if (options.inject) {
        config.onload = function(window) {
            if (typeof options.inject === 'function') {
                options.inject(window);
            } else {
                require(path.join(__dirname, options.inject))(window);
            }
        };
    }

    return new Promise((resolve, reject) => {
        jsdom.env(src, config, (err, res) => {
            if (err) {
                return reject(err);
            }
            return resolve(res);
        });
    }).then((result) => {
        return new Promise((resolve) => {
            setTimeout(() => resolve(result), options.timeout);
        });
    });
}
Load a page.
@param  {String}  src
@param  {Object}  options
@return {Promise}