Last active
December 14, 2015 09:18
-
-
Save thisconnect/5063576 to your computer and use it in GitHub Desktop.
Use connect.js to server a directory but add some files at a specific URI.
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
<!DOCTYPE html> | |
<meta charset="utf-8"> | |
<meta name=viewport content="width=device-width, initial-scale=1.0"> | |
<title>Mocha Tests</title> | |
<link rel=stylesheet href="mocha.css"> | |
<div id=mocha></div> | |
<script src="mocha.js"></script> | |
<script>mocha.setup('bdd');</script> | |
<script src="expect.js"></script> | |
<script src="indexOf.js"></script> | |
<script>mocha.run();</script> |
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
if (!global.expect) expect = require('expect.js'); // ugly | |
describe('Array', function(){ | |
describe('#indexOf()', function(){ | |
it('should return -1 when the value is not present', function(){ | |
expect([1, 2, 3].indexOf(5)).to.equal(-1); | |
expect([1, 2, 3].indexOf(0)).to.equal(-1); | |
}); | |
it('should return position when the value is present', function(){ | |
expect([1, 2, 3].indexOf(3)).to.equal(2); | |
}); | |
}); | |
}); |
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
var connect = require('connect'), | |
send = require('send'); | |
connect() | |
.use(connect.static(__dirname + '/')) | |
.use('/mocha.js', function(req, res){ | |
send(req, 'mocha.js') | |
.root(__dirname + '/../node_modules/mocha/') | |
.pipe(res); | |
}) | |
.use('/mocha.css', function(req, res){ | |
send(req, 'mocha.css') | |
.root(__dirname + '/../node_modules/mocha/') | |
.pipe(res); | |
}) | |
.use('/expect.js', function(req, res){ | |
send(req, 'expect.js') | |
.root(__dirname + '/../node_modules/expect.js/') | |
.pipe(res); | |
}) | |
.use(function(req, res){ | |
var body = '<!DOCTYPE HTML><meta charset="utf-8"><h1>404</h1>'; | |
res.statusCode = 404; | |
res.setHeader('Content-Length', body.length); | |
res.end(body); | |
}) | |
.listen(8080, '127.0.0.1'); | |
console.log('browse tests @ http://127.0.0.1:8080/'); |
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
{ | |
"name": "mocha-test" | |
, "devDependencies": { | |
"mocha": ">= 1.8.1" | |
, "connect": ">= 2.7.3" | |
, "expect.js": "0.2.0" | |
, "send": ">= 0.1.0" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment