quick and dirty test interface for clientside

This commit is contained in:
Christopher Jeffrey
2012-03-11 00:43:00 -06:00
parent 45fd7a24f8
commit 1bf3dc4bf7
4 changed files with 105 additions and 0 deletions
+5
View File
@@ -0,0 +1,5 @@
<!doctype html>
<title>marked tests</title>
<p>testing...</p>
<script src="marked.js"></script>
<script src="test.js"></script>
+40
View File
@@ -0,0 +1,40 @@
var fs = require('fs');
var main = require('../')
, load = main.load;
var express = require('express')
, app = express.createServer();
app.use(function(req, res, next) {
var setHeader = res.setHeader;
res.setHeader = function(name) {
switch (name) {
case 'Cache-Control':
case 'Last-Modified':
case 'ETag':
return;
}
return setHeader.apply(res, arguments);
};
next();
});
var dir = __dirname + '/../tests'
, files = {};
app.get('/test.js', function(req, res, next) {
var test = fs.readFileSync(__dirname + '/test.js', 'utf8')
, files = load();
test = test.replace('__TESTS__', JSON.stringify(files));
test = test.replace('__MAIN__', main + '');
res.contentType('.js');
res.send(test);
});
app.use(express.static(__dirname + '/../../lib'));
app.use(express.static(__dirname));
app.listen(8080);
+57
View File
@@ -0,0 +1,57 @@
;(function() {
var files = __TESTS__;
var BREAK_ON_ERROR = false;
var print = function(text) {
var args = Array.prototype.slice.call(arguments, 1)
, i = 0;
text = text.replace(/%\w/g, function() {
return args[i++] || '';
});
if (window.console) window.console.log(text);
document.body.innerHTML += '<pre>' + escape(text) + '</pre>';
};
var console = { log: print };
var pretty = function(text) {
return text;
};
var load = function() {};
Object.keys = Object.keys || function(obj) {
var out = []
, key;
for (key in obj) {
if (Object.prototype.hasOwnProperty.call(obj, key)) {
out.push(key);
}
}
return out;
};
String.prototype.trim = String.prototype.trim || function() {
return this.replace(/^\s+|\s+$/g, '');
};
var escape = function(html, encode) {
return html
.replace(!encode ? /&(?!#?\w+;)/g : /&/g, '&amp;')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;')
.replace(/"/g, '&quot;')
.replace(/'/g, '&#39;');
};
var main = __MAIN__;
main();
}).call(this);
+3
View File
@@ -34,6 +34,8 @@ var load = function() {
html: fs.readFileSync(file.replace(/[^.]+$/, 'html'), 'utf8')
};
}
return files;
};
var main = function() {
@@ -290,5 +292,6 @@ if (!module.parent) {
main();
}
} else {
main.load = load;
module.exports = main;
}