-
Notifications
You must be signed in to change notification settings - Fork 141
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
262 additions
and
222 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@segment/analytics-core': patch | ||
--- | ||
|
||
Move code out of core and into analytics-node. Tweak emitter error contract. |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
const fetcher = jest.fn() | ||
jest.mock('../lib/fetch', () => ({ fetch: fetcher })) | ||
|
||
import { createError, createSuccess } from './test-helpers/factories' | ||
import { createTestAnalytics } from './test-helpers/create-test-analytics' | ||
import { Context } from '../app/analytics-node' | ||
|
||
describe('Callback behavior', () => { | ||
beforeEach(() => { | ||
fetcher.mockReturnValue(createSuccess()) | ||
}) | ||
|
||
it('should handle success', async () => { | ||
const ajs = createTestAnalytics({ maxEventsInBatch: 1 }) | ||
const ctx = await new Promise<Context>((resolve, reject) => | ||
ajs.track( | ||
{ | ||
anonymousId: 'bar', | ||
event: 'event name', | ||
}, | ||
(err, ctx) => { | ||
if (err) reject('test fail') | ||
resolve(ctx!) | ||
} | ||
) | ||
) | ||
expect(ctx.event.event).toBe('event name') | ||
expect(ctx.event.anonymousId).toBe('bar') | ||
}) | ||
|
||
it('should handle errors', async () => { | ||
fetcher.mockReturnValue(createError()) | ||
const ajs = createTestAnalytics({ maxEventsInBatch: 1 }) | ||
const [err, ctx] = await new Promise<[any, Context]>((resolve) => | ||
ajs.track( | ||
{ | ||
anonymousId: 'bar', | ||
event: 'event name', | ||
}, | ||
(err, ctx) => { | ||
resolve([err!, ctx!]) | ||
} | ||
) | ||
) | ||
expect(ctx.event.event).toBe('event name') | ||
expect(ctx.event.anonymousId).toBe('bar') | ||
expect(err).toEqual(new Error('[404] Not Found')) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.