Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use in memory provider for e2e suites #740

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.

Loading