-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update ts-test. Add tests for lazy init
- Loading branch information
1 parent
d58d8e3
commit 9dce402
Showing
9 changed files
with
116 additions
and
18 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
import { SplitFactory as SplitFactorySS } from '../../factory/node'; | ||
import { SplitFactory as SplitFactoryCS } from '../../factory/browser'; | ||
|
||
// Tests should finish without dangling timers or requests | ||
export default function (settings, fetchMock, t) { | ||
|
||
t.test('Server-side', async (assert) => { | ||
let splitio; | ||
|
||
for (let i = 0; i < 100; i++) { | ||
splitio = SplitFactorySS({ | ||
core: { | ||
authorizationKey: 'fake-token-' + i, | ||
}, | ||
urls: { | ||
sdk: 'https://not-called/api', | ||
events: 'https://not-called/api', | ||
auth: 'https://not-called/api', | ||
} | ||
}, (modules) => { | ||
modules.lazyInit = true; | ||
}); | ||
|
||
const manager = splitio.manager(); | ||
assert.deepEqual(manager.names(), [], 'We should not have done any request yet'); | ||
|
||
const client = splitio.client(); | ||
assert.equal(client.getTreatment('user-1', 'split_test'), 'control', 'We should get control'); | ||
assert.equal(client.track('user-1', 'user', 'my_event'), true, 'We should track the event'); | ||
} | ||
|
||
fetchMock.getOnce('https://not-called/api/splitChanges?s=1.1&since=-1', { status: 200, body: { splits: [], since: -1, till: 1457552620999 } }); | ||
fetchMock.getOnce('https://not-called/api/splitChanges?s=1.1&since=1457552620999', { status: 200, body: { splits: [], since: 1457552620999, till: 1457552620999 } }); | ||
fetchMock.postOnce('https://not-called/api/testImpressions/bulk', 200); | ||
fetchMock.postOnce('https://not-called/api/events/bulk', 200); | ||
|
||
splitio.init(); | ||
await splitio.client().ready(); | ||
assert.true(splitio.client().__getStatus().isReady, 'Split SDK is ready'); | ||
await splitio.destroy(); | ||
|
||
assert.end(); | ||
}); | ||
|
||
t.test('Client-side', async (assert) => { | ||
let splitio; | ||
|
||
for (let i = 0; i < 100; i++) { | ||
splitio = SplitFactoryCS({ | ||
core: { | ||
authorizationKey: 'fake-token-' + i, | ||
key: 'user-' + i, | ||
}, | ||
urls: { | ||
sdk: 'https://not-called/api', | ||
events: 'https://not-called/api', | ||
auth: 'https://not-called/api', | ||
} | ||
}, (modules) => { | ||
modules.lazyInit = true; | ||
}); | ||
|
||
const manager = splitio.manager(); | ||
assert.deepEqual(manager.names(), [], 'We should not have done any request yet'); | ||
|
||
const client = splitio.client(); | ||
assert.equal(client.getTreatment('split_test'), 'control', 'We should get control'); | ||
assert.equal(client.track('user', 'my_event'), true, 'We should track the event'); | ||
|
||
const otherClient = splitio.client('other-user'); | ||
assert.equal(otherClient.getTreatment('split_test'), 'control', 'We should get control'); | ||
assert.equal(otherClient.track('user', 'my_event'), true, 'We should track the event'); | ||
} | ||
|
||
fetchMock.getOnce('https://not-called/api/splitChanges?s=1.2&since=-1', { status: 200, body: { splits: [], since: -1, till: 1457552620999 } }); | ||
fetchMock.getOnce('https://not-called/api/splitChanges?s=1.2&since=1457552620999', { status: 200, body: { splits: [], since: 1457552620999, till: 1457552620999 } }); | ||
fetchMock.getOnce('https://not-called/api/memberships/user-99', { status: 200, body: {} }); | ||
fetchMock.getOnce('https://not-called/api/memberships/other-user', { status: 200, body: {} }); | ||
fetchMock.postOnce('https://not-called/api/testImpressions/bulk', 200); | ||
fetchMock.postOnce('https://not-called/api/events/bulk', 200); | ||
|
||
splitio.init(); | ||
await splitio.client().ready(); | ||
assert.true(splitio.client().__getStatus().isReady, 'Split SDK is ready'); | ||
await splitio.destroy(); | ||
|
||
assert.end(); | ||
}); | ||
} |
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 |
---|---|---|
@@ -1 +1 @@ | ||
export const packageVersion = '10.28.1-rc.2'; | ||
export const packageVersion = '10.28.1-rc.4'; |
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