UNPKG

3.05 kBJavaScriptView Raw
1var assert = require("assert");
2var _ = require("underscore");
3var seoaudit = require("../plugins/audit-plugin.js");
4var logger = require("../plugins/log-plugin.js");
5
6var testSite = require("./website-2/start.js").site;
7
8var crawler = require("../index.js");
9
10
11
12describe('Audit Plugin', function() {
13
14 it('Audit a mini site - all links images ', function(done) {
15 var end = function() {
16
17 //assert(audit.errors.length == 0, "Error during the crawl");
18
19 //console.log(audit.resources.get("http://localhost:9991/index.html"));
20
21 assert(audit.resources.get("http://localhost:9991/index.html").title =="This is the meta title of the page");
22 assert(audit.resources.get("http://localhost:9991/index.html").h2.length == 3);
23 assert(audit.resources.get("http://localhost:9991/index.html").contentType == "text/html; charset=UTF-8");
24
25
26 /*
27 console.log(audit.duplicateContents.keys());
28 audit.duplicateContents.keys().forEach(function(k){
29 console.log(audit.duplicateContents.get(k));
30 });
31 */
32 assert(audit.duplicateContents.get("a02ecf7dbed6115812462ff0f55c5cd03bb8f3b8").length == 2);
33
34 var outLinks = audit.outLinks.get("http://localhost:9991/markdown.html");
35 assert(outLinks.length == 28, "incorrect outlink, it should be : " + outLinks.length);
36 assert(_.filter(outLinks,function(page){ return page.isDoFollow == false}).length == 3);
37
38 assert(audit.inLinks.get("http://localhost:9991/markdown.html").length == 13);
39
40 var inLinks = audit.inLinks.get("http://localhost:9991/markdown.html");
41 assert(_.filter(inLinks,function(page){ return page.isDoFollow == false}).length == 0);
42
43 //console.log(audit.resources.get("http://localhost:9991/pdf/excelforseo.pdf"));
44
45 assert(audit.externalLinks.keys().length == 8);
46
47
48 assert(audit.inLinks.get("http://localhost:9991/css/bootstrap-theme.min.css").length == 5);
49
50 done();
51
52 };
53 var audit = new seoaudit.Plugin();
54 var log = new logger.Plugin();
55 crawler.init(null, end);
56
57 crawler.registerPlugin(audit);
58 crawler.registerPlugin(log);
59 crawler.queue({url : "http://localhost:9991/index.html"});
60
61 });
62
63
64 it('Audit a mini site - crawl only a.href links ', function(done) {
65
66 var end = function() {
67 //console.log(audit.resources.keys());
68 assert(audit.resources.keys().length == 9);
69 done();
70
71 };
72 crawler.init({images : false, links: false /*links = html link tag*/, scripts:false }, end );
73 var audit = new seoaudit.Plugin();
74 crawler.registerPlugin(audit);
75
76 crawler.queue({url : "http://localhost:9991/index.html"});
77
78 });
79
80});