Skip to content
This repository has been archived by the owner on Feb 13, 2024. It is now read-only.

Don't start a timer #172

Merged
merged 3 commits into from Aug 18, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions index.js
Expand Up @@ -211,6 +211,7 @@ class Analytics {

if (this.queue.length >= this.flushAt) {
this.flush()
return
}

if (this.flushInterval && !this.timer) {
Expand Down
16 changes: 16 additions & 0 deletions test.js
Expand Up @@ -254,6 +254,22 @@ test('enqueue - don\'t reset an existing timer', async t => {
t.true(client.flush.calledOnce)
})

test('enqueue - cancel timer when flushing at max length', async t => {
nd4p90x marked this conversation as resolved.
Show resolved Hide resolved
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)
})
Copy link
Contributor

@pbassut pbassut Jul 24, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test is not clear enough.
If I understood this correctly: even though it waited 10 seconds it didn't flush a third time because it had already flushed when it reached flushAt.
Maybe the title could be enqueue - prevent flushing through time interval when already flushed by flushAt


test('enqueue - extend context', t => {
const client = createClient()

Expand Down