sitemapper_mos
Version:
Parser for XML Sitemaps to be used with Robots.txt and web crawlers
2 lines • 5.41 kB
JavaScript
;require("async"),require("assert"),require("should");var _isUrl=_interopRequireDefault(require("is-url")),_sitemapper=_interopRequireDefault(require("../../lib/assets/sitemapper.js"));function _interopRequireDefault(a){return a&&a.__esModule?a:{default:a}}var sitemapper;describe("Sitemapper",function(){beforeEach(()=>{sitemapper=new _sitemapper.default({debug:!0,rejectUnauthorized:!1})}),describe("Sitemapper Class",function(){it("should have initializeTimeout method",()=>{sitemapper.initializeTimeout.should.be.Function}),it("should have crawl method",()=>{sitemapper.crawl.should.be.Function}),it("should have parse method",()=>{sitemapper.parse.should.be.Function}),it("should have fetch method",()=>{sitemapper.fetch.should.be.Function}),it("should construct with a url",()=>{sitemapper=new _sitemapper.default({url:"google.com"}),sitemapper.url.should.equal("google.com")}),it("should construct with a timeout",()=>{sitemapper=new _sitemapper.default({timeout:1e3}),sitemapper.timeout.should.equal(1e3)}),it("should set timeout",()=>{sitemapper.timeout=1e3,sitemapper.timeout.should.equal(1e3)}),it("should set url",()=>{sitemapper.url=1e3,sitemapper.url.should.equal(1e3)})}),describe("fetch Method resolves sites to array",function(){it("https://www.wegirls.it/page-sitemap.xml sitemaps should be an array",function(a){this.timeout(3e4);sitemapper.fetch("https://www.wegirls.it/page-sitemap.xml").then(b=>{b.sites.should.be.Array,b.url.should.equal("https://www.wegirls.it/page-sitemap.xml"),b.sites.length.should.be.above(2),(0,_isUrl.default)(b.sites[0]).should.be.true,a()}).catch(b=>{console.error("Test failed"),a(b)})}),it("gibberish.gibberish should fail silently with an empty array",function(a){this.timeout(3e4);sitemapper.debug=!0,sitemapper.fetch("http://gibberish.gibberish").then(b=>{b.sites.should.be.Array,b.errors.should.be.Array,b.errors.length.should.be.greaterThan(0),b.errors.length.should.be.greaterThan(0),console.log(b),a()}).catch(b=>{console.error("Test failed"),a(b)})}),it("https://www.google.com/work/sitemap.xml sitemaps should be an array",function(a){this.timeout(3e4);sitemapper.fetch("https://www.google.com/work/sitemap.xml").then(b=>{b.sites.should.be.Array,b.url.should.equal("https://www.google.com/work/sitemap.xml"),b.sites.length.should.be.above(2),(0,_isUrl.default)(b.sites[0]).should.be.true,a()}).catch(b=>{console.error("Test failed"),a(b)})}),it("https://www.golinks.io/sitemap.xml sitemaps should be an array",function(a){this.timeout(3e4);sitemapper.timeout=5e3,sitemapper.fetch("https://www.golinks.io/sitemap.xml").then(b=>{b.sites.should.be.Array,b.url.should.equal("https://www.golinks.io/sitemap.xml"),b.sites.length.should.be.above(2),(0,_isUrl.default)(b.sites[0]).should.be.true,a()}).catch(b=>{console.error("Test failed"),a(b)})}),it("https://www.golinks.io/sitemap.xml sitemaps should return an empty array when timing out",function(a){this.timeout(3e4);sitemapper.timeout=1,sitemapper.fetch("https://www.golinks.io/sitemap.xml").then(b=>{b.sites.should.be.Array,b.errors.should.be.Array,console.log(b),a()}).catch(b=>{console.error("Test failed"),a(b)})}),it("https://www.golinks.com/blog/sitemap.xml sitemaps should return an empty array when timing out",function(a){this.timeout(3e4);sitemapper.timeout=1e4,sitemapper.fetch("https://www.golinks.com/blog/sitemap.xml").then(b=>{b.sites.should.be.Array,b.errors.should.be.Array,a()}).catch(b=>{console.error("Test failed"),a(b)})}),it("https://www.banggood.com/sitemap/category.xml.gz gzip should be a non-empty array",function(a){this.timeout(3e4);sitemapper.timeout=1e4,sitemapper.fetch("https://www.banggood.com/sitemap/category.xml.gz").then(b=>{b.sites.should.be.Array,b.sites.length.should.be.greaterThan(0),a()}).catch(b=>{console.error("Test failed"),a(b)})})}),describe("gzipped sitemaps",function(){beforeEach(()=>{sitemapper=new _sitemapper.default({requestHeaders:{"Accept-Encoding":"gzip,deflate,sdch"}})}),it("https://www.banggood.com/sitemap/category.xml.gz gzip should be a non-empty array",function(a){this.timeout(3e4);sitemapper.timeout=1e4,sitemapper.fetch("https://www.banggood.com/sitemap/category.xml.gz").then(b=>{b.sites.should.be.Array,b.errors.should.be.Array,b.sites.length.should.be.greaterThan(0),a()}).catch(b=>{console.error("Test failed"),a(b)})}),it("https://foo.com/sitemap.xml should allow insecure request",function(a){this.timeout(3e4);sitemapper.timeout=1e4,sitemapper.rejectUnauthorized=!0,sitemapper.fetch("https://foo.com/sitemap.xml").then(b=>{b.sites.should.be.Array,b.errors.should.be.Array,b.errors.should.containEql({type:"RequestError",url:"https://foo.com/sitemap.xml",retries:0}),a()}).catch(b=>{console.error("Test failed"),a(b)})}),it("https://foo.com/sitemap.xml should not allow insecure request",function(a){this.timeout(3e4);sitemapper.timeout=1e4,sitemapper.rejectUnauthorized=!1,sitemapper.fetch("https://foo.com/sitemap.xml").then(b=>{b.sites.should.be.Array,b.errors.should.be.Array,b.errors.should.containEql({type:"HTTPError",url:"https://foo.com/sitemap.xml",retries:0}),a()}).catch(b=>{console.error("Test failed"),a(b)})})}),describe("getSites method",function(){it("getSites should be backwards compatible",function(a){this.timeout(3e4);sitemapper.getSites("https://wp.seantburke.com/sitemap.xml",(b,c)=>{c.should.be.Array,(0,_isUrl.default)(c[0]).should.be.true,a()})})})});
//# sourceMappingURL=test.js.map