Skip to content

Commit

Permalink
Renames batch callback to flushed and exposes it in tracker facade
Browse files Browse the repository at this point in the history
  • Loading branch information
marcospassos committed Apr 19, 2020
1 parent 1af6913 commit e0ffcc6
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ export class Container {

this.tracker.suspend();

await this.tracker.batch;
await this.tracker.flushed;
}

delete this.context;
Expand Down
4 changes: 4 additions & 0 deletions src/facade/trackerFacade.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ export default class TrackerFacade {
this.tracker = tracker;
}

public get flushed(): Promise<void> {
return this.tracker.flushed;
}

public enable(): void {
this.tracker.enable();
}
Expand Down
2 changes: 1 addition & 1 deletion src/tracker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export default class Tracker {
this.trackInactivity = this.trackInactivity.bind(this);
}

public get batch(): Promise<void> {
public get flushed(): Promise<void> {
const suppress = (): void => {
// suppress errors
};
Expand Down
15 changes: 15 additions & 0 deletions test/facade/trackerFacade.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,21 @@ describe('A tracker facade', () => {
expect(tracker.disable).toHaveBeenCalledTimes(1);
});

test('should provide a callback that is called when the current pending events are flushed', async () => {
const tracker = jest.genMockFromModule<Tracker>('../../src/tracker');
const batch = jest.fn().mockResolvedValue(undefined);

Object.defineProperty(tracker, 'flushed', {
get: batch,
});

const trackerFacade = new TrackerFacade(tracker);

await expect(trackerFacade.flushed).resolves.toBeUndefined();

expect(batch).toHaveBeenCalledTimes(1);
});

test.each<ExternalEvent[]>([
[
{
Expand Down
6 changes: 3 additions & 3 deletions test/tracker.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1071,7 +1071,7 @@ describe('A tracker', () => {
expect(channel.publish).toHaveBeenCalledTimes(1);
});

test('should provide a callback that is called when the current event batch is processed', async () => {
test('should provide a callback that is called when the current pending events are flushed', async () => {
const publish = jest.fn(event => new Promise<any>(resolve => setTimeout(() => resolve(event), 10)));

const channel: OutputChannel<Beacon> = {
Expand All @@ -1087,7 +1087,7 @@ describe('A tracker', () => {
channel: channel,
});

await expect(tracker.batch).resolves.toBeUndefined();
await expect(tracker.flushed).resolves.toBeUndefined();

const event: Event = {
type: 'nothingChanged',
Expand All @@ -1096,7 +1096,7 @@ describe('A tracker', () => {

const promise = tracker.track(event);

await expect(tracker.batch).resolves.toBeUndefined();
await expect(tracker.flushed).resolves.toBeUndefined();

expect(publish).toBeCalledWith({
timestamp: now,
Expand Down

0 comments on commit e0ffcc6

Please sign in to comment.