-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make keep_alive configurable in the Web version
- Loading branch information
Showing
3 changed files
with
64 additions
and
4 deletions.
There are no files selected for viewing
42 changes: 42 additions & 0 deletions
42
packages/client-web/__tests__/integration/web_connection.test.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,42 @@ | ||
import { createClient } from '../../src' | ||
import type { WebClickHouseClient } from '../../src/client' | ||
|
||
describe('[Web] Connection', () => { | ||
let fetchSpy: jasmine.Spy<typeof window.fetch> | ||
beforeEach(() => { | ||
fetchSpy = spyOn(window, 'fetch').and.returnValue( | ||
Promise.resolve(stubResponse()) | ||
) | ||
}) | ||
|
||
describe('KeepAlive setting', () => { | ||
it('should be enabled by default', async () => { | ||
const client = createClient() | ||
const fetchParams = await pingAndGetRequestInit(client) | ||
expect(fetchParams.keepalive).toBeTruthy() | ||
}) | ||
|
||
it('should be possible to disable it', async () => { | ||
const client = createClient({ keep_alive: { enabled: false } }) | ||
const fetchParams = await pingAndGetRequestInit(client) | ||
expect(fetchParams!.keepalive).toBeFalsy() | ||
}) | ||
|
||
it('should be enabled with an explicit setting', async () => { | ||
const client = createClient({ keep_alive: { enabled: true } }) | ||
const fetchParams = await pingAndGetRequestInit(client) | ||
expect(fetchParams.keepalive).toBeTruthy() | ||
}) | ||
|
||
async function pingAndGetRequestInit(client: WebClickHouseClient) { | ||
await client.ping() | ||
expect(fetchSpy).toHaveBeenCalledTimes(1) | ||
const [, fetchParams] = fetchSpy.calls.mostRecent().args | ||
return fetchParams! | ||
} | ||
}) | ||
|
||
function stubResponse() { | ||
return new Response() | ||
} | ||
}) |
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