From 7c97f4217d8e548451be728ff5f47c2bce4be2d0 Mon Sep 17 00:00:00 2001 From: Yaroslav Serhieiev Date: Fri, 1 Sep 2023 12:18:38 +0300 Subject: [PATCH] feat: align hook and testFn invocation interfaces (#18) --- .../src/metadata/containers/HookInvocationMetadata.ts | 8 ++++++-- .../src/metadata/containers/TestFnInvocationMetadata.ts | 7 ++++++- packages/library/src/metadata/types/Metadata.ts | 4 ++++ 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/packages/library/src/metadata/containers/HookInvocationMetadata.ts b/packages/library/src/metadata/containers/HookInvocationMetadata.ts index 1ba0728..7ae057b 100644 --- a/packages/library/src/metadata/containers/HookInvocationMetadata.ts +++ b/packages/library/src/metadata/containers/HookInvocationMetadata.ts @@ -1,5 +1,6 @@ import type { AggregatedIdentifier } from '../ids'; +import type { InvocationMetadata } from '../types'; import { BaseMetadata } from './BaseMetadata'; import type { DescribeBlockMetadata } from './DescribeBlockMetadata'; import type { HookDefinitionMetadata } from './HookDefinitionMetadata'; @@ -9,8 +10,11 @@ import type { TestInvocationMetadata } from './TestInvocationMetadata'; type HookInvocationParentMetadata = DescribeBlockMetadata | TestInvocationMetadata; export class HookInvocationMetadata< - ParentMetadata extends HookInvocationParentMetadata = HookInvocationParentMetadata, -> extends BaseMetadata { + ParentMetadata extends HookInvocationParentMetadata = HookInvocationParentMetadata, + > + extends BaseMetadata + implements InvocationMetadata +{ constructor( context: MetadataContext, public readonly definition: HookDefinitionMetadata, diff --git a/packages/library/src/metadata/containers/TestFnInvocationMetadata.ts b/packages/library/src/metadata/containers/TestFnInvocationMetadata.ts index ddead32..326a1a5 100644 --- a/packages/library/src/metadata/containers/TestFnInvocationMetadata.ts +++ b/packages/library/src/metadata/containers/TestFnInvocationMetadata.ts @@ -1,10 +1,11 @@ import type { AggregatedIdentifier } from '../ids'; +import type { InvocationMetadata } from '../types'; import { BaseMetadata } from './BaseMetadata'; import type { MetadataContext } from './MetadataContext'; import type { TestInvocationMetadata } from './TestInvocationMetadata'; -export class TestFnInvocationMetadata extends BaseMetadata { +export class TestFnInvocationMetadata extends BaseMetadata implements InvocationMetadata { constructor( context: MetadataContext, public readonly test: TestInvocationMetadata, @@ -12,4 +13,8 @@ export class TestFnInvocationMetadata extends BaseMetadata { ) { super(context, id); } + + get definition() { + return this.test.entry; + } } diff --git a/packages/library/src/metadata/types/Metadata.ts b/packages/library/src/metadata/types/Metadata.ts index 762f257..df559b4 100644 --- a/packages/library/src/metadata/types/Metadata.ts +++ b/packages/library/src/metadata/types/Metadata.ts @@ -10,3 +10,7 @@ export interface Metadata { assign(path: undefined | string | readonly string[], value: Data): this; merge(path: undefined | string | readonly string[], value: Data): this; } + +export interface InvocationMetadata { + readonly definition: Metadata; +}