Skip to content

Commit 41b4fdc

Browse files
znonthedevbeeme1mrtoddbaert
committed
fix: use in memory provider for e2e suites (#740)
## This PR Removes setup using Flagd Provider and uses In-Memory Provider Fixes #712 --------- Signed-off-by: Mohamed V J <[email protected]> Signed-off-by: Todd Baert <[email protected]> Co-authored-by: Michael Beemer <[email protected]> Co-authored-by: Todd Baert <[email protected]>
1 parent 7a4cb82 commit 41b4fdc

File tree

10 files changed

+154
-67
lines changed

10 files changed

+154
-67
lines changed

.github/workflows/pr-checks.yaml

-6
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,6 @@ jobs:
6565
e2e:
6666
runs-on: ubuntu-latest
6767

68-
services:
69-
flagd:
70-
image: ghcr.io/open-feature/flagd-testbed:latest
71-
ports:
72-
- 8013:8013
73-
7468
steps:
7569
- uses: actions/checkout@v4
7670
- uses: actions/setup-node@v4

CONTRIBUTING.md

+1-5
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,7 @@ Run tests with `npm test`.
3030

3131
### End-to-End Tests
3232

33-
The continuous integration runs a set of [gherkin e2e tests](https://github.com/open-feature/test-harness/blob/main/features/evaluation.feature) using [`flagd`](https://github.com/open-feature/flagd). These tests run with the "e2e" npm script. If you'd like to run them locally, you can start the flagd testbed with
34-
```
35-
docker run -p 8013:8013 ghcr.io/open-feature/flagd-testbed:latest
36-
```
37-
and then run
33+
The continuous integration runs a set of [gherkin e2e tests](https://github.com/open-feature/test-harness/blob/main/features/evaluation.feature) using in-memory provider. These tests run with the "e2e" npm script. If you'd like to run them locally, follow the steps below:
3834
```
3935
npm run e2e-server
4036
```

jest.config.ts

-2
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,6 @@ export default {
138138
preset: 'ts-jest',
139139
testMatch: ['<rootDir>/packages/server/e2e/**/*.spec.ts'],
140140
modulePathIgnorePatterns: ['.*/node-modules/'],
141-
setupFiles: ['<rootDir>/packages/server/e2e/step-definitions/setup.ts'],
142141
moduleNameMapper: {
143142
'@openfeature/core': '<rootDir>/packages/shared/src',
144143
},
@@ -149,7 +148,6 @@ export default {
149148
preset: 'ts-jest',
150149
testMatch: ['<rootDir>/packages/client/e2e/**/*.spec.ts'],
151150
modulePathIgnorePatterns: ['.*/node-modules/'],
152-
setupFiles: ['<rootDir>/packages/client/e2e/step-definitions/setup.ts'],
153151
moduleNameMapper: {
154152
'^uuid$': require.resolve('uuid'),
155153
'^(.*)\\.js$': ['$1', '$1.js'],

packages/client/e2e/step-definitions/evaluation.spec.ts

+6-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ import {
77
ResolutionDetails,
88
StandardResolutionReasons,
99
} from '@openfeature/core';
10-
import { OpenFeature, ProviderEvents } from '../..';
10+
import { OpenFeature, ProviderEvents, InMemoryProvider } from '../../src';
11+
import flagConfiguration from './flags-config';
1112
// load the feature file.
1213
const feature = loadFeature('packages/client/e2e/features/evaluation.feature');
1314

@@ -17,6 +18,7 @@ const client = OpenFeature.getClient();
1718
const givenAnOpenfeatureClientIsRegisteredWithCacheDisabled = (
1819
given: (stepMatcher: string, stepDefinitionCallback: () => void) => void
1920
) => {
21+
OpenFeature.setProvider(new InMemoryProvider(flagConfiguration));
2022
given('a provider is registered with cache disabled', () => undefined);
2123
};
2224

@@ -70,10 +72,11 @@ defineFeature(feature, (test) => {
7072

7173
givenAnOpenfeatureClientIsRegisteredWithCacheDisabled(given);
7274

75+
7376
when(
7477
/^an integer flag with key "(.*)" is evaluated with default value (\d+)$/,
75-
(key: string, defaultValue: number) => {
76-
value = client.getNumberValue(key, defaultValue);
78+
(key: string, defaultValue: string) => {
79+
value = client.getNumberValue(key, Number.parseInt(defaultValue));
7780
}
7881
);
7982

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
export default {
2+
'boolean-flag': {
3+
disabled: false,
4+
variants: {
5+
on: true,
6+
off: false,
7+
},
8+
defaultVariant: 'on',
9+
},
10+
'string-flag': {
11+
disabled: false,
12+
variants: {
13+
greeting: 'hi',
14+
parting: 'bye',
15+
},
16+
defaultVariant: 'greeting',
17+
},
18+
'integer-flag': {
19+
disabled: false,
20+
variants: {
21+
one: 1,
22+
ten: 10,
23+
},
24+
defaultVariant: 'ten',
25+
},
26+
'float-flag': {
27+
disabled: false,
28+
variants: {
29+
tenth: 0.1,
30+
half: 0.5,
31+
},
32+
defaultVariant: 'half',
33+
},
34+
'object-flag': {
35+
disabled: false,
36+
variants: {
37+
empty: {},
38+
template: {
39+
showImages: true,
40+
title: 'Check out these pics!',
41+
imagesPerPage: 100,
42+
},
43+
},
44+
defaultVariant: 'template',
45+
},
46+
'context-aware': {
47+
disabled: false,
48+
variants: {
49+
internal: 'INTERNAL',
50+
external: 'EXTERNAL',
51+
},
52+
defaultVariant: 'external',
53+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
54+
contextEvaluator(ctx: any) {
55+
const { fn, ln, age, customer } = ctx;
56+
if (fn === 'Sulisław' && ln === 'Świętopełk' && age === 29 && customer === false) {
57+
return 'internal';
58+
} else {
59+
return 'external';
60+
}
61+
},
62+
},
63+
'wrong-flag': {
64+
disabled: false,
65+
variants: {
66+
one: 'uno',
67+
two: 'dos',
68+
},
69+
defaultVariant: 'one',
70+
},
71+
};

packages/client/e2e/step-definitions/setup.ts

-19
This file was deleted.

packages/server/e2e/step-definitions/evaluation.spec.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ import {
88
StandardResolutionReasons,
99
ProviderEvents,
1010
} from '@openfeature/core';
11-
import { OpenFeature } from '../..';
11+
import { OpenFeature, InMemoryProvider } from '../../src';
12+
import flagConfiguration from './flags-config';
1213
// load the feature file.
1314
const feature = loadFeature('packages/server/e2e/features/evaluation.feature');
1415

@@ -18,7 +19,9 @@ const client = OpenFeature.getClient();
1819
const givenAnOpenfeatureClientIsRegisteredWithCacheDisabled = (
1920
given: (stepMatcher: string, stepDefinitionCallback: () => void) => void
2021
) => {
21-
// TODO: when the FlagdProvider is updated to support caching, we may need to disable it here for this test to work as expected.
22+
OpenFeature.setProvider(
23+
new InMemoryProvider(flagConfiguration),
24+
);
2225
given('a provider is registered with cache disabled', () => undefined);
2326
};
2427

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
export default {
2+
'boolean-flag': {
3+
disabled: false,
4+
variants: {
5+
on: true,
6+
off: false,
7+
},
8+
defaultVariant: 'on',
9+
},
10+
'string-flag': {
11+
disabled: false,
12+
variants: {
13+
greeting: 'hi',
14+
parting: 'bye',
15+
},
16+
defaultVariant: 'greeting',
17+
},
18+
'integer-flag': {
19+
disabled: false,
20+
variants: {
21+
one: 1,
22+
ten: 10,
23+
},
24+
defaultVariant: 'ten',
25+
},
26+
'float-flag': {
27+
disabled: false,
28+
variants: {
29+
tenth: 0.1,
30+
half: 0.5,
31+
},
32+
defaultVariant: 'half',
33+
},
34+
'object-flag': {
35+
disabled: false,
36+
variants: {
37+
empty: {},
38+
template: {
39+
showImages: true,
40+
title: 'Check out these pics!',
41+
imagesPerPage: 100,
42+
},
43+
},
44+
defaultVariant: 'template',
45+
},
46+
'context-aware': {
47+
disabled: false,
48+
variants: {
49+
internal: 'INTERNAL',
50+
external: 'EXTERNAL',
51+
},
52+
defaultVariant: 'external',
53+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
54+
contextEvaluator(ctx: any) {
55+
const { fn, ln, age, customer } = ctx;
56+
if (fn === 'Sulisław' && ln === 'Świętopełk' && age === 29 && customer === false) {
57+
return 'internal';
58+
} else {
59+
return 'external';
60+
}
61+
},
62+
},
63+
'wrong-flag': {
64+
disabled: false,
65+
variants: {
66+
one: 'uno',
67+
two: 'dos',
68+
},
69+
defaultVariant: 'one',
70+
},
71+
};

packages/server/e2e/step-definitions/jest.config.ts

-16
This file was deleted.

packages/server/e2e/step-definitions/setup.ts

-14
This file was deleted.

0 commit comments

Comments
 (0)