-
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.
Added getState method to NodeJS factory instances
1 parent
d58d8e3
commit 170c81c
Showing
11 changed files
with
110 additions
and
38 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -478,6 +478,64 @@ export default function (fetchMock, assert) { | |
}); | ||
}); | ||
|
||
assert.test(t => { // Testing when we start with preloaded data and MEMORY storage type (is ready from cache immediately) | ||
const testUrls = { | ||
sdk: 'https://sdk.baseurl/readyFromCacheWithPreloadedData', | ||
events: 'https://events.baseurl/readyFromCacheWithPreloadedData' | ||
}; | ||
|
||
t.plan(5); | ||
|
||
fetchMock.getOnce(testUrls.sdk + '/splitChanges?s=1.2&since=25', { status: 200, body: { ...splitChangesMock1, since: 25 } }); | ||
fetchMock.getOnce(testUrls.sdk + '/splitChanges?s=1.2&since=1457552620999', { status: 200, body: splitChangesMock2 }); | ||
fetchMock.getOnce(testUrls.sdk + '/memberships/nicolas%40split.io', { status: 200, body: membershipsNicolas }); | ||
fetchMock.getOnce(testUrls.sdk + '/memberships/nicolas2%40split.io', { status: 200, body: { 'ms': {} } }); | ||
|
||
fetchMock.postOnce(testUrls.events + '/testImpressions/bulk', 200); | ||
fetchMock.postOnce(testUrls.events + '/testImpressions/count', 200); | ||
|
||
const splitio = SplitFactory({ | ||
...baseConfig, | ||
storage: { | ||
type: 'MEMORY', | ||
}, | ||
urls: testUrls, | ||
preloadedData: { | ||
since: 25, | ||
splitsData: [JSON.parse(alwaysOnSplitInverted)] | ||
} | ||
}); | ||
|
||
const client = splitio.client(); | ||
const client2 = splitio.client('[email protected]'); | ||
|
||
t.equal(client.__getStatus().isReadyFromCache, true, 'Client is ready from cache'); | ||
|
||
t.equal(client.getTreatment('always_on'), 'off', 'It should evaluate treatments with data from cache instead of control due to Input Validation'); | ||
t.equal(client2.getTreatment('always_on'), 'off', 'It should evaluate treatments with data from cache instead of control due to Input Validation'); | ||
|
||
client.on(client.Event.SDK_READY_TIMED_OUT, () => { | ||
t.fail('It should not timeout in this scenario.'); | ||
t.end(); | ||
}); | ||
|
||
client.on(client.Event.SDK_READY_FROM_CACHE, () => { | ||
t.fail('SDK is ready from cache immediately. SDK_READY_FROM_CACHE not emitted.'); | ||
t.end(); | ||
}); | ||
|
||
client.on(client.Event.SDK_READY, () => { | ||
t.equal(client.getTreatment('always_on'), 'on', 'It should evaluate treatments with updated data after syncing with the cloud.'); | ||
}); | ||
client2.on(client2.Event.SDK_READY, () => { | ||
t.equal(client2.getTreatment('always_on'), 'on', 'It should evaluate treatments with updated data after syncing with the cloud.'); | ||
|
||
splitio.destroy().then(() => { | ||
t.end(); | ||
}); | ||
}); | ||
}); | ||
|
||
/** Fetch specific splits **/ | ||
|
||
assert.test(t => { // Testing when we start with cached data but without storage hash (JS SDK <=v10.24.0 and Browser SDK <=v0.12.0), and a valid split filter config | ||
|
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
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.3'; |
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,43 +1,29 @@ | ||
import { isLocalStorageAvailable } from '@splitsoftware/splitio-commons/src/utils/env/isLocalStorageAvailable'; | ||
import { LOCALHOST_MODE, STORAGE_MEMORY } from '@splitsoftware/splitio-commons/src/utils/constants'; | ||
import { STORAGE_MEMORY } from '@splitsoftware/splitio-commons/src/utils/constants'; | ||
|
||
const STORAGE_LOCALSTORAGE = 'LOCALSTORAGE'; | ||
|
||
export function validateStorage(settings) { | ||
let { | ||
log, | ||
mode, | ||
storage: { | ||
type, | ||
options = {}, | ||
prefix | ||
} = { type: STORAGE_MEMORY }, | ||
} = settings; | ||
let __originalType; | ||
|
||
const fallbackToMemory = () => { | ||
__originalType = type; | ||
type = STORAGE_MEMORY; | ||
}; | ||
|
||
// In localhost mode, fallback to Memory storage and track original type to emit SDK_READY_FROM_CACHE if corresponds. | ||
// ATM, other mode settings (e.g., 'consumer') are ignored in client-side API, and so treated as standalone. | ||
if (mode === LOCALHOST_MODE && type === STORAGE_LOCALSTORAGE) { | ||
fallbackToMemory(); | ||
} | ||
|
||
// If an invalid storage type is provided OR we want to use LOCALSTORAGE and | ||
// it's not available, fallback into MEMORY | ||
if (type !== STORAGE_MEMORY && type !== STORAGE_LOCALSTORAGE || | ||
type === STORAGE_LOCALSTORAGE && !isLocalStorageAvailable()) { | ||
fallbackToMemory(); | ||
type = STORAGE_MEMORY; | ||
log.error('Invalid or unavailable storage. Fallback into MEMORY storage'); | ||
} | ||
|
||
return { | ||
type, | ||
options, | ||
prefix, | ||
__originalType | ||
}; | ||
} |
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