diff --git a/index.js b/index.js index a55c048c..5dfe01c5 100644 --- a/index.js +++ b/index.js @@ -219,6 +219,7 @@ class Analytics { const hasReachedQueueSize = this.queue.reduce((acc, item) => acc + JSON.stringify(item).length, 0) >= this.maxQueueSize if (hasReachedFlushAt || hasReachedQueueSize) { this.flush(callback) + return } if (this.flushInterval && !this.timer) { diff --git a/test.js b/test.js index 6a13fba4..6bdd7992 100644 --- a/test.js +++ b/test.js @@ -267,6 +267,22 @@ test('enqueue - don\'t reset an existing timer', async t => { t.true(client.flush.calledOnce) }) +test('enqueue - prevent flushing through time interval when already flushed by flushAt', async t => { + const client = createClient({ flushAt: 2, flushInterval: 10 }) + client.flushed = false + spy(client, 'flush') + + client.enqueue('type', {}) + t.true(client.flush.calledOnce) + + client.enqueue('type', {}) + client.enqueue('type', {}) + t.true(client.flush.calledTwice) + + await delay(10) + t.true(client.flush.calledTwice) +}) + test('enqueue - extend context', t => { const client = createClient()