Skip to content

Commit

Permalink
fix: use in memory provider for e2e suites (#740)
Browse files Browse the repository at this point in the history
## 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]>
  • Loading branch information
3 people committed Jan 11, 2024
1 parent 7a4cb82 commit 41b4fdc
Show file tree
Hide file tree
Showing 10 changed files with 154 additions and 67 deletions.
6 changes: 0 additions & 6 deletions .github/workflows/pr-checks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,6 @@ jobs:
e2e:
runs-on: ubuntu-latest

services:
flagd:
image: ghcr.io/open-feature/flagd-testbed:latest
ports:
- 8013:8013

steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
Expand Down
6 changes: 1 addition & 5 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,7 @@ Run tests with `npm test`.

### End-to-End Tests

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
```
docker run -p 8013:8013 ghcr.io/open-feature/flagd-testbed:latest
```
and then run
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:
```
npm run e2e-server
```
Expand Down
2 changes: 0 additions & 2 deletions jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,6 @@ export default {
preset: 'ts-jest',
testMatch: ['<rootDir>/packages/server/e2e/**/*.spec.ts'],
modulePathIgnorePatterns: ['.*/node-modules/'],
setupFiles: ['<rootDir>/packages/server/e2e/step-definitions/setup.ts'],
moduleNameMapper: {
'@openfeature/core': '<rootDir>/packages/shared/src',
},
Expand All @@ -149,7 +148,6 @@ export default {
preset: 'ts-jest',
testMatch: ['<rootDir>/packages/client/e2e/**/*.spec.ts'],
modulePathIgnorePatterns: ['.*/node-modules/'],
setupFiles: ['<rootDir>/packages/client/e2e/step-definitions/setup.ts'],
moduleNameMapper: {
'^uuid$': require.resolve('uuid'),
'^(.*)\\.js$': ['$1', '$1.js'],
Expand Down
9 changes: 6 additions & 3 deletions packages/client/e2e/step-definitions/evaluation.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import {
ResolutionDetails,
StandardResolutionReasons,
} from '@openfeature/core';
import { OpenFeature, ProviderEvents } from '../..';
import { OpenFeature, ProviderEvents, InMemoryProvider } from '../../src';
import flagConfiguration from './flags-config';
// load the feature file.
const feature = loadFeature('packages/client/e2e/features/evaluation.feature');

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

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

givenAnOpenfeatureClientIsRegisteredWithCacheDisabled(given);


when(
/^an integer flag with key "(.*)" is evaluated with default value (\d+)$/,
(key: string, defaultValue: number) => {
value = client.getNumberValue(key, defaultValue);
(key: string, defaultValue: string) => {
value = client.getNumberValue(key, Number.parseInt(defaultValue));
}
);

Expand Down
71 changes: 71 additions & 0 deletions packages/client/e2e/step-definitions/flags-config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
export default {
'boolean-flag': {
disabled: false,
variants: {
on: true,
off: false,
},
defaultVariant: 'on',
},
'string-flag': {
disabled: false,
variants: {
greeting: 'hi',
parting: 'bye',
},
defaultVariant: 'greeting',
},
'integer-flag': {
disabled: false,
variants: {
one: 1,
ten: 10,
},
defaultVariant: 'ten',
},
'float-flag': {
disabled: false,
variants: {
tenth: 0.1,
half: 0.5,
},
defaultVariant: 'half',
},
'object-flag': {
disabled: false,
variants: {
empty: {},
template: {
showImages: true,
title: 'Check out these pics!',
imagesPerPage: 100,
},
},
defaultVariant: 'template',
},
'context-aware': {
disabled: false,
variants: {
internal: 'INTERNAL',
external: 'EXTERNAL',
},
defaultVariant: 'external',
// eslint-disable-next-line @typescript-eslint/no-explicit-any
contextEvaluator(ctx: any) {
const { fn, ln, age, customer } = ctx;
if (fn === 'Sulisław' && ln === 'Świętopełk' && age === 29 && customer === false) {
return 'internal';
} else {
return 'external';
}
},
},
'wrong-flag': {
disabled: false,
variants: {
one: 'uno',
two: 'dos',
},
defaultVariant: 'one',
},
};
19 changes: 0 additions & 19 deletions packages/client/e2e/step-definitions/setup.ts

This file was deleted.

7 changes: 5 additions & 2 deletions packages/server/e2e/step-definitions/evaluation.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import {
StandardResolutionReasons,
ProviderEvents,
} from '@openfeature/core';
import { OpenFeature } from '../..';
import { OpenFeature, InMemoryProvider } from '../../src';
import flagConfiguration from './flags-config';
// load the feature file.
const feature = loadFeature('packages/server/e2e/features/evaluation.feature');

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

Expand Down
71 changes: 71 additions & 0 deletions packages/server/e2e/step-definitions/flags-config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
export default {
'boolean-flag': {
disabled: false,
variants: {
on: true,
off: false,
},
defaultVariant: 'on',
},
'string-flag': {
disabled: false,
variants: {
greeting: 'hi',
parting: 'bye',
},
defaultVariant: 'greeting',
},
'integer-flag': {
disabled: false,
variants: {
one: 1,
ten: 10,
},
defaultVariant: 'ten',
},
'float-flag': {
disabled: false,
variants: {
tenth: 0.1,
half: 0.5,
},
defaultVariant: 'half',
},
'object-flag': {
disabled: false,
variants: {
empty: {},
template: {
showImages: true,
title: 'Check out these pics!',
imagesPerPage: 100,
},
},
defaultVariant: 'template',
},
'context-aware': {
disabled: false,
variants: {
internal: 'INTERNAL',
external: 'EXTERNAL',
},
defaultVariant: 'external',
// eslint-disable-next-line @typescript-eslint/no-explicit-any
contextEvaluator(ctx: any) {
const { fn, ln, age, customer } = ctx;
if (fn === 'Sulisław' && ln === 'Świętopełk' && age === 29 && customer === false) {
return 'internal';
} else {
return 'external';
}
},
},
'wrong-flag': {
disabled: false,
variants: {
one: 'uno',
two: 'dos',
},
defaultVariant: 'one',
},
};
16 changes: 0 additions & 16 deletions packages/server/e2e/step-definitions/jest.config.ts

This file was deleted.

14 changes: 0 additions & 14 deletions packages/server/e2e/step-definitions/setup.ts

This file was deleted.

0 comments on commit 41b4fdc

Please sign in to comment.