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: type support for Promise<void> before hook #693

Merged
merged 3 commits into from
Nov 30, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion packages/server/src/hooks/hook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ import { BaseHook, EvaluationContext, FlagValue } from '@openfeature/core';

export type Hook = BaseHook<
FlagValue,
Promise<EvaluationContext | Promise<void>> | EvaluationContext | void,
Promise<EvaluationContext | void> | EvaluationContext | void,
Promise<void> | void
>;
31 changes: 26 additions & 5 deletions packages/server/test/hooks.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,8 @@ describe('Hooks', () => {
const clientPropToOverwrite434 = 'clientPropToOverwrite';
const invocationProp434 = 'invocationProp';
const invocationPropToOverwrite434 = 'invocationPropToOverwrite';
const hookProp434 = 'hookProp';
const syncHookProp434 = 'syncHookProp';
const asyncHookProp434 = 'asyncHookProp';

OpenFeature.setContext({
[globalProp434]: true,
Expand All @@ -223,9 +224,12 @@ describe('Hooks', () => {
[invocationPropToOverwrite434]: false,
[clientPropToOverwrite434]: true,
};
const hookContext = {
const syncHookContext = {
[invocationPropToOverwrite434]: true,
[hookProp434]: true,
[syncHookProp434]: true,
};
const asyncHookContext = {
[asyncHookProp434]: true,
};

const localClient = OpenFeature.getClient('merge-test', 'test', clientContext);
Expand All @@ -234,7 +238,23 @@ describe('Hooks', () => {
hooks: [
{
before: () => {
return hookContext;
// synchronous hook that doesn't modify context
toddbaert marked this conversation as resolved.
Show resolved Hide resolved
},
},
{
before: () => {
return syncHookContext;
},
},
{
before: async () => {
// asynchronous hook that doesn't modify context
await Promise.resolve();
},
toddbaert marked this conversation as resolved.
Show resolved Hide resolved
},
{
before: async () => {
return Promise.resolve(asyncHookContext);
},
},
],
Expand All @@ -250,7 +270,8 @@ describe('Hooks', () => {
[clientPropToOverwrite434]: true,
[invocationProp434]: true,
[invocationPropToOverwrite434]: true,
[hookProp434]: true,
[syncHookProp434]: true,
[asyncHookProp434]: true,
}),
expect.anything(),
);
Expand Down
Loading