mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
PERF: Speed up JSHint tests by using local buffers instead of AJAX
requests.
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user