// Runs a very simple crawl on an HTTP server
// This is more of an integration test than a unit test.

var chai = require("chai");
	chai.should();

var testserver = require("./lib/testserver.js");

describe("Test Crawl",function() {
	
	var Crawler	= require("../");
	
	// Create a new crawler to crawl this server
	var localCrawler = new Crawler("127.0.0.1","/",3000);
	
	it("should be able to be started",function(done) {
		
		localCrawler.on("crawlstart",done);
		
		localCrawler.start();
		localCrawler.running.should.be.truthy;
	});
	
	it("should have a queue with at least the initial crawl path",function() {
		
		localCrawler.queue.length.should.be.greaterThan(0);
	});
	
	it("should complete the fetch queue",function(done) {
		
		localCrawler.on("complete",function() {
			done();
		});
	});
	
	// Suddenly feeling very incompatible with the mocha philosophy.
	// Will try to make it work first, then look for another framework that
	// supports parallell tests.
	// 
	// it("should be able to discover link resources",function(done) {
	//	var linksDiscovered = 0;
	//	
	//	localCrawler.on("discoverycomplete",function() {
	//		linksDiscovered ++;
	//		
	//		if (!linksDiscovered) done();
	//	});
	// });
	// 
	// 
	// 
	// Todo: test how simple error conditions, content types, and responses
	// are handled.
	
	// Test encodings.
	
	// Test URL detection
	
	// Test handling binary data
	
	// test bad content length

});
@@ -125,17 +125,20 @@
 chai%22);%0A
-%09
+    
 chai.sho
@@ -230,17 +230,16 @@
 ion() %7B%0A
-%09
 %0A%09var Cr
@@ -262,17 +262,16 @@
 %22../%22);%0A
-%09
 %0A%09// Cre
@@ -361,24 +361,49 @@
 %22/%22,3000);%0A%09
+var linksDiscovered = 0;%0A
 %0A%09it(%22should
@@ -435,34 +435,32 @@
 unction(done) %7B%0A
-%09%09
 %0A%09%09localCrawler.
@@ -482,18 +482,16 @@
 ,done);%0A
-%09%09
 %0A%09%09local
@@ -549,25 +549,24 @@
 ruthy;%0A%09%7D);%0A
-%09
 %0A%09it(%22should
@@ -626,26 +626,24 @@
 unction() %7B%0A
-%09%09
 %0A%09%09localCraw
@@ -690,17 +690,16 @@
 );%0A%09%7D);%0A
-%09
 %0A%09it(%22sh
@@ -707,26 +707,44 @@
 uld 
-complete the fetch
+discover all linked resources in the
  que
@@ -764,18 +764,16 @@
 done) %7B%0A
-%09%09
 %0A%09%09local
@@ -788,278 +788,25 @@
 on(%22
-complete%22,function() %7B%0A%09%09%09done();%0A%09%09%7D);%0A%09%7D);%0A%09%0A%09// Suddenly feeling 
+disco
 very
- in
 comp
-atible with the mocha philosophy.%0A%09// Will try to make it work first, then look for another framework that%0A%09// supports parallell tests.%0A%09// %0A%09// it(%22should be able to discover link resources
+lete
 %22,fu
@@ -816,24 +816,15 @@
 ion(
-done
 ) %7B%0A%09
-//%09var 
+%09%09
 link
@@ -839,21 +839,20 @@
 red 
-= 0;%0A%09//%09%0A%09//
+++;%0A%09%09%7D);%0A%0A%09
 %09loc
@@ -861,33 +861,24 @@
 Crawler.on(%22
-discovery
 complete%22,fu
@@ -889,18 +889,16 @@
 on() %7B%0A%09
-//
 %09%09linksD
@@ -910,46 +910,29 @@
 ered
- ++;%0A%09//%09%09%0A%09//%09%09if (!linksDiscovered) 
+.should.equal(4);%0A%09%09%09
 done
@@ -940,49 +940,35 @@
 );%0A%09
-//
 %09%7D);%0A%09
-// 
 %7D);%0A
-%09// %0A%09// %0A%09// %0A%09// Todo: t
+%0A%0A%09// TODO%0A%0A%09// T
 est 
@@ -1024,20 +1024,16 @@
 esponses
-%0A%09//
  are han
@@ -1038,17 +1038,16 @@
 andled.%0A
-%09
 %0A%09// Tes
@@ -1059,17 +1059,16 @@
 odings.%0A
-%09
 %0A%09// Tes
@@ -1083,17 +1083,16 @@
 tection%0A
-%09
 %0A%09// Tes
@@ -1118,15 +1118,14 @@
 ata%0A
-%09
 %0A%09// 
-t
+T
 est 
@@ -1147,8 +1147,9 @@
 gth%0A%0A%7D);
+%0A

Assert that 'discoverycomplete' is fired an expected number of times