From eb03fe927c01743125af7dc0f9c62845cf6de9e9 Mon Sep 17 00:00:00 2001 From: Sean Thomas Burke <965298+seantomburke@users.noreply.github.com> Date: Tue, 24 Nov 2020 23:11:19 -0800 Subject: [PATCH] Fixing cancel method and tests (#65) Co-authored-by: Sean Thomas Burke --- lib/assets/sitemapper.js | 3 ++- src/assets/sitemapper.js | 4 ++-- src/tests/test.es5.js | 15 +++++++++++++++ src/tests/test.js | 19 +++++++++++++++++-- src/tests/test.ts.ts | 16 ++++++++++++++++ 5 files changed, 52 insertions(+), 5 deletions(-) diff --git a/lib/assets/sitemapper.js b/lib/assets/sitemapper.js index f8ffdde..2da62b8 100644 --- a/lib/assets/sitemapper.js +++ b/lib/assets/sitemapper.js @@ -98,7 +98,8 @@ var Sitemapper = /*#__PURE__*/function () { headers: this.requestHeaders }; return new Promise(function (resolve) { - var requester = (0, _got["default"])(url, requestOptions).then(function (response) { + var requester = (0, _got["default"])(url, requestOptions); + requester.then(function (response) { if (!response || response.statusCode !== 200) { clearTimeout(_this2.timeoutTable[url]); return resolve({ diff --git a/src/assets/sitemapper.js b/src/assets/sitemapper.js index 7406d49..d783ed7 100644 --- a/src/assets/sitemapper.js +++ b/src/assets/sitemapper.js @@ -101,8 +101,8 @@ export default class Sitemapper { }; return new Promise((resolve) => { - const requester = got(url, requestOptions) - .then((response) => { + const requester = got(url, requestOptions); + requester.then((response) => { if (!response || response.statusCode !== 200) { clearTimeout(this.timeoutTable[url]); return resolve({ error: response.error, data: response }); diff --git a/src/tests/test.es5.js b/src/tests/test.es5.js index 1fc305a..eb63e2c 100644 --- a/src/tests/test.es5.js +++ b/src/tests/test.es5.js @@ -121,6 +121,21 @@ describe('Sitemapper', function () { done(error); }); }); + + it('https://www.golinks.io/sitemap.xml sitemaps should return an empty array when timing out', function (done) { + this.timeout(30000); + const url = 'https://www.golinks.io/sitemap.xml'; + sitemapper.timeout = 1; + sitemapper.fetch(url) + .then(data => { + data.sites.should.be.Array; + done(); + }) + .catch(error => { + console.error('Test failed'); + done(error); + }); + }); }); describe('getSites method', function () { diff --git a/src/tests/test.js b/src/tests/test.js index f5c7a85..9fb4134 100644 --- a/src/tests/test.js +++ b/src/tests/test.js @@ -30,14 +30,14 @@ describe('Sitemapper', function () { sitemapper.fetch.should.be.Function; }); - it('should contruct with a url', () => { + it('should construct with a url', () => { sitemapper = new Sitemapper({ url: 'google.com', }); sitemapper.url.should.equal('google.com'); }); - it('should contruct with a timeout', () => { + it('should construct with a timeout', () => { sitemapper = new Sitemapper({ timeout: 1000, }); @@ -121,6 +121,21 @@ describe('Sitemapper', function () { done(error); }); }); + + it('https://www.golinks.io/sitemap.xml sitemaps should return an empty array when timing out', function (done) { + this.timeout(30000); + const url = 'https://www.golinks.io/sitemap.xml'; + sitemapper.timeout = 1; + sitemapper.fetch(url) + .then(data => { + data.sites.should.be.Array; + done(); + }) + .catch(error => { + console.error('Test failed'); + done(error); + }); + }); }); describe('getSites method', function () { diff --git a/src/tests/test.ts.ts b/src/tests/test.ts.ts index be2e13e..5e0eabe 100644 --- a/src/tests/test.ts.ts +++ b/src/tests/test.ts.ts @@ -123,6 +123,22 @@ describe('Sitemapper', function () { done(error); }); }); + + it('https://www.golinks.io/sitemap.xml sitemaps should return an empty array when timing out', function (done) { + this.timeout(30000); + const url = 'https://www.golinks.io/sitemap.xml'; + sitemapper.timeout = 1; + + sitemapper.fetch(url) + .then(data => { + data.sites.should.be.Array; + done(); + }) + .catch(error => { + console.error('Test failed'); + done(error); + }); + }); }); describe('getSites method', function () {