1 | var assert = require("assert");
|
2 | var _ = require("underscore");
|
3 | var seoaudit = require("../plugins/audit-plugin.js");
|
4 | var logger = require("../plugins/log-plugin.js");
|
5 |
|
6 | var testSite = require("./website-2/start.js").site;
|
7 |
|
8 | var crawler = require("../index.js");
|
9 |
|
10 |
|
11 |
|
12 | describe('Audit Plugin', function() {
|
13 |
|
14 | it('Audit a mini site - all links images ', function(done) {
|
15 | var end = function() {
|
16 |
|
17 |
|
18 |
|
19 |
|
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 |
|
28 |
|
29 |
|
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 |
|
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 |
|
68 | assert(audit.resources.keys().length == 9);
|
69 | done();
|
70 |
|
71 | };
|
72 | crawler.init({images : false, links: false , 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 | });
|