-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds bootstrap support. Doesn't make any changes we may need to manage using localStorage+boostrap, which wasn't possible with the old SDK, but is possible now.
- Loading branch information
1 parent
8cd0cdc
commit 4e5dbee
Showing
11 changed files
with
393 additions
and
10 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,149 @@ | ||
import { jest } from '@jest/globals'; | ||
|
||
import { readFlagsFromBootstrap } from '../src/bootstrap'; | ||
import { goodBootstrapData, goodBootstrapDataWithReasons } from './testBootstrapData'; | ||
|
||
it('can read valid bootstrap data', () => { | ||
const logger = { | ||
debug: jest.fn(), | ||
info: jest.fn(), | ||
warn: jest.fn(), | ||
error: jest.fn(), | ||
}; | ||
|
||
const readData = readFlagsFromBootstrap(logger, goodBootstrapData); | ||
expect(readData).toEqual({ | ||
cat: { version: 2, flag: { version: 2, variation: 1, value: false } }, | ||
json: { version: 3, flag: { version: 3, variation: 1, value: ['a', 'b', 'c', 'd'] } }, | ||
killswitch: { version: 5, flag: { version: 5, variation: 0, value: true } }, | ||
'my-boolean-flag': { version: 11, flag: { version: 11, variation: 1, value: false } }, | ||
'string-flag': { version: 3, flag: { version: 3, variation: 1, value: 'is bob' } }, | ||
}); | ||
expect(logger.debug).not.toHaveBeenCalled(); | ||
expect(logger.info).not.toHaveBeenCalled(); | ||
expect(logger.warn).not.toHaveBeenCalled(); | ||
expect(logger.error).not.toHaveBeenCalled(); | ||
}); | ||
|
||
it('can read valid bootstrap data with reasons', () => { | ||
const logger = { | ||
debug: jest.fn(), | ||
info: jest.fn(), | ||
warn: jest.fn(), | ||
error: jest.fn(), | ||
}; | ||
|
||
const readData = readFlagsFromBootstrap(logger, goodBootstrapDataWithReasons); | ||
expect(readData).toEqual({ | ||
cat: { | ||
version: 2, | ||
flag: { | ||
version: 2, | ||
variation: 1, | ||
value: false, | ||
reason: { | ||
kind: 'OFF', | ||
}, | ||
}, | ||
}, | ||
json: { | ||
version: 3, | ||
flag: { | ||
version: 3, | ||
variation: 1, | ||
value: ['a', 'b', 'c', 'd'], | ||
reason: { | ||
kind: 'OFF', | ||
}, | ||
}, | ||
}, | ||
killswitch: { | ||
version: 5, | ||
flag: { | ||
version: 5, | ||
variation: 0, | ||
value: true, | ||
reason: { | ||
kind: 'FALLTHROUGH', | ||
}, | ||
}, | ||
}, | ||
'my-boolean-flag': { | ||
version: 11, | ||
flag: { | ||
version: 11, | ||
variation: 1, | ||
value: false, | ||
reason: { | ||
kind: 'OFF', | ||
}, | ||
}, | ||
}, | ||
'string-flag': { | ||
version: 3, | ||
flag: { | ||
version: 3, | ||
variation: 1, | ||
value: 'is bob', | ||
reason: { | ||
kind: 'OFF', | ||
}, | ||
}, | ||
}, | ||
}); | ||
expect(logger.debug).not.toHaveBeenCalled(); | ||
expect(logger.info).not.toHaveBeenCalled(); | ||
expect(logger.warn).not.toHaveBeenCalled(); | ||
expect(logger.error).not.toHaveBeenCalled(); | ||
}); | ||
|
||
it('can read old bootstrap data', () => { | ||
const logger = { | ||
debug: jest.fn(), | ||
info: jest.fn(), | ||
warn: jest.fn(), | ||
error: jest.fn(), | ||
}; | ||
|
||
const oldData: any = { ...goodBootstrapData }; | ||
delete oldData.$flagsState; | ||
|
||
const readData = readFlagsFromBootstrap(logger, oldData); | ||
expect(readData).toEqual({ | ||
cat: { version: 0, flag: { version: 0, value: false } }, | ||
json: { version: 0, flag: { version: 0, value: ['a', 'b', 'c', 'd'] } }, | ||
killswitch: { version: 0, flag: { version: 0, value: true } }, | ||
'my-boolean-flag': { version: 0, flag: { version: 0, value: false } }, | ||
'string-flag': { version: 0, flag: { version: 0, value: 'is bob' } }, | ||
}); | ||
expect(logger.debug).not.toHaveBeenCalled(); | ||
expect(logger.info).not.toHaveBeenCalled(); | ||
expect(logger.warn).toHaveBeenCalledWith( | ||
'LaunchDarkly client was initialized with bootstrap data that did not' + | ||
' include flag metadata. Events may not be sent correctly.', | ||
); | ||
expect(logger.warn).toHaveBeenCalledTimes(1); | ||
expect(logger.error).not.toHaveBeenCalled(); | ||
}); | ||
|
||
it('can handle invalid bootstrap data', () => { | ||
const logger = { | ||
debug: jest.fn(), | ||
info: jest.fn(), | ||
warn: jest.fn(), | ||
error: jest.fn(), | ||
}; | ||
|
||
const invalid: any = { $valid: false, $flagsState: {} }; | ||
|
||
const readData = readFlagsFromBootstrap(logger, invalid); | ||
expect(readData).toEqual({}); | ||
expect(logger.debug).not.toHaveBeenCalled(); | ||
expect(logger.info).not.toHaveBeenCalled(); | ||
expect(logger.warn).toHaveBeenCalledWith( | ||
'LaunchDarkly bootstrap data is not available because the back end' + | ||
' could not read the flags.', | ||
); | ||
expect(logger.warn).toHaveBeenCalledTimes(1); | ||
expect(logger.error).not.toHaveBeenCalled(); | ||
}); |
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,76 @@ | ||
export const goodBootstrapData = { | ||
cat: false, | ||
json: ['a', 'b', 'c', 'd'], | ||
killswitch: true, | ||
'my-boolean-flag': false, | ||
'string-flag': 'is bob', | ||
$flagsState: { | ||
cat: { | ||
variation: 1, | ||
version: 2, | ||
}, | ||
json: { | ||
variation: 1, | ||
version: 3, | ||
}, | ||
killswitch: { | ||
variation: 0, | ||
version: 5, | ||
}, | ||
'my-boolean-flag': { | ||
variation: 1, | ||
version: 11, | ||
}, | ||
'string-flag': { | ||
variation: 1, | ||
version: 3, | ||
}, | ||
}, | ||
$valid: true, | ||
}; | ||
|
||
export const goodBootstrapDataWithReasons = { | ||
cat: false, | ||
json: ['a', 'b', 'c', 'd'], | ||
killswitch: true, | ||
'my-boolean-flag': false, | ||
'string-flag': 'is bob', | ||
$flagsState: { | ||
cat: { | ||
variation: 1, | ||
version: 2, | ||
reason: { | ||
kind: 'OFF', | ||
}, | ||
}, | ||
json: { | ||
variation: 1, | ||
version: 3, | ||
reason: { | ||
kind: 'OFF', | ||
}, | ||
}, | ||
killswitch: { | ||
variation: 0, | ||
version: 5, | ||
reason: { | ||
kind: 'FALLTHROUGH', | ||
}, | ||
}, | ||
'my-boolean-flag': { | ||
variation: 1, | ||
version: 11, | ||
reason: { | ||
kind: 'OFF', | ||
}, | ||
}, | ||
'string-flag': { | ||
variation: 1, | ||
version: 3, | ||
reason: { | ||
kind: 'OFF', | ||
}, | ||
}, | ||
}, | ||
$valid: true, | ||
}; |
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.