File tree Expand file tree Collapse file tree 3 files changed +36
-11
lines changed Expand file tree Collapse file tree 3 files changed +36
-11
lines changed Original file line number Diff line number Diff line change 1- import { TestRunHookFinished } from '@cucumber/messages'
21import React , { FC } from 'react'
32
4- import { useQueries } from '../../hooks/useQueries .js'
3+ import { useTestRunHooks } from '../../hooks/useTestRunHooks .js'
54import { TestRunHookOutcome } from '../results/TestRunHookOutcome.js'
65import styles from './TestRunHooks.module.scss'
76
87export const TestRunHooks : FC = ( ) => {
9- const { cucumberQuery } = useQueries ( )
10- const testRunHooksFinished : ReadonlyArray < TestRunHookFinished > =
11- cucumberQuery . findAllTestRunHookFinished ( )
8+ const hooks = useTestRunHooks ( )
9+
1210 return (
1311 < ol aria-label = "RunHooks" className = { styles . hooks } >
14- { testRunHooksFinished . map ( ( testRunHookFinished ) => {
15- const testRunHook = cucumberQuery . findHookBy ( testRunHookFinished )
16-
12+ { hooks . map ( ( { testRunHookFinished, hook } ) => {
1713 return (
1814 < TestRunHookOutcome
15+ key = { hook . id }
1916 // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
20- key = { testRunHook ! . id }
21- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
22- hook = { testRunHook ! }
17+ hook = { hook ! }
2318 testRunHookFinished = { testRunHookFinished }
2419 />
2520 )
Original file line number Diff line number Diff line change 1+ export function ensure < T > ( value : T | undefined , message : string ) : T {
2+ if ( ! value ) {
3+ throw new Error ( message )
4+ }
5+ return value
6+ }
Original file line number Diff line number Diff line change 1+ import { Hook , TestRunHookFinished } from '@cucumber/messages'
2+
3+ import { ensure } from './helpers.js'
4+ import { useQueries } from './useQueries.js'
5+
6+ type RunHooksList = { testRunHookFinished : TestRunHookFinished ; hook : Hook } [ ]
7+
8+ export function useTestRunHooks ( ) : RunHooksList {
9+ const { cucumberQuery } = useQueries ( )
10+ const testRunHooksFinished : ReadonlyArray < TestRunHookFinished > =
11+ cucumberQuery . findAllTestRunHookFinished ( )
12+
13+ return testRunHooksFinished . map ( ( testRunHookFinished ) => {
14+ const hook = ensure (
15+ cucumberQuery . findHookBy ( testRunHookFinished ) ,
16+ 'Expected testRunHookFinished to resolve with a hook'
17+ )
18+
19+ return {
20+ testRunHookFinished,
21+ hook,
22+ }
23+ } )
24+ }
You can’t perform that action at this time.
0 commit comments