Skip to content

Commit 1bccd11

Browse files
authored
feat: Add tests for config feature (#1407)
Signed-off-by: Marko Mlakar <[email protected]>
1 parent 17fd726 commit 1bccd11

File tree

3 files changed

+33
-0
lines changed

3 files changed

+33
-0
lines changed

libs/providers/flagd/src/e2e/constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ export const UNSTABLE_CLIENT_NAME = 'unstable';
44
export const UNAVAILABLE_CLIENT_NAME = 'unavailable';
55

66
export const GHERKIN_FLAGD = getGherkinTestPath('*.feature');
7+
export const CONFIG_FEATURE = getGherkinTestPath('config.feature');

libs/providers/flagd/src/e2e/step-definitions/configSteps.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,19 @@ export const configSteps: Steps = (state: State) => {
1313
}
1414
}
1515

16+
const originalEnv = { ...process.env };
17+
1618
return ({ given, when, then }: StepsDefinitionCallbackOptions) => {
1719
beforeEach(() => {
1820
state.options = {};
21+
state.config = undefined;
22+
state.events = [];
23+
Object.keys(process.env)
24+
.filter((key) => !Object.prototype.hasOwnProperty.call(originalEnv, key))
25+
.forEach((key) => delete process.env[key]);
26+
Object.assign(process.env, originalEnv);
1927
});
28+
2029
given(/^an option "(.*)" of type "(.*)" with value "(.*)"$/, (name: string, type: string, value: string) => {
2130
state.options[mapName(name)] = mapValueToType(value, type);
2231
});

libs/providers/flagd/src/lib/configuration.spec.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ import type { Config, FlagdProviderOptions } from './configuration';
22
import { getConfig } from './configuration';
33
import { DEFAULT_MAX_CACHE_SIZE } from './constants';
44
import type { EvaluationContext } from '@openfeature/server-sdk';
5+
import { configSteps } from '../e2e/step-definitions/configSteps';
6+
import type { State } from '../e2e/step-definitions/state';
7+
import { autoBindSteps, loadFeatures } from 'jest-cucumber';
8+
import { CONFIG_FEATURE } from '../e2e';
59

610
describe('Configuration', () => {
711
const OLD_ENV = process.env;
@@ -163,4 +167,23 @@ describe('Configuration', () => {
163167
});
164168
});
165169
});
170+
171+
describe('config.feature', () => {
172+
const state: State = {
173+
resolverType: 'in-process',
174+
options: {},
175+
config: undefined,
176+
events: [],
177+
};
178+
179+
autoBindSteps(
180+
loadFeatures(CONFIG_FEATURE, {
181+
scenarioNameTemplate: (vars) => {
182+
const tags = [...new Set([...vars.scenarioTags, ...vars.featureTags])];
183+
return `${vars.scenarioTitle}${tags.length > 0 ? ` (${tags.join(', ')})` : ''}`;
184+
},
185+
}),
186+
[configSteps(state)],
187+
);
188+
});
166189
});

0 commit comments

Comments
 (0)