PERF: Speed up JSHint tests by using local buffers instead of AJAX

requests.
This commit is contained in:
Robin Ward
2014-07-22 14:13:13 -04:00
parent 386b6213a5
commit 4c51258526
4 changed files with 44 additions and 6 deletions

View File

@@ -9,17 +9,24 @@ var qHint = function(name, sourceFile, options, globals) {
}
return asyncTestDiscourse(name, function() {
if (typeof window.__jshintSrc !== "undefined") {
var src = window.__jshintSrc[sourceFile];
if (src) {
start();
qHint.validateFile(src, options, globals);
return;
}
}
console.warn("Using AJAX for JSHint " + sourceFile);
qHint.sendRequest(sourceFile, function(req) {
start();
if (req.status == 200) {
var text = req.responseText;
// Remove our generate IIFEs so we get the same line numbers as original
// files
text = text.replace(/^[^]*\/\/ IIFE Wrapped Content Begins:\n\n/m, "");
text = text.replace(/\n\n\/\/ IIFE Wrapped Content Ends[^]*$/m, "");
qHint.validateFile(text, options, globals);
} else {
ok(false, "HTTP error " + req.status +
@@ -32,6 +39,9 @@ var qHint = function(name, sourceFile, options, globals) {
qHint.validateFile = function (source, options, globals) {
var i, len, err;
source = source.replace(/^[^]*\/\/ IIFE Wrapped Content Begins:\n\n/m, "");
source = source.replace(/\n\n\/\/ IIFE Wrapped Content Ends[^]*$/m, "");
if (JSHINT(source, options, globals)) {
ok(true);
return;