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/).
8
8
Please see [ CONTRIBUTING.md] ( ./CONTRIBUTING.md ) on how to contribute to Cucumber.
9
9
10
10
## [ Unreleased]
11
+ ### Added
12
+ - Support named BeforeAll/AfterAll hooks ([ #2661 ] ( https://github.com/cucumber/cucumber-js/pull/2661 ) )
11
13
12
14
## [ 12.2.0] - 2025-08-22
13
15
### 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
54
54
Defines a hook which is run after all scenarios have completed.
55
55
56
56
* ` options ` : An object with the following keys:
57
+ * ` name ` : An optional name for this hook
57
58
* ` timeout ` : A hook-specific timeout, to override the default timeout.
58
59
* ` fn ` : A function, defined as follows:
59
60
* 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(
195
195
hook : {
196
196
id : hook . id ,
197
197
type,
198
+ name : hook . name ,
198
199
sourceReference : makeSourceReference ( hook ) ,
199
200
} ,
200
201
} satisfies Envelope )
Original file line number Diff line number Diff line change @@ -287,7 +287,9 @@ describe('helpers', () => {
287
287
unwrappedCode : noopFunction ,
288
288
id : '1' ,
289
289
line : 7 ,
290
- options : { } ,
290
+ options : {
291
+ name : 'special cleanup thing' ,
292
+ } ,
291
293
uri : 'features/support/run-hooks.js' ,
292
294
} ) ,
293
295
new TestRunHookDefinition ( {
@@ -306,6 +308,7 @@ describe('helpers', () => {
306
308
hook : {
307
309
id : '0' ,
308
310
type : HookType . BEFORE_TEST_RUN ,
311
+ name : undefined ,
309
312
sourceReference : {
310
313
uri : 'features/support/run-hooks.js' ,
311
314
location : {
@@ -318,6 +321,7 @@ describe('helpers', () => {
318
321
hook : {
319
322
id : '1' ,
320
323
type : HookType . AFTER_TEST_RUN ,
324
+ name : 'special cleanup thing' ,
321
325
sourceReference : {
322
326
uri : 'features/support/run-hooks.js' ,
323
327
location : {
@@ -330,6 +334,7 @@ describe('helpers', () => {
330
334
hook : {
331
335
id : '2' ,
332
336
type : HookType . AFTER_TEST_RUN ,
337
+ name : undefined ,
333
338
sourceReference : {
334
339
uri : 'features/support/run-hooks.js' ,
335
340
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'
2
5
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 7
7
} from '@cucumber/cucumber-expressions'
8
8
import TestCaseHookDefinition from '../models/test_case_hook_definition'
9
9
import 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'
11
13
import StepDefinition from '../models/step_definition'
12
14
import { formatLocation } from '../formatter/helpers'
13
15
import { doesHaveValue } from '../value_checker'
@@ -355,7 +357,7 @@ export class SupportCodeLibraryBuilder {
355
357
code : wrappedCode ,
356
358
id : canonicalIds ? canonicalIds [ index ] : this . newId ( ) ,
357
359
line,
358
- options,
360
+ options : options as ITestRunHookDefinitionOptions ,
359
361
unwrappedCode : code ,
360
362
uri,
361
363
} )
Original file line number Diff line number Diff line change @@ -67,6 +67,7 @@ export interface IDefineTestStepHookOptions {
67
67
}
68
68
69
69
export interface IDefineTestRunHookOptions {
70
+ name ?: string
70
71
timeout ?: number
71
72
}
72
73
Original file line number Diff line number Diff line change @@ -50,3 +50,9 @@ Before(async function () {
50
50
After ( async function ( ) {
51
51
return 'skipped'
52
52
} )
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