forked from sintaxi/harp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
multihost.js
69 lines (61 loc) · 1.89 KB
/
multihost.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
65
66
67
68
69
var should = require("should")
var request = require('request')
var path = require("path")
var fs = require("fs")
var exec = require("child_process").exec
var harp = require("../");
var cherio = require("cheerio");
describe("multihost", function(){
var projectPath = path.join(__dirname, "apps/multihost");
var port = 8104;
var $;
var urls = [];
before(function(done){
harp.multihost(projectPath, { port: port }, function(errors){
done();
});
});
it("should return list of apps", function(done){
request("http://localhost:" + port + "/", function(e,r,b){
r.statusCode.should.eql(200)
$ = cherio.load(b);
urls = $(".projects A");
$(".project-name").length.should.eql(4)
done();
});
});
it("harp-apps should be served on a compatible URL", function(done) {
var sites = [];
for (var i = 0; i < urls.length; i++) {
sites.push($(urls[i]).attr("href"));
}
sites.should.containEql('http://app.harp.nu:' + port);
done();
});
// This test loads the index page, then navigates to each app, checking the heading.
// Each app has its own heading, and there should be the same number as links followed.
// it("apps should not overlap", function(done){
// var len = urls.length;
// var titles = [];
// for (var i = 0; i < len; i++) {
// (function(i){
// var site = $(urls[i]).attr('href');
// request(site, function(e,r,b) {
// $ = cherio.load(b);
// r.statusCode.should.eql(200);
// titles.push($("h1").text());
// if (i+1 == len) {
// arrayUnique(titles).length.should.eql(len)
// }
// });
// })(i)
// }
// done();
// });
var arrayUnique = function(a) {
return a.reduce(function(p, c) {
if (p.indexOf(c) < 0) p.push(c);
return p;
}, []);
};
});