Skip to content

Commit

Permalink
quick and dirty test interface for clientside
Browse files Browse the repository at this point in the history
  • Loading branch information
chjj committed Mar 11, 2012
1 parent 45fd7a2 commit 1bf3dc4
Show file tree
Hide file tree
Showing 4 changed files with 105 additions and 0 deletions.
5 changes: 5 additions & 0 deletions test/browser/index.html
@@ -0,0 +1,5 @@
<!doctype html>
<title>marked tests</title>
<p>testing...</p>
<script src="marked.js"></script>
<script src="test.js"></script>
40 changes: 40 additions & 0 deletions test/browser/index.js
@@ -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 changes: 57 additions & 0 deletions test/browser/test.js
@@ -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 changes: 3 additions & 0 deletions test/index.js
Expand Up @@ -34,6 +34,8 @@ var load = function() {
html: fs.readFileSync(file.replace(/[^.]+$/, 'html'), 'utf8')
};
}

return files;
};

var main = function() {
Expand Down Expand Up @@ -290,5 +292,6 @@ if (!module.parent) {
main();
}
} else {
main.load = load;
module.exports = main;
}

0 comments on commit 1bf3dc4

Please sign in to comment.