-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathindex.js
64 lines (53 loc) · 1.87 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/*jslint node:true plusplus:true vars:true nomen:true*/
(function () {
"use strict";
var testFiles = [
"0_expects.js",
"1_equality.js",
"2_functions.js",
"3_arrays.js"
// "4_objects.js",
// "5_inheritance.js",
// "6_scope.js"
];
var express = require("express");
var app = express.createServer();
var port = process.env.PORT || 3000;
var ipaddr = process.env.IP || "localhost";
app.configure(function () {
app.use(app.router);
app.use(express["static"](__dirname + "/tests"));
app.use(express["static"](__dirname + "/node_modules/mocha"));
app.use(express["static"](__dirname + "/node_modules/expect.js"));
});
app.get("/", function (req, res) {
var i, ii;
var html =
"<html>" +
" <head>" +
" <title>Week 2 Homework</title>" +
" <link href='mocha.css' rel='stylesheet'></link>" +
" <script src='expect.js'></script>" +
" <script src='mocha.js'></script>" +
" <script>mocha.setup('bdd')</script>";
for (i = 0, ii = testFiles.length; i < ii; i++) {
html = html + "<script src='" + testFiles[i] + "'></script>";
}
html = html +
" </head>" +
" <body>" +
" <div id='mocha'></div>" +
" <script type='text/javascript'>mocha.run()</script>" +
" </body>" +
"</html>";
res.end(html);
});
app.listen(port, ipaddr);
if (process.env.PORT) {
console.log("****************************");
console.log("* Tests are now accessible *");
console.log("****************************");
} else {
console.log("Now listening at address http://" + ipaddr + ":" + port + "/");
}
}());