-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Todd Baert <[email protected]>
- Loading branch information
Showing
10 changed files
with
4,214 additions
and
342 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,16 @@ | ||
Feature: Flag evaluation | ||
|
||
Scenario: Resolves boolean value | ||
Given A boolean flag called boolean-flag with value true exists | ||
When Flag is evaluated with default value false | ||
Then The resolved value should match the flag value | ||
|
||
Scenario: Resolves string value | ||
Given A string flag called string-flag with value #CC0000 exists | ||
When Flag is evaluated with default value #0000CC | ||
Then The resolved value should match the flag value | ||
|
||
Scenario: Resolves number value | ||
Given A number flag called number-flag with value 1 exists | ||
When Flag is evaluated with default value 2 | ||
Then The resolved value should match the flag value |
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,68 @@ | ||
import { defineFeature, loadFeature } from 'jest-cucumber'; | ||
import { OpenFeature } from '../../src/open-feature.js'; | ||
|
||
// load the feature file. | ||
const feature = loadFeature('integration/features/evaluation.feature'); | ||
|
||
// get a client (flagd provider registered in setup) | ||
const client = OpenFeature.getClient(); | ||
|
||
defineFeature(feature, (test) => { | ||
test('Resolves boolean value', ({ given, when, then }) => { | ||
let expectedValue: boolean; | ||
let value: boolean; | ||
let flagKey: string; | ||
|
||
given(/^A boolean flag called (.*) with value (.*) exists$/, (key, value) => { | ||
flagKey = key; | ||
// convert to bool | ||
expectedValue = value === 'true'; | ||
}); | ||
|
||
when(/^Flag is evaluated with default value (.*)$/, async (defaultValue) => { | ||
value = await client.getBooleanValue(flagKey, defaultValue === 'true' ? true : false); | ||
}); | ||
|
||
then(/^The resolved value should match the flag value$/, () => { | ||
expect(value).toEqual(expectedValue); | ||
}); | ||
}); | ||
|
||
test('Resolves string value', ({ given, when, then }) => { | ||
let expectedValue: string; | ||
let value: string; | ||
let flagKey: string; | ||
|
||
given(/^A string flag called (.*) with value (.*) exists$/, (key, value) => { | ||
flagKey = key; | ||
expectedValue = value; | ||
}); | ||
|
||
when(/^Flag is evaluated with default value (.*)$/, async (defaultValue) => { | ||
value = await client.getStringValue(flagKey, defaultValue); | ||
}); | ||
|
||
then(/^The resolved value should match the flag value$/, () => { | ||
expect(value).toEqual(expectedValue); | ||
}); | ||
}); | ||
|
||
test('Resolves number value', ({ given, when, then }) => { | ||
let expectedValue: number; | ||
let value: number; | ||
let flagKey: string; | ||
|
||
given(/^A number flag called (.*) with value (.*) exists$/, (key, value) => { | ||
flagKey = key; | ||
expectedValue = Number.parseInt(value); | ||
}); | ||
|
||
when(/^Flag is evaluated with default value (.*)$/, async (defaultValue) => { | ||
value = await client.getNumberValue(flagKey, Number.parseInt(defaultValue)); | ||
}); | ||
|
||
then(/^The resolved value should match the flag value$/, () => { | ||
expect(value).toEqual(expectedValue); | ||
}); | ||
}); | ||
}); |
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,16 @@ | ||
export default { | ||
clearMocks: true, | ||
collectCoverage: true, | ||
coverageDirectory: 'coverage', | ||
coverageProvider: 'v8', | ||
globals: { | ||
'ts-jest': { | ||
tsConfig: 'integration/step-definitions/tsconfig.json', | ||
}, | ||
}, | ||
moduleNameMapper: { | ||
'^(.*)\\.js$': ['$1', '$1.js'], | ||
}, | ||
setupFiles: ['./setup.ts'], | ||
preset: 'ts-jest', | ||
}; |
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,9 @@ | ||
import { OpenFeature } from '../../src/open-feature.js'; | ||
import { FlagdRESTProvider } from '@openfeature/flagd-rest-provider'; | ||
import assert from 'assert'; | ||
|
||
// register the flagd provider before the tests. | ||
console.log('Setting flagd provider...'); | ||
OpenFeature.setProvider(new FlagdRESTProvider()); | ||
assert(OpenFeature.providerMetadata.name === 'Flagd REST', new Error('Expected flagd provider to be configured!')); | ||
console.log('flagd provider configured!'); |
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,8 @@ | ||
{ | ||
"extends": "../../tsconfig.json", | ||
"compilerOptions": { | ||
"moduleResolution": "node" | ||
}, | ||
"include": ["./**/*.ts"], | ||
"exclude": ["node_modules", "**/*.test.js"] | ||
} |
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.