File tree Expand file tree Collapse file tree 8 files changed +37
-5
lines changed
support_code_library_builder Expand file tree Collapse file tree 8 files changed +37
-5
lines changed Original file line number Diff line number Diff line change @@ -8,6 +8,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
88Please see [ CONTRIBUTING.md] ( ./CONTRIBUTING.md ) on how to contribute to Cucumber.
99
1010## [ Unreleased]
11+ ### Added
12+ - Support named BeforeAll/AfterAll hooks ([ #2661 ] ( https://github.com/cucumber/cucumber-js/pull/2661 ) )
1113
1214## [ 12.2.0] - 2025-08-22
1315### Added
Original file line number Diff line number Diff line change @@ -54,6 +54,7 @@ Multiple `After` hooks are executed in the **reverse** order that they are defin
5454Defines a hook which is run after all scenarios have completed.
5555
5656* ` options ` : An object with the following keys:
57+ * ` name ` : An optional name for this hook
5758 * ` timeout ` : A hook-specific timeout, to override the default timeout.
5859* ` fn ` : A function, defined as follows:
5960 * When using the asynchronous callback interface, have one argument for the callback function.
Original file line number Diff line number Diff line change @@ -195,6 +195,7 @@ function emitTestRunHooks(
195195 hook : {
196196 id : hook . id ,
197197 type,
198+ name : hook . name ,
198199 sourceReference : makeSourceReference ( hook ) ,
199200 } ,
200201 } satisfies Envelope )
Original file line number Diff line number Diff line change @@ -287,7 +287,9 @@ describe('helpers', () => {
287287 unwrappedCode : noopFunction ,
288288 id : '1' ,
289289 line : 7 ,
290- options : { } ,
290+ options : {
291+ name : 'special cleanup thing' ,
292+ } ,
291293 uri : 'features/support/run-hooks.js' ,
292294 } ) ,
293295 new TestRunHookDefinition ( {
@@ -306,6 +308,7 @@ describe('helpers', () => {
306308 hook : {
307309 id : '0' ,
308310 type : HookType . BEFORE_TEST_RUN ,
311+ name : undefined ,
309312 sourceReference : {
310313 uri : 'features/support/run-hooks.js' ,
311314 location : {
@@ -318,6 +321,7 @@ describe('helpers', () => {
318321 hook : {
319322 id : '1' ,
320323 type : HookType . AFTER_TEST_RUN ,
324+ name : 'special cleanup thing' ,
321325 sourceReference : {
322326 uri : 'features/support/run-hooks.js' ,
323327 location : {
@@ -330,6 +334,7 @@ describe('helpers', () => {
330334 hook : {
331335 id : '2' ,
332336 type : HookType . AFTER_TEST_RUN ,
337+ name : undefined ,
333338 sourceReference : {
334339 uri : 'features/support/run-hooks.js' ,
335340 location : {
Original file line number Diff line number Diff line change 1- import Definition from './definition'
1+ import Definition , {
2+ IDefinitionParameters ,
3+ IDefinitionOptions ,
4+ } from './definition'
25
3- export default class TestRunHookDefinition extends Definition { }
6+ export interface ITestRunHookDefinitionOptions extends IDefinitionOptions {
7+ name ?: string
8+ }
9+
10+ export default class TestRunHookDefinition extends Definition {
11+ public readonly name : string
12+
13+ constructor ( data : IDefinitionParameters < ITestRunHookDefinitionOptions > ) {
14+ super ( data )
15+ this . name = data . options . name
16+ }
17+ }
Original file line number Diff line number Diff line change 77} from '@cucumber/cucumber-expressions'
88import TestCaseHookDefinition from '../models/test_case_hook_definition'
99import TestStepHookDefinition from '../models/test_step_hook_definition'
10- import TestRunHookDefinition from '../models/test_run_hook_definition'
10+ import TestRunHookDefinition , {
11+ ITestRunHookDefinitionOptions ,
12+ } from '../models/test_run_hook_definition'
1113import StepDefinition from '../models/step_definition'
1214import { formatLocation } from '../formatter/helpers'
1315import { doesHaveValue } from '../value_checker'
@@ -355,7 +357,7 @@ export class SupportCodeLibraryBuilder {
355357 code : wrappedCode ,
356358 id : canonicalIds ? canonicalIds [ index ] : this . newId ( ) ,
357359 line,
358- options,
360+ options : options as ITestRunHookDefinitionOptions ,
359361 unwrappedCode : code ,
360362 uri,
361363 } )
Original file line number Diff line number Diff line change @@ -67,6 +67,7 @@ export interface IDefineTestStepHookOptions {
6767}
6868
6969export interface IDefineTestRunHookOptions {
70+ name ?: string
7071 timeout ?: number
7172}
7273
Original file line number Diff line number Diff line change @@ -50,3 +50,9 @@ Before(async function () {
5050After ( async function ( ) {
5151 return 'skipped'
5252} )
53+
54+ // should allow named hooks
55+ BeforeAll ( { name : 'before test run' } , function ( ) { } )
56+ AfterAll ( { name : 'after test run' } , function ( ) { } )
57+ Before ( { name : 'before test case' } , function ( ) { } )
58+ After ( { name : 'after test case' } , function ( ) { } )
You can’t perform that action at this time.
0 commit comments