Skip to content

Commit

Permalink
Fixing cancel method and tests (#65)
Browse files Browse the repository at this point in the history
Co-authored-by: Sean Thomas Burke <[email protected]>
  • Loading branch information
seantomburke and seantomburke authored Nov 25, 2020
1 parent c832f2b commit eb03fe9
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 5 deletions.
3 changes: 2 additions & 1 deletion lib/assets/sitemapper.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/assets/sitemapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
Expand Down
15 changes: 15 additions & 0 deletions src/tests/test.es5.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down
19 changes: 17 additions & 2 deletions src/tests/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});
Expand Down Expand Up @@ -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 () {
Expand Down
16 changes: 16 additions & 0 deletions src/tests/test.ts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down

0 comments on commit eb03fe9

Please sign in to comment.