Skip to content

Commit dbba301

Browse files
committed
Move the config feature unit test logic to configuration.spec
* Removed the config.spec.ts from the e2e suite and moved the logic to configuration.spec.ts unit test * Restored env vars safely by deleting only the added keys Signed-off-by: Marko Mlakar <[email protected]>
1 parent cfc6e2f commit dbba301

File tree

3 files changed

+26
-23
lines changed

3 files changed

+26
-23
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ export const configSteps: Steps = (state: State) => {
2020
state.options = {};
2121
state.config = undefined;
2222
state.events = [];
23-
Object.keys(process.env).forEach((key) => delete process.env[key]);
23+
Object.keys(process.env)
24+
.filter((key) => !Object.prototype.hasOwnProperty.call(originalEnv, key))
25+
.forEach((key) => delete process.env[key]);
2426
Object.assign(process.env, originalEnv);
2527
});
2628

libs/providers/flagd/src/e2e/tests/config.spec.ts

Lines changed: 0 additions & 22 deletions
This file was deleted.

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)