-
Notifications
You must be signed in to change notification settings - Fork 136
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
12 changed files
with
186 additions
and
273 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
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
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
16 changes: 14 additions & 2 deletions
16
packages/node/src/__tests__/test-helpers/create-test-analytics.ts
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 |
---|---|---|
@@ -1,8 +1,20 @@ | ||
import { Analytics } from '../../app/analytics-node' | ||
import { AnalyticsSettings } from '../../app/settings' | ||
import { TestFetchClient, TestFetchClientOptions } from './test-fetch-client' | ||
|
||
export const createTestAnalytics = ( | ||
settings: Partial<AnalyticsSettings> = {} | ||
settings: Partial<AnalyticsSettings> = {}, | ||
{ | ||
withError, | ||
useRealHTTPClient, | ||
}: TestFetchClientOptions & { useRealHTTPClient?: boolean } = {} | ||
) => { | ||
return new Analytics({ writeKey: 'foo', flushInterval: 100, ...settings }) | ||
return new Analytics({ | ||
writeKey: 'foo', | ||
flushInterval: 100, | ||
...(useRealHTTPClient | ||
? {} | ||
: { customClient: new TestFetchClient({ withError }) }), | ||
...settings, | ||
}) | ||
} |
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
26 changes: 26 additions & 0 deletions
26
packages/node/src/__tests__/test-helpers/test-fetch-client.ts
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,26 @@ | ||
import { CustomHTTPClient } from '../../lib/customhttpclient' | ||
import { createError, createSuccess } from './factories' | ||
|
||
export type TestFetchClientOptions = { | ||
withError?: boolean | ||
/** override response (if needed) */ | ||
response?: Response | Promise<Response> | ||
} | ||
/** | ||
* Test client. | ||
* Try not to use this directly -- use createTestAnalytics instead. | ||
*/ | ||
export class TestFetchClient implements CustomHTTPClient { | ||
private withError?: TestFetchClientOptions['withError'] | ||
private response?: TestFetchClientOptions['response'] | ||
constructor({ withError, response }: TestFetchClientOptions = {}) { | ||
this.withError = withError | ||
this.response = response | ||
} | ||
send(..._args: Parameters<CustomHTTPClient['send']>) { | ||
if (this.response) { | ||
return Promise.resolve(this.response) | ||
} | ||
return Promise.resolve(this.withError ? createError() : createSuccess()) | ||
} | ||
} |
Oops, something went wrong.