-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 9032db1
Showing
4 changed files
with
157 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
|
||
/node_modules/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
/** | ||
* Copyright (c) 2012 Andreas Madsen | ||
* MIT License | ||
*/ | ||
|
||
var fs = require('fs'); | ||
var path = require('path'); | ||
var tako = require('tako'); | ||
var domstream = require('domstream'); | ||
|
||
module.exports = function(port, files, style) { | ||
|
||
var app = tako(); | ||
|
||
var mochaCorePath = path.resolve( path.dirname(require.resolve('mocha')), 'mocha.js'); | ||
app.route('/file/mocha.js').file(mochaCorePath); | ||
|
||
var mochaStylePath = path.resolve( path.dirname(require.resolve('mocha')), 'mocha.css'); | ||
app.route('/file/mocha.css').file(mochaStylePath); | ||
|
||
var chaiPath = path.resolve( path.dirname(require.resolve('chai')), 'chai.js'); | ||
app.route('/file/chai.js').file(chaiPath); | ||
|
||
// find the shared dirname | ||
var root = path.dirname(files[0]), i, l; | ||
for (i = 1, l = files.length; i < l; i++) { | ||
var testDir = path.dirname(files[i]); | ||
|
||
while (root !== testDir) { | ||
root = path.dirname(root); | ||
testDir = path.dirname(testDir); | ||
} | ||
} | ||
|
||
// create pathmap | ||
var map = {}; | ||
for (i = 0, l = files.length; i < l; i++) { | ||
map[ files[i].slice(root.length) ] = files[i]; | ||
} | ||
|
||
// route all static test files | ||
Object.keys(map).forEach(function (relative) { | ||
console.log('/test' + relative + ' = ' + map[relative]); | ||
app.route('/test' + relative).file(map[relative]); | ||
}); | ||
|
||
// | ||
var indexFile = generateIndex(map, style); | ||
app.route('/').html(indexFile); | ||
|
||
// route all subtest pages | ||
Object.keys(map).forEach(function (relative) { | ||
var content = generateTest(relative, style); | ||
app.route(relative).html(content); | ||
}); | ||
|
||
app.httpServer.listen(port, function () { | ||
console.log('mocha server online at http://127.0.0.1:' + port); | ||
}); | ||
}; | ||
|
||
// Standart output | ||
var base = domstream( fs.readFileSync( path.resolve(path.dirname(module.filepath), 'index.html') ) ); | ||
|
||
// generate the master testsuite | ||
function generateIndex(files, style) { | ||
var document = base.copy(); | ||
|
||
// modify title | ||
var title = document.find().only().elem('title').toValue(); | ||
title.setContent('Mocha Tests - all'); | ||
|
||
// add testcases | ||
var head = document.find().only().elem('head').toValue(); | ||
|
||
// set mocha style | ||
head.append('<script>mocha.setup("' + style + '")</script>'); | ||
|
||
// bind testcases | ||
Object.keys(files).forEach(function (relative) { | ||
head.append('<script src="/test' + relative + '"></script>'); | ||
}); | ||
|
||
// bind mocha runner | ||
head.append('<script> window.onload = function () { mocha.run() }; </script>'); | ||
|
||
return document.content; | ||
} | ||
|
||
// generate individual testcases | ||
function generateTest(file, style) { | ||
var document = base.copy(); | ||
|
||
// modify title | ||
var title = document.find().only().elem('title').toValue(); | ||
title.setContent('Mocha Tests - ' + file); | ||
|
||
// add testcases | ||
var head = document.find().only().elem('head').toValue(); | ||
|
||
// set mocha style | ||
head.append('<script>mocha.setup("' + style + '")</script>'); | ||
|
||
// bind testcases | ||
head.append('<script src="/test' + file + '"></script>'); | ||
|
||
// bind mocha runner | ||
head.append('<script> window.onload = function () { mocha.run() }; </script>'); | ||
|
||
return document.content; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8"> | ||
<title></title> | ||
|
||
<link rel="stylesheet" href="/file/mocha.css" /> | ||
<script src="/file/chai.js"></script> | ||
<script src="/file/mocha.js"></script> | ||
|
||
</head> | ||
<body> | ||
<div id="mocha"></div> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
{ | ||
"name": "blow", | ||
"description": "simple boilerplate for the testframework mocha brower", | ||
"version": "0.1.0", | ||
"author": "Andreas Madsen <amwebdk@gmail.com>", | ||
"main": "./blow.js", | ||
"repository" : { | ||
"type": "git", | ||
"url": "git://github.com/AndreasMadsen/blow.git" | ||
}, | ||
"keywords": [ | ||
"test", | ||
"testsuite", | ||
"test framework", | ||
"browser" | ||
], | ||
"devDependencies": { | ||
"mocha" : "1.3.x", | ||
"chai": "1.1.x", | ||
"domstream": "0.3.x", | ||
"tako": "0.3.x" | ||
}, | ||
"license": "MIT", | ||
"engines": { | ||
"node": "0.6 || 0.8", | ||
"npm": "1" | ||
} | ||
} |