multihost.js 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. var should = require("should")
  2. var request = require('request')
  3. var path = require("path")
  4. var fs = require("fs")
  5. var exec = require("child_process").exec
  6. var harp = require("../");
  7. var cherio = require("cheerio");
  8. describe("multihost", function(){
  9. var projectPath = path.join(__dirname, "apps/multihost");
  10. var port = 8104;
  11. var $;
  12. var urls = [];
  13. before(function(done){
  14. harp.multihost(projectPath, { port: port }, function(errors){
  15. done();
  16. });
  17. });
  18. it("should return list of apps", function(done){
  19. request("http://localhost:" + port + "/", function(e,r,b){
  20. r.statusCode.should.eql(200)
  21. $ = cherio.load(b);
  22. urls = $(".projects A");
  23. $(".project-name").length.should.eql(4)
  24. done();
  25. });
  26. });
  27. it("harp-apps should be served on a compatible URL", function(done) {
  28. var sites = [];
  29. for (var i = 0; i < urls.length; i++) {
  30. sites.push($(urls[i]).attr("href"));
  31. }
  32. sites.should.containEql('http://app.harp.nu:' + port);
  33. done();
  34. });
  35. // This test loads the index page, then navigates to each app, checking the heading.
  36. // Each app has its own heading, and there should be the same number as links followed.
  37. // it("apps should not overlap", function(done){
  38. // var len = urls.length;
  39. // var titles = [];
  40. // for (var i = 0; i < len; i++) {
  41. // (function(i){
  42. // var site = $(urls[i]).attr('href');
  43. // request(site, function(e,r,b) {
  44. // $ = cherio.load(b);
  45. // r.statusCode.should.eql(200);
  46. // titles.push($("h1").text());
  47. // if (i+1 == len) {
  48. // arrayUnique(titles).length.should.eql(len)
  49. // }
  50. // });
  51. // })(i)
  52. // }
  53. // done();
  54. // });
  55. var arrayUnique = function(a) {
  56. return a.reduce(function(p, c) {
  57. if (p.indexOf(c) < 0) p.push(c);
  58. return p;
  59. }, []);
  60. };
  61. });