Skip to content

Commit 20cc92e

Browse files
committed
fix: using both skipHours/Days and emitOnStart emits items on first request
1 parent 3f222c8 commit 20cc92e

File tree

2 files changed

+45
-18
lines changed

2 files changed

+45
-18
lines changed

lib/feedsub.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,8 @@ module.exports = class FeedReader extends EventEmitter {
209209

210210
// If skipHours or skipDays are enabled and feed provides hours/days
211211
// to skip and it's one of those hours/days, abort.
212-
if (this.options.hoursToSkip || this.options.daysToSkip) {
212+
if ((!this.first || !this.options.emitOnStart) &&
213+
(this.options.hoursToSkip || this.options.daysToSkip)) {
213214
let now = new Date();
214215
if ((this.options.hoursToSkip &&
215216
this.options.hoursToSkip.indexOf(now.getHours()) !== -1) ||

test/skip-test.js

Lines changed: 43 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,25 +8,51 @@ const path = require('path');
88
describe('Use skipHours', () => {
99
const feed = path.join(__dirname, 'assets', 'skiphours.rss');
1010
describe('With hours that match time now', () => {
11-
it('Should return no items', (done) => {
12-
muk(Date.prototype, 'getHours', () => 4);
13-
after(muk.restore);
14-
const host = 'http://www.google.com';
15-
const path = '/reader/public/atom/';
16-
const reader = new FeedSub(host + path, {
17-
emitOnStart: true, skipHours: true
11+
describe('With `emitOnStart`', () => {
12+
it('Should return some items', (done) => {
13+
muk(Date.prototype, 'getHours', () => 4);
14+
after(muk.restore);
15+
const host = 'http://www.google.com';
16+
const path = '/reader/public/atom/';
17+
const reader = new FeedSub(host + path, {
18+
emitOnStart: true, skipHours: true
19+
});
20+
21+
const scope = nock(host)
22+
.get(path)
23+
.replyWithFile(200, feed);
24+
25+
reader.read((err, items) => {
26+
assert.ifError(err);
27+
assert.ok(Array.isArray(items));
28+
assert.equal(items.length, 20);
29+
scope.done();
30+
done();
31+
});
1832
});
33+
});
1934

20-
const scope = nock(host)
21-
.get(path)
22-
.replyWithFile(200, feed);
35+
describe('Without `emitOnStart`', () => {
36+
it('Should return no items', (done) => {
37+
muk(Date.prototype, 'getHours', () => 4);
38+
after(muk.restore);
39+
const host = 'http://www.google.com';
40+
const path = '/reader/public/atom/';
41+
const reader = new FeedSub(host + path, {
42+
emitOnStart: false, skipHours: true
43+
});
2344

24-
reader.read((err, items) => {
25-
assert.ifError(err);
26-
assert.ok(Array.isArray(items));
27-
assert.equal(items.length, 0);
28-
scope.done();
29-
done();
45+
const scope = nock(host)
46+
.get(path)
47+
.replyWithFile(200, feed);
48+
49+
reader.read((err, items) => {
50+
assert.ifError(err);
51+
assert.ok(Array.isArray(items));
52+
assert.equal(items.length, 0);
53+
scope.done();
54+
done();
55+
});
3056
});
3157
});
3258
});
@@ -65,7 +91,7 @@ describe('Use skipDays', () => {
6591
const host = 'http://blog.nodejs.org';
6692
const path = '/feed/';
6793
const reader = new FeedSub(host + path, {
68-
emitOnStart: true, skipDays: true
94+
emitOnStart: false, skipDays: true
6995
});
7096

7197
const scope = nock(host)

0 commit comments

Comments
 (0)