Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
var jsdom = require("jsdom");
var assert = require("chai").assert;
var expect = require("chai").expect;
var should = require("chai").should();
var chai = require("chai");
var requirejs = require("requirejs");
//chai.config.includeStack = true;
requirejs.config({
nodeRequire: require,
baseUrl: "./src/"
});
//var fs = require("fs");
//var html = fs.readFileSync("test/template.html", "utf8");
jsdom.defaultDocumentFeatures = {
FetchExternalResources : ["script"],
ProcessExternalResources : ["script"],
MutationEvents : "2.0",
QuerySelector : true
};
// load our sample and we'll test core functionality on it, no need to develop that stuff again
var window, doc, donefn, started = false, blast;
doc = jsdom.jsdom("");
window = doc.parentWindow;
GLOBAL.window = window;
GLOBAL.document = doc;
blast = requirejs("blast");
window.addEventListener("load", function () {
if (donefn) {
donefn(); // start tests
}
it("should execute all testcases", (done) => {
var jsdom = require("jsdom")
jsdom.defaultDocumentFeatures = {
FetchExternalResources : ["script"],
ProcessExternalResources : ["script"],
MutationEvents : true,
QuerySelector : true
};
var fs = require("fs")
/* Gets all sub directories in dir */
var getDirectories = (fs, dir) => {
var files = fs.readdirSync(dir)
var result = []
files.forEach((file) => {
var stat = fs.statSync(dir + "/" + file)
if (stat.isDirectory()){
result.push(file)
,testOutput = ''
,sandbox
;
if (!config) {
process.exit(0);
}
if (!process.argv[2]) {
console.log('You must specify a test to run! This file is relative to testDir');
process.exit(1);
}
//Turn off all the jsdom 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
};
TEST_FILE = PATH.join(config.testDir, process.argv[2]);
DO_COVERAGE = TEST_FILE.match(/do_coverage=1/);
TEST_FILE = TEST_FILE.replace(/\?.*/,''); // get rid of any query string
console.log('Testing ' + TEST_FILE + ' with' + (DO_COVERAGE ? '' : 'out') + ' code coverage');
"use strict";
var jsdom = require("jsdom");
jsdom.defaultDocumentFeatures = {
MutationEvents: false
};
var jsdomObj = jsdom.jsdom();
var serverWindow = jsdomObj.defaultView || jsdomObj.parentWindow;
/**
* [wawjr3d] next 2 lines fix issue here:
* https://github.com/brisket/brisket/issues/36
*/
serverWindow.HTMLFrameElement._init = function() {};
serverWindow.HTMLIFrameElement._init = function() {};
module.exports = serverWindow;
// ----------------------------------------------------------------------------
};
location = {
hash: "",
host: "home",
hostname: "home.com",
href: "http://home.com/",
origin: "http://home.com",
pathname: "/",
port: "",
protocol: "http:"
};
jsdom.defaultDocumentFeatures = {
// FetchExternalResources : ["script"],
ProcessExternalResources : ['script', 'img', 'css', 'frame', 'link'],
FetchExternalResources : [],
ProcessExternalResources : [],
"MutationEvents" : '3.0',
"QuerySelector" : false
}
var dojoDom = module.exports = {
/**
// {url:"http://www.weg.de"}
**/
createDocument : function(input, callback){
*
*/
// dependencies
var path = require('path'),
fs = require('fs'),
nopt = require('nopt'),
request = require('request'),
async = require('async'),
jsdom = require('jsdom').jsdom,
mkdirp = require('mkdirp'),
Q = require('q'),
$ = require('jquery')(jsdom().defaultView);
// Setting jsdom global config
require("jsdom").defaultDocumentFeatures = {
FetchExternalResources: false,
ProcessExternalResources: false,
MutationEvents: false,
QuerySelector: false
};
// Locals
var options = {
"outputdir": path,
"format": String,
"help": Boolean,
"rules": String,
"print": Boolean,
"quiet": Boolean
},
shortHand = {
and sent to the client
* path to your script resolves to dir hoxy was launched from.
* jQuery 1.6.1 is used and ships with this plugin
*/
// declare vars, import libs, etc
var jsdomExists = true;
try { var JSDOM = require('jsdom'); }
catch (err) { jsdomExists = false; }
var PATH = require('path');
var VM = require('vm');
var FS = require('fs');
var doctypePatt = /(]*>)/i;
// make sure jsdom gives us an inert DOM
JSDOM.defaultDocumentFeatures = {
FetchExternalResources : false,
ProcessExternalResources : false,
MutationEvents : false,
QuerySelector : false,
};
// utility to cache script objects
var scriptCache = {};
var jQueryCode = './lib/jquery-1.6.1.min.js';
jQueryCode = PATH.resolve(__dirname, jQueryCode);
jQueryCode = FS.readFileSync(jQueryCode,'utf8');
function getScriptFromPath(path){
if (!scriptCache[path]){
var code = FS.readFileSync(path, 'utf8');
scriptCache[path] = VM.createScript(jQueryCode+'\n\n\n'+code);
}
}
};
return MockWriter;
});
helpers.templating = {
compileAndLoad: compileAndLoad,
compileAndRender: compileAndRender,
compileAndRenderAsync: compileAndRenderAsync,
runAsyncFragmentTests: runAsyncFragmentTests,
MockWriter: MockWriter
};
//JSDOM helper functions
require('jsdom').defaultDocumentFeatures = {
FetchExternalResources : ['script'],
ProcessExternalResources : ['script'],
MutationEvents : '2.0',
QuerySelector : false
};
var jsdomOptimizerConfig = require('raptor/optimizer').loadConfigXml(new File(__dirname, 'jsdom-optimizer-config.xml')),
jsdomOptimizer = require('raptor/optimizer').createPageOptimizer(jsdomOptimizerConfig);
function jsdomScripts(dependencies, enabledExtensions) {
if (!enabledExtensions) {
enabledExtensions = ['browser', 'jquery', 'raptor/logging/console'];
}
var deferred = require('raptor/promises').defer();
var document = jsdom.jsdom(response.body, null, {})
var window = document.parentWindow;
window.run(jquery, jqueryFilename)
window.$.fn.spider = function () {
this.each(function () {
var h = window.$(this).attr('href');
if (!isUrl.test(h)) {
h = urlResolve(url, h);
}
self.get(h, url);
})
}
this.currentUrl = url;
if (jsdom.defaultDocumentFeatures.ProcessExternalResources) {
$(function () { r.fn.call(r, window, window.$); })
} else {
r.fn.call(r, window, window.$);
}
this.currentUrl = null;
window.close(); //fix suggested by
}
}
Spider.prototype.log = function (level) {
var replServer = require('repl');
var util = require('util');
var len;
replServer.REPLServer.prototype.displayPrompt = function() {
var l = this.bufferedCommand.length ? 11 : len;
this.rli.setPrompt(this.bufferedCommand.length ? '.......... '.yellow : this.prompt, l);
this.rli.prompt();
};
require('colors');
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() {};