Skip to content

Commit

Permalink
Adds tests for multihost issue sintaxi#223
Browse files Browse the repository at this point in the history
  • Loading branch information
silentrob committed Feb 6, 2014
1 parent cb21ee0 commit b04052e
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"cheerio": "~0.13.1"
},
"scripts": {
"test": "mocha --reporter spec"
"test": "mocha --reporter spec -t 5000"
},
"license": "MIT",
"preferGlobal": true,
Expand Down
1 change: 1 addition & 0 deletions test/apps/multihost/app1.subdomain.com/index.jade
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
h1 app1.subdomain.com
Empty file.
1 change: 1 addition & 0 deletions test/apps/multihost/app1.subdomain.net/index.jade
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
h1 app1.subdomain.net
1 change: 1 addition & 0 deletions test/apps/multihost/app2.subdomain.io/index.jade
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
h1 app2.subdomain.io
37 changes: 35 additions & 2 deletions test/multihost.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ describe("multihost", function(){
var port = 8104;
var $;

var urls = [];

before(function(done){
harp.multihost(projectPath, { port: port }, function(errors){
done();
Expand All @@ -22,10 +24,41 @@ describe("multihost", function(){
request("http://localhost:" + port + "/", function(e,r,b){
r.statusCode.should.eql(200)
$ = cherio.load(b);

$(".project-name").length.should.eql(2)
urls = $(".projects A");
$(".project-name").length.should.eql(3)
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(n){
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 (n+1 == len) {

arrayUnique(titles).length.should.eql(len)
done();
}
});
})(i)
}

});


var arrayUnique = function(a) {
return a.reduce(function(p, c) {
if (p.indexOf(c) < 0) p.push(c);
return p;
}, []);
};
});

0 comments on commit b04052e

Please sign in to comment.