@serenity-js/core 3.42.2 → 3.43.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +23 -0
- package/esm/Serenity.d.ts +3 -1
- package/esm/Serenity.d.ts.map +1 -1
- package/esm/Serenity.js +4 -3
- package/esm/Serenity.js.map +1 -1
- package/esm/config/SerenityConfig.d.ts +1 -1
- package/esm/config/SerenityConfig.js +1 -1
- package/esm/events/SceneFinishes.d.ts +1 -1
- package/esm/events/SceneFinishes.js +1 -1
- package/esm/events/actor/ActorStageExitCompleted.d.ts +1 -1
- package/esm/events/actor/ActorStageExitCompleted.js +1 -1
- package/esm/events/actor/ActorStageExitFailed.d.ts +1 -1
- package/esm/events/actor/ActorStageExitFailed.js +1 -1
- package/esm/events/actor/ActorStageExitStarts.d.ts +1 -1
- package/esm/events/actor/ActorStageExitStarts.js +1 -1
- package/esm/screenplay/Actor.d.ts +3 -3
- package/esm/screenplay/Actor.d.ts.map +1 -1
- package/esm/screenplay/Actor.js +7 -8
- package/esm/screenplay/Actor.js.map +1 -1
- package/esm/screenplay/abilities/Ability.d.ts +6 -6
- package/esm/screenplay/abilities/Ability.js +6 -6
- package/esm/screenplay/abilities/Discardable.d.ts +5 -4
- package/esm/screenplay/abilities/Discardable.d.ts.map +1 -1
- package/esm/screenplay/abilities/Discardable.js +25 -1
- package/esm/screenplay/abilities/Discardable.js.map +1 -1
- package/esm/screenplay/abilities/Initialisable.d.ts +9 -8
- package/esm/screenplay/abilities/Initialisable.d.ts.map +1 -1
- package/esm/screenplay/abilities/Initialisable.js +22 -1
- package/esm/screenplay/abilities/Initialisable.js.map +1 -1
- package/esm/stage/ActorLifecycleManager.d.ts +191 -0
- package/esm/stage/ActorLifecycleManager.d.ts.map +1 -0
- package/esm/stage/ActorLifecycleManager.js +255 -0
- package/esm/stage/ActorLifecycleManager.js.map +1 -0
- package/esm/stage/Stage.d.ts +22 -38
- package/esm/stage/Stage.d.ts.map +1 -1
- package/esm/stage/Stage.js +61 -117
- package/esm/stage/Stage.js.map +1 -1
- package/esm/stage/StageManager.d.ts +2 -4
- package/esm/stage/StageManager.d.ts.map +1 -1
- package/esm/stage/StageManager.js +0 -5
- package/esm/stage/StageManager.js.map +1 -1
- package/esm/stage/index.d.ts +1 -0
- package/esm/stage/index.d.ts.map +1 -1
- package/esm/stage/index.js +1 -0
- package/esm/stage/index.js.map +1 -1
- package/lib/Serenity.d.ts +3 -1
- package/lib/Serenity.d.ts.map +1 -1
- package/lib/Serenity.js +4 -3
- package/lib/Serenity.js.map +1 -1
- package/lib/config/SerenityConfig.d.ts +1 -1
- package/lib/config/SerenityConfig.js +1 -1
- package/lib/events/SceneFinishes.d.ts +1 -1
- package/lib/events/SceneFinishes.js +1 -1
- package/lib/events/actor/ActorStageExitCompleted.d.ts +1 -1
- package/lib/events/actor/ActorStageExitCompleted.js +1 -1
- package/lib/events/actor/ActorStageExitFailed.d.ts +1 -1
- package/lib/events/actor/ActorStageExitFailed.js +1 -1
- package/lib/events/actor/ActorStageExitStarts.d.ts +1 -1
- package/lib/events/actor/ActorStageExitStarts.js +1 -1
- package/lib/screenplay/Actor.d.ts +3 -3
- package/lib/screenplay/Actor.d.ts.map +1 -1
- package/lib/screenplay/Actor.js +6 -7
- package/lib/screenplay/Actor.js.map +1 -1
- package/lib/screenplay/abilities/Ability.d.ts +6 -6
- package/lib/screenplay/abilities/Ability.js +6 -6
- package/lib/screenplay/abilities/Discardable.d.ts +5 -4
- package/lib/screenplay/abilities/Discardable.d.ts.map +1 -1
- package/lib/screenplay/abilities/Discardable.js +27 -0
- package/lib/screenplay/abilities/Discardable.js.map +1 -1
- package/lib/screenplay/abilities/Initialisable.d.ts +9 -8
- package/lib/screenplay/abilities/Initialisable.d.ts.map +1 -1
- package/lib/screenplay/abilities/Initialisable.js +24 -0
- package/lib/screenplay/abilities/Initialisable.js.map +1 -1
- package/lib/stage/ActorLifecycleManager.d.ts +191 -0
- package/lib/stage/ActorLifecycleManager.d.ts.map +1 -0
- package/lib/stage/ActorLifecycleManager.js +259 -0
- package/lib/stage/ActorLifecycleManager.js.map +1 -0
- package/lib/stage/Stage.d.ts +22 -38
- package/lib/stage/Stage.d.ts.map +1 -1
- package/lib/stage/Stage.js +57 -113
- package/lib/stage/Stage.js.map +1 -1
- package/lib/stage/StageManager.d.ts +2 -4
- package/lib/stage/StageManager.d.ts.map +1 -1
- package/lib/stage/StageManager.js +0 -5
- package/lib/stage/StageManager.js.map +1 -1
- package/lib/stage/index.d.ts +1 -0
- package/lib/stage/index.d.ts.map +1 -1
- package/lib/stage/index.js +1 -0
- package/lib/stage/index.js.map +1 -1
- package/package.json +3 -3
- package/src/Serenity.ts +5 -2
- package/src/config/SerenityConfig.ts +1 -1
- package/src/events/SceneFinishes.ts +1 -1
- package/src/events/actor/ActorStageExitCompleted.ts +1 -1
- package/src/events/actor/ActorStageExitFailed.ts +1 -1
- package/src/events/actor/ActorStageExitStarts.ts +1 -1
- package/src/screenplay/Actor.ts +8 -11
- package/src/screenplay/abilities/Ability.ts +6 -6
- package/src/screenplay/abilities/Discardable.ts +9 -4
- package/src/screenplay/abilities/Initialisable.ts +15 -8
- package/src/stage/ActorLifecycleManager.ts +314 -0
- package/src/stage/Stage.ts +87 -165
- package/src/stage/StageManager.ts +3 -7
- package/src/stage/index.ts +1 -0
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
import type { Clock, Duration } from '../screenplay/index.js';
|
|
2
|
+
import { Actor } from '../screenplay/index.js';
|
|
3
|
+
import type { Cast } from './Cast.js';
|
|
4
|
+
import type { Stage } from './Stage.js';
|
|
5
|
+
/**
|
|
6
|
+
* Represents the focus area where actors are tracked.
|
|
7
|
+
*
|
|
8
|
+
* - `'foreground'` - Scene-scoped actors that are dismissed when a scene finishes
|
|
9
|
+
* - `'background'` - Test run-scoped actors that persist across scenes and are dismissed when the test run finishes
|
|
10
|
+
*
|
|
11
|
+
* @group Stage
|
|
12
|
+
*/
|
|
13
|
+
export type StageFocus = 'foreground' | 'background';
|
|
14
|
+
/**
|
|
15
|
+
* Manages the lifecycle of [actors](https://serenity-js.org/api/core/class/Actor/) on the [stage](https://serenity-js.org/api/core/class/Stage/),
|
|
16
|
+
* including their creation, retrieval, and tracking of which actors are in the foreground (scene-scoped)
|
|
17
|
+
* versus background (test run-scoped).
|
|
18
|
+
*
|
|
19
|
+
* The `ActorLifecycleManager` is responsible for:
|
|
20
|
+
* - Instantiating and caching actors via the configured [cast](https://serenity-js.org/api/core/class/Cast/)
|
|
21
|
+
* - Tracking which actor is currently in the spotlight (active)
|
|
22
|
+
* - Managing the focus area (foreground vs background) where new actors are created
|
|
23
|
+
* - Providing access to actors for dismissal when scenes or test runs finish
|
|
24
|
+
*
|
|
25
|
+
* ## Default behaviour
|
|
26
|
+
*
|
|
27
|
+
* By default, actors created before the actual test scenario starts, e.g. in beforeAll hooks, are placed in the `'background'` focus area.
|
|
28
|
+
* When a [`SceneStarts`](https://serenity-js.org/api/core-events/class/SceneStarts/) event is announced,
|
|
29
|
+
* the focus switches to `'foreground'`. When a [`SceneFinishes`](https://serenity-js.org/api/core-events/class/SceneFinishes/)
|
|
30
|
+
* event is announced, foreground actors are dismissed, their abilities [discarded](https://serenity-js.org/api/core/class/Discardable/)
|
|
31
|
+
* and focus returns to `'background'`.
|
|
32
|
+
*
|
|
33
|
+
* ## Custom lifecycle management
|
|
34
|
+
*
|
|
35
|
+
* Test runner adapters like [`@serenity-js/playwright-test`](https://serenity-js.org/api/playwright-test/),
|
|
36
|
+
* where test execution and reporting happen in separate processes, can inject a custom `ActorLifecycleManager` instance
|
|
37
|
+
* to control actor lifecycle programmatically.
|
|
38
|
+
*
|
|
39
|
+
* ```typescript
|
|
40
|
+
* const actorLifecycleManager = new ActorLifecycleManager(cast, clock, interactionTimeout);
|
|
41
|
+
* const serenity = new Serenity(clock, cueTimeout, actorLifecycleManager);
|
|
42
|
+
*
|
|
43
|
+
* // At the start of each test:
|
|
44
|
+
* actorLifecycleManager.switchFocus('foreground');
|
|
45
|
+
* ```
|
|
46
|
+
*
|
|
47
|
+
* ## Learn more
|
|
48
|
+
* - [`Stage`](https://serenity-js.org/api/core/class/Stage/)
|
|
49
|
+
* - [`Cast`](https://serenity-js.org/api/core/class/Cast/)
|
|
50
|
+
* - [`Actor`](https://serenity-js.org/api/core/class/Actor/)
|
|
51
|
+
*
|
|
52
|
+
* @group Stage
|
|
53
|
+
*/
|
|
54
|
+
export declare class ActorLifecycleManager {
|
|
55
|
+
protected cast: Cast;
|
|
56
|
+
protected readonly clock: Clock;
|
|
57
|
+
protected interactionTimeout: Duration;
|
|
58
|
+
/**
|
|
59
|
+
* The most recent actor referenced via the {@apilink actor} method
|
|
60
|
+
*/
|
|
61
|
+
private currentActor?;
|
|
62
|
+
/**
|
|
63
|
+
* The scene in which the spotlight was last set.
|
|
64
|
+
* Used to detect when the spotlight shifts to a different scene context.
|
|
65
|
+
*/
|
|
66
|
+
private currentActorScene;
|
|
67
|
+
private currentFocusValue;
|
|
68
|
+
private actors;
|
|
69
|
+
protected stage: Stage;
|
|
70
|
+
constructor(cast: Cast, clock: Clock, interactionTimeout: Duration);
|
|
71
|
+
/**
|
|
72
|
+
* Configures the manager with new settings.
|
|
73
|
+
*
|
|
74
|
+
* @param options - Configuration options
|
|
75
|
+
* @param options.interactionTimeout - The maximum time to wait for an interaction to complete
|
|
76
|
+
*/
|
|
77
|
+
configure({ interactionTimeout }: {
|
|
78
|
+
interactionTimeout: Duration;
|
|
79
|
+
}): void;
|
|
80
|
+
/**
|
|
81
|
+
* Associates this manager with a [`Stage`](https://serenity-js.org/api/core/class/Stage/) instance.
|
|
82
|
+
*
|
|
83
|
+
* This method is called automatically by the `Stage` during construction.
|
|
84
|
+
* It establishes the bidirectional relationship between the manager and the stage,
|
|
85
|
+
* allowing the manager to emit [domain events](https://serenity-js.org/api/core-events/class/DomainEvent/)
|
|
86
|
+
* when actors enter the stage or are spotlighted.
|
|
87
|
+
*
|
|
88
|
+
* @param stage - The Stage instance to associate with this manager
|
|
89
|
+
*/
|
|
90
|
+
assignTo(stage: Stage): void;
|
|
91
|
+
/**
|
|
92
|
+
* Configures the manager to use the provided [cast](https://serenity-js.org/api/core/class/Cast/) for preparing actors.
|
|
93
|
+
*
|
|
94
|
+
* @param actors - The cast to use for preparing new actors
|
|
95
|
+
*
|
|
96
|
+
* @throws [`ConfigurationError`](https://serenity-js.org/api/core/class/ConfigurationError/)
|
|
97
|
+
* If the provided cast is not defined or doesn't have a `prepare` method
|
|
98
|
+
*/
|
|
99
|
+
engage(actors: Cast): void;
|
|
100
|
+
/**
|
|
101
|
+
* Returns the current [cast](https://serenity-js.org/api/core/class/Cast/) used for preparing actors.
|
|
102
|
+
*
|
|
103
|
+
* @returns The currently configured cast
|
|
104
|
+
*/
|
|
105
|
+
currentCast(): Cast;
|
|
106
|
+
/**
|
|
107
|
+
* Instantiates a new [`Actor`](https://serenity-js.org/api/core/class/Actor/) or fetches an existing one
|
|
108
|
+
* identified by their name if they've already been instantiated.
|
|
109
|
+
*
|
|
110
|
+
* When a new actor is instantiated, an [`ActorEntersStage`](https://serenity-js.org/api/core-events/class/ActorEntersStage/)
|
|
111
|
+
* event is announced. When the spotlight shifts to a different actor (or the same actor in a different scene),
|
|
112
|
+
* an [`ActorSpotlighted`](https://serenity-js.org/api/core-events/class/ActorSpotlighted/) event is announced.
|
|
113
|
+
*
|
|
114
|
+
* Actors are first looked up in the `'background'` focus area, then in `'foreground'`.
|
|
115
|
+
* New actors are always created in the current focus area.
|
|
116
|
+
*
|
|
117
|
+
* @param name - Case-sensitive name of the Actor, e.g. `Alice`
|
|
118
|
+
* @returns The actor with the given name
|
|
119
|
+
*/
|
|
120
|
+
actor(name: string): Actor;
|
|
121
|
+
private prepareActor;
|
|
122
|
+
private typeOf;
|
|
123
|
+
private existingActorCalled;
|
|
124
|
+
/**
|
|
125
|
+
* Returns `true` if there is an [`Actor`](https://serenity-js.org/api/core/class/Actor/) in the spotlight, `false` otherwise.
|
|
126
|
+
*
|
|
127
|
+
* @returns `true` if an actor is currently spotlighted
|
|
128
|
+
*/
|
|
129
|
+
hasActorInTheSpotlight(): boolean;
|
|
130
|
+
/**
|
|
131
|
+
* Returns the last [`Actor`](https://serenity-js.org/api/core/class/Actor/) instantiated
|
|
132
|
+
* via [`actor`](https://serenity-js.org/api/core/class/ActorLifecycleManager/#actor).
|
|
133
|
+
*
|
|
134
|
+
* @returns The currently spotlighted actor
|
|
135
|
+
*
|
|
136
|
+
* @throws [`LogicError`](https://serenity-js.org/api/core/class/LogicError/)
|
|
137
|
+
* If no [`Actor`](https://serenity-js.org/api/core/class/Actor/) has been activated yet
|
|
138
|
+
*/
|
|
139
|
+
actorInTheSpotlight(): Actor;
|
|
140
|
+
/**
|
|
141
|
+
* Switches the focus to the specified stage area.
|
|
142
|
+
*
|
|
143
|
+
* Actors created after this call will be added to the specified area.
|
|
144
|
+
* This method is typically called automatically by the [`Stage`](https://serenity-js.org/api/core/class/Stage/)
|
|
145
|
+
* in response to [`SceneStarts`](https://serenity-js.org/api/core-events/class/SceneStarts/) and
|
|
146
|
+
* [`SceneFinishes`](https://serenity-js.org/api/core-events/class/SceneFinishes/) events.
|
|
147
|
+
*
|
|
148
|
+
* Test runner adapters can also call this method directly to control actor lifecycle
|
|
149
|
+
* when scene events are not available (e.g., in Playwright Test where the reporter
|
|
150
|
+
* runs in a separate process).
|
|
151
|
+
*
|
|
152
|
+
* @param focus - The focus area to switch to: `'foreground'` for scene-scoped actors,
|
|
153
|
+
* `'background'` for test run-scoped actors
|
|
154
|
+
*/
|
|
155
|
+
switchFocus(focus: StageFocus): void;
|
|
156
|
+
/**
|
|
157
|
+
* Returns the current focus area.
|
|
158
|
+
*
|
|
159
|
+
* @returns The current focus: `'foreground'` or `'background'`
|
|
160
|
+
*/
|
|
161
|
+
currentFocus(): StageFocus;
|
|
162
|
+
/**
|
|
163
|
+
* Returns all actors in the specified focus area.
|
|
164
|
+
*
|
|
165
|
+
* This method is used by the [`Stage`](https://serenity-js.org/api/core/class/Stage/) to retrieve
|
|
166
|
+
* actors for dismissal when scenes or test runs finish.
|
|
167
|
+
*
|
|
168
|
+
* @param focus - The focus area to retrieve actors from
|
|
169
|
+
* @returns An array of actors in the specified focus area
|
|
170
|
+
*/
|
|
171
|
+
actorsIn(focus: StageFocus): Actor[];
|
|
172
|
+
/**
|
|
173
|
+
* Clears the spotlight if the current actor is in the specified focus area.
|
|
174
|
+
*
|
|
175
|
+
* This ensures that after actors in a focus area are dismissed, the spotlight
|
|
176
|
+
* doesn't reference a dismissed actor.
|
|
177
|
+
*
|
|
178
|
+
* @param focus - The focus area to check
|
|
179
|
+
*/
|
|
180
|
+
clearSpotlightIfIn(focus: StageFocus): void;
|
|
181
|
+
/**
|
|
182
|
+
* Clears all actors from the specified focus area.
|
|
183
|
+
*
|
|
184
|
+
* This method is called by the [`Stage`](https://serenity-js.org/api/core/class/Stage/) after
|
|
185
|
+
* actors have been dismissed to remove them from the internal tracking maps.
|
|
186
|
+
*
|
|
187
|
+
* @param focus - The focus area to clear
|
|
188
|
+
*/
|
|
189
|
+
clearActorsIn(focus: StageFocus): void;
|
|
190
|
+
}
|
|
191
|
+
//# sourceMappingURL=ActorLifecycleManager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ActorLifecycleManager.d.ts","sourceRoot":"","sources":["../../src/stage/ActorLifecycleManager.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAC9D,OAAO,EAAE,KAAK,EAAgB,MAAM,wBAAwB,CAAC;AAC7D,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAExC;;;;;;;GAOG;AACH,MAAM,MAAM,UAAU,GAAG,YAAY,GAAG,YAAY,CAAC;AAErD;;;;;;;;;;;;;;;;;;;;;;;;;;;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GAAG,IAAI;IAS3C;;;;;;;OAOG;IACH,aAAa,CAAC,KAAK,EAAE,UAAU,GAAG,IAAI;CAGzC"}
|
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
import { ensure, isDefined, property } from 'tiny-types';
|
|
2
|
+
import { ConfigurationError, LogicError, RaiseErrors } from '../errors/index.js';
|
|
3
|
+
import { ActorEntersStage, ActorSpotlighted, } from '../events/index.js';
|
|
4
|
+
import { CorrelationId } from '../model/index.js';
|
|
5
|
+
import { Actor, ScheduleWork } from '../screenplay/index.js';
|
|
6
|
+
/**
|
|
7
|
+
* Manages the lifecycle of [actors](https://serenity-js.org/api/core/class/Actor/) on the [stage](https://serenity-js.org/api/core/class/Stage/),
|
|
8
|
+
* including their creation, retrieval, and tracking of which actors are in the foreground (scene-scoped)
|
|
9
|
+
* versus background (test run-scoped).
|
|
10
|
+
*
|
|
11
|
+
* The `ActorLifecycleManager` is responsible for:
|
|
12
|
+
* - Instantiating and caching actors via the configured [cast](https://serenity-js.org/api/core/class/Cast/)
|
|
13
|
+
* - Tracking which actor is currently in the spotlight (active)
|
|
14
|
+
* - Managing the focus area (foreground vs background) where new actors are created
|
|
15
|
+
* - Providing access to actors for dismissal when scenes or test runs finish
|
|
16
|
+
*
|
|
17
|
+
* ## Default behaviour
|
|
18
|
+
*
|
|
19
|
+
* By default, actors created before the actual test scenario starts, e.g. in beforeAll hooks, are placed in the `'background'` focus area.
|
|
20
|
+
* When a [`SceneStarts`](https://serenity-js.org/api/core-events/class/SceneStarts/) event is announced,
|
|
21
|
+
* the focus switches to `'foreground'`. When a [`SceneFinishes`](https://serenity-js.org/api/core-events/class/SceneFinishes/)
|
|
22
|
+
* event is announced, foreground actors are dismissed, their abilities [discarded](https://serenity-js.org/api/core/class/Discardable/)
|
|
23
|
+
* and focus returns to `'background'`.
|
|
24
|
+
*
|
|
25
|
+
* ## Custom lifecycle management
|
|
26
|
+
*
|
|
27
|
+
* Test runner adapters like [`@serenity-js/playwright-test`](https://serenity-js.org/api/playwright-test/),
|
|
28
|
+
* where test execution and reporting happen in separate processes, can inject a custom `ActorLifecycleManager` instance
|
|
29
|
+
* to control actor lifecycle programmatically.
|
|
30
|
+
*
|
|
31
|
+
* ```typescript
|
|
32
|
+
* const actorLifecycleManager = new ActorLifecycleManager(cast, clock, interactionTimeout);
|
|
33
|
+
* const serenity = new Serenity(clock, cueTimeout, actorLifecycleManager);
|
|
34
|
+
*
|
|
35
|
+
* // At the start of each test:
|
|
36
|
+
* actorLifecycleManager.switchFocus('foreground');
|
|
37
|
+
* ```
|
|
38
|
+
*
|
|
39
|
+
* ## Learn more
|
|
40
|
+
* - [`Stage`](https://serenity-js.org/api/core/class/Stage/)
|
|
41
|
+
* - [`Cast`](https://serenity-js.org/api/core/class/Cast/)
|
|
42
|
+
* - [`Actor`](https://serenity-js.org/api/core/class/Actor/)
|
|
43
|
+
*
|
|
44
|
+
* @group Stage
|
|
45
|
+
*/
|
|
46
|
+
export class ActorLifecycleManager {
|
|
47
|
+
cast;
|
|
48
|
+
clock;
|
|
49
|
+
interactionTimeout;
|
|
50
|
+
/**
|
|
51
|
+
* The most recent actor referenced via the {@apilink actor} method
|
|
52
|
+
*/
|
|
53
|
+
currentActor;
|
|
54
|
+
/**
|
|
55
|
+
* The scene in which the spotlight was last set.
|
|
56
|
+
* Used to detect when the spotlight shifts to a different scene context.
|
|
57
|
+
*/
|
|
58
|
+
currentActorScene = new CorrelationId('unknown');
|
|
59
|
+
currentFocusValue = 'background';
|
|
60
|
+
actors = {
|
|
61
|
+
'foreground': new Map(),
|
|
62
|
+
'background': new Map(),
|
|
63
|
+
};
|
|
64
|
+
stage;
|
|
65
|
+
constructor(cast, clock, interactionTimeout) {
|
|
66
|
+
this.cast = cast;
|
|
67
|
+
this.clock = clock;
|
|
68
|
+
this.interactionTimeout = interactionTimeout;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Configures the manager with new settings.
|
|
72
|
+
*
|
|
73
|
+
* @param options - Configuration options
|
|
74
|
+
* @param options.interactionTimeout - The maximum time to wait for an interaction to complete
|
|
75
|
+
*/
|
|
76
|
+
configure({ interactionTimeout }) {
|
|
77
|
+
this.interactionTimeout = interactionTimeout;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Associates this manager with a [`Stage`](https://serenity-js.org/api/core/class/Stage/) instance.
|
|
81
|
+
*
|
|
82
|
+
* This method is called automatically by the `Stage` during construction.
|
|
83
|
+
* It establishes the bidirectional relationship between the manager and the stage,
|
|
84
|
+
* allowing the manager to emit [domain events](https://serenity-js.org/api/core-events/class/DomainEvent/)
|
|
85
|
+
* when actors enter the stage or are spotlighted.
|
|
86
|
+
*
|
|
87
|
+
* @param stage - The Stage instance to associate with this manager
|
|
88
|
+
*/
|
|
89
|
+
assignTo(stage) {
|
|
90
|
+
this.stage = stage;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Configures the manager to use the provided [cast](https://serenity-js.org/api/core/class/Cast/) for preparing actors.
|
|
94
|
+
*
|
|
95
|
+
* @param actors - The cast to use for preparing new actors
|
|
96
|
+
*
|
|
97
|
+
* @throws [`ConfigurationError`](https://serenity-js.org/api/core/class/ConfigurationError/)
|
|
98
|
+
* If the provided cast is not defined or doesn't have a `prepare` method
|
|
99
|
+
*/
|
|
100
|
+
engage(actors) {
|
|
101
|
+
this.cast = ensure('actors', actors, isDefined(), property('prepare', isDefined()));
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Returns the current [cast](https://serenity-js.org/api/core/class/Cast/) used for preparing actors.
|
|
105
|
+
*
|
|
106
|
+
* @returns The currently configured cast
|
|
107
|
+
*/
|
|
108
|
+
currentCast() {
|
|
109
|
+
return this.cast;
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Instantiates a new [`Actor`](https://serenity-js.org/api/core/class/Actor/) or fetches an existing one
|
|
113
|
+
* identified by their name if they've already been instantiated.
|
|
114
|
+
*
|
|
115
|
+
* When a new actor is instantiated, an [`ActorEntersStage`](https://serenity-js.org/api/core-events/class/ActorEntersStage/)
|
|
116
|
+
* event is announced. When the spotlight shifts to a different actor (or the same actor in a different scene),
|
|
117
|
+
* an [`ActorSpotlighted`](https://serenity-js.org/api/core-events/class/ActorSpotlighted/) event is announced.
|
|
118
|
+
*
|
|
119
|
+
* Actors are first looked up in the `'background'` focus area, then in `'foreground'`.
|
|
120
|
+
* New actors are always created in the current focus area.
|
|
121
|
+
*
|
|
122
|
+
* @param name - Case-sensitive name of the Actor, e.g. `Alice`
|
|
123
|
+
* @returns The actor with the given name
|
|
124
|
+
*/
|
|
125
|
+
actor(name) {
|
|
126
|
+
if (!this.existingActorCalled(name)) {
|
|
127
|
+
const actor = this.prepareActor(new Actor(name, this.stage, [
|
|
128
|
+
new RaiseErrors(this.stage),
|
|
129
|
+
new ScheduleWork(this.clock, this.interactionTimeout)
|
|
130
|
+
]));
|
|
131
|
+
this.actors[this.currentFocusValue].set(actor.name, actor);
|
|
132
|
+
this.stage.announce(new ActorEntersStage(this.stage.currentSceneId(), actor.toJSON(), this.stage.currentTime()));
|
|
133
|
+
}
|
|
134
|
+
const previousActorInSpotlight = this.currentActor;
|
|
135
|
+
const previousSceneOfSpotlightedActor = this.currentActorScene;
|
|
136
|
+
this.currentActor = this.existingActorCalled(name);
|
|
137
|
+
this.currentActorScene = this.stage.currentSceneId();
|
|
138
|
+
const spotlightShifted = this.currentActor !== previousActorInSpotlight
|
|
139
|
+
|| !this.stage.currentSceneId().equals(previousSceneOfSpotlightedActor);
|
|
140
|
+
if (spotlightShifted) {
|
|
141
|
+
this.stage.announce(new ActorSpotlighted(this.stage.currentSceneId(), this.currentActor.toJSON(), this.stage.currentTime()));
|
|
142
|
+
}
|
|
143
|
+
return this.currentActor;
|
|
144
|
+
}
|
|
145
|
+
prepareActor(actor) {
|
|
146
|
+
let preparedActor;
|
|
147
|
+
try {
|
|
148
|
+
preparedActor = this.cast.prepare(actor);
|
|
149
|
+
}
|
|
150
|
+
catch (error) {
|
|
151
|
+
throw new ConfigurationError(`${this.typeOf(this.cast)} encountered a problem when preparing actor "${actor.name}" for stage`, error);
|
|
152
|
+
}
|
|
153
|
+
if (!(preparedActor instanceof Actor)) {
|
|
154
|
+
throw new ConfigurationError(`Instead of a new instance of actor "${actor.name}", ${this.typeOf(this.cast)} returned ${preparedActor}`);
|
|
155
|
+
}
|
|
156
|
+
return preparedActor;
|
|
157
|
+
}
|
|
158
|
+
typeOf(cast) {
|
|
159
|
+
return cast.constructor === Object
|
|
160
|
+
? 'Cast'
|
|
161
|
+
: cast.constructor.name;
|
|
162
|
+
}
|
|
163
|
+
existingActorCalled(name) {
|
|
164
|
+
return this.actors['background'].has(name)
|
|
165
|
+
? this.actors['background'].get(name)
|
|
166
|
+
: this.actors['foreground'].get(name);
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Returns `true` if there is an [`Actor`](https://serenity-js.org/api/core/class/Actor/) in the spotlight, `false` otherwise.
|
|
170
|
+
*
|
|
171
|
+
* @returns `true` if an actor is currently spotlighted
|
|
172
|
+
*/
|
|
173
|
+
hasActorInTheSpotlight() {
|
|
174
|
+
return Boolean(this.currentActor);
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* Returns the last [`Actor`](https://serenity-js.org/api/core/class/Actor/) instantiated
|
|
178
|
+
* via [`actor`](https://serenity-js.org/api/core/class/ActorLifecycleManager/#actor).
|
|
179
|
+
*
|
|
180
|
+
* @returns The currently spotlighted actor
|
|
181
|
+
*
|
|
182
|
+
* @throws [`LogicError`](https://serenity-js.org/api/core/class/LogicError/)
|
|
183
|
+
* If no [`Actor`](https://serenity-js.org/api/core/class/Actor/) has been activated yet
|
|
184
|
+
*/
|
|
185
|
+
actorInTheSpotlight() {
|
|
186
|
+
if (!this.currentActor) {
|
|
187
|
+
throw new LogicError(`There is no actor in the spotlight yet. Make sure you instantiate one with stage.actor(actorName) before calling this method.`);
|
|
188
|
+
}
|
|
189
|
+
return this.currentActor;
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Switches the focus to the specified stage area.
|
|
193
|
+
*
|
|
194
|
+
* Actors created after this call will be added to the specified area.
|
|
195
|
+
* This method is typically called automatically by the [`Stage`](https://serenity-js.org/api/core/class/Stage/)
|
|
196
|
+
* in response to [`SceneStarts`](https://serenity-js.org/api/core-events/class/SceneStarts/) and
|
|
197
|
+
* [`SceneFinishes`](https://serenity-js.org/api/core-events/class/SceneFinishes/) events.
|
|
198
|
+
*
|
|
199
|
+
* Test runner adapters can also call this method directly to control actor lifecycle
|
|
200
|
+
* when scene events are not available (e.g., in Playwright Test where the reporter
|
|
201
|
+
* runs in a separate process).
|
|
202
|
+
*
|
|
203
|
+
* @param focus - The focus area to switch to: `'foreground'` for scene-scoped actors,
|
|
204
|
+
* `'background'` for test run-scoped actors
|
|
205
|
+
*/
|
|
206
|
+
switchFocus(focus) {
|
|
207
|
+
this.currentFocusValue = focus;
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* Returns the current focus area.
|
|
211
|
+
*
|
|
212
|
+
* @returns The current focus: `'foreground'` or `'background'`
|
|
213
|
+
*/
|
|
214
|
+
currentFocus() {
|
|
215
|
+
return this.currentFocusValue;
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* Returns all actors in the specified focus area.
|
|
219
|
+
*
|
|
220
|
+
* This method is used by the [`Stage`](https://serenity-js.org/api/core/class/Stage/) to retrieve
|
|
221
|
+
* actors for dismissal when scenes or test runs finish.
|
|
222
|
+
*
|
|
223
|
+
* @param focus - The focus area to retrieve actors from
|
|
224
|
+
* @returns An array of actors in the specified focus area
|
|
225
|
+
*/
|
|
226
|
+
actorsIn(focus) {
|
|
227
|
+
return Array.from(this.actors[focus].values());
|
|
228
|
+
}
|
|
229
|
+
/**
|
|
230
|
+
* Clears the spotlight if the current actor is in the specified focus area.
|
|
231
|
+
*
|
|
232
|
+
* This ensures that after actors in a focus area are dismissed, the spotlight
|
|
233
|
+
* doesn't reference a dismissed actor.
|
|
234
|
+
*
|
|
235
|
+
* @param focus - The focus area to check
|
|
236
|
+
*/
|
|
237
|
+
clearSpotlightIfIn(focus) {
|
|
238
|
+
const actors = this.actorsIn(focus);
|
|
239
|
+
if (actors.includes(this.currentActor)) {
|
|
240
|
+
this.currentActor = undefined;
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
244
|
+
* Clears all actors from the specified focus area.
|
|
245
|
+
*
|
|
246
|
+
* This method is called by the [`Stage`](https://serenity-js.org/api/core/class/Stage/) after
|
|
247
|
+
* actors have been dismissed to remove them from the internal tracking maps.
|
|
248
|
+
*
|
|
249
|
+
* @param focus - The focus area to clear
|
|
250
|
+
*/
|
|
251
|
+
clearActorsIn(focus) {
|
|
252
|
+
this.actors[focus].clear();
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
//# sourceMappingURL=ActorLifecycleManager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ActorLifecycleManager.js","sourceRoot":"","sources":["../../src/stage/ActorLifecycleManager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAEzD,OAAO,EAAE,kBAAkB,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjF,OAAO,EAAE,gBAAgB,EAAE,gBAAgB,GAAG,MAAM,oBAAoB,CAAC;AACzE,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAElD,OAAO,EAAE,KAAK,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAc7D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AACH,MAAM,OAAO,qBAAqB;IAuBhB;IACS;IACT;IAvBd;;OAEG;IACK,YAAY,CAAS;IAE7B;;;OAGG;IACK,iBAAiB,GAAkB,IAAI,aAAa,CAAC,SAAS,CAAC,CAAC;IAEhE,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QAAQ,CAAC,KAAiB;QACtB,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC;IACnD,CAAC;IAED;;;;;;;OAOG;IACH,kBAAkB,CAAC,KAAiB;QAEhC,MAAM,MAAM,GAAG,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;QAEpC,IAAI,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,YAAY,CAAC,EAAE,CAAC;YACrC,IAAI,CAAC,YAAY,GAAG,SAAS,CAAC;QAClC,CAAC;IACL,CAAC;IAED;;;;;;;OAOG;IACH,aAAa,CAAC,KAAiB;QAC3B,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,CAAC;IAC/B,CAAC;CACJ"}
|
package/esm/stage/Stage.d.ts
CHANGED
|
@@ -2,9 +2,11 @@ import type { SerenityConfig } from '../config/index.js';
|
|
|
2
2
|
import { ErrorFactory, type ErrorOptions, type RuntimeError } from '../errors/index.js';
|
|
3
3
|
import { type DomainEvent, type EmitsDomainEvents } from '../events/index.js';
|
|
4
4
|
import { type ActivityDetails, CorrelationId, type CorrelationIdFactory } from '../model/index.js';
|
|
5
|
-
import { Actor
|
|
6
|
-
import type {
|
|
5
|
+
import type { Actor } from '../screenplay/index.js';
|
|
6
|
+
import type { Clock, Duration, Timestamp } from '../screenplay/index.js';
|
|
7
|
+
import { ActorLifecycleManager } from './ActorLifecycleManager.js';
|
|
7
8
|
import type { Cast } from './Cast.js';
|
|
9
|
+
import type { ListensToDomainEvents } from './ListensToDomainEvents.js';
|
|
8
10
|
import type { StageManager } from './StageManager.js';
|
|
9
11
|
/**
|
|
10
12
|
* Stage is the place where [actors](https://serenity-js.org/api/core/class/Actor/) perform.
|
|
@@ -23,44 +25,28 @@ import type { StageManager } from './StageManager.js';
|
|
|
23
25
|
* @group Stage
|
|
24
26
|
*/
|
|
25
27
|
export declare class Stage implements EmitsDomainEvents {
|
|
26
|
-
private
|
|
27
|
-
private manager;
|
|
28
|
+
private readonly manager;
|
|
28
29
|
private errors;
|
|
29
30
|
private readonly clock;
|
|
30
|
-
private interactionTimeout;
|
|
31
31
|
private readonly sceneIdFactory;
|
|
32
32
|
static readonly unknownSceneId: CorrelationId;
|
|
33
|
-
/**
|
|
34
|
-
* Actors instantiated after the scene has started,
|
|
35
|
-
* who will be dismissed when the scene finishes.
|
|
36
|
-
*/
|
|
37
|
-
private actorsOnFrontStage;
|
|
38
|
-
/**
|
|
39
|
-
* Actors instantiated before the scene has started,
|
|
40
|
-
* who will be dismissed when the test run finishes.
|
|
41
|
-
*/
|
|
42
|
-
private actorsOnBackstage;
|
|
43
|
-
private actorsOnStage;
|
|
44
|
-
/**
|
|
45
|
-
* The most recent actor referenced via the [`Actor`](https://serenity-js.org/api/core/class/Actor/) method
|
|
46
|
-
*/
|
|
47
|
-
private actorInTheSpotlight;
|
|
48
|
-
/**
|
|
49
|
-
* The scene in which the spotlight was last set.
|
|
50
|
-
* Used to detect when the spotlight shifts to a different scene context.
|
|
51
|
-
*/
|
|
52
|
-
private sceneOfSpotlightedActor;
|
|
53
33
|
private currentActivity;
|
|
54
34
|
private currentScene;
|
|
35
|
+
private readonly actorLifecycleManager;
|
|
55
36
|
/**
|
|
56
|
-
*
|
|
57
|
-
*
|
|
58
|
-
* @param
|
|
59
|
-
* @param
|
|
60
|
-
* @param
|
|
61
|
-
* @param
|
|
62
|
-
|
|
63
|
-
|
|
37
|
+
* Creates a new Stage instance.
|
|
38
|
+
*
|
|
39
|
+
* @param cast - The default cast to use for preparing actors
|
|
40
|
+
* @param manager - The stage manager responsible for notifying listeners of domain events
|
|
41
|
+
* @param errors - Factory for creating runtime errors with proper context
|
|
42
|
+
* @param clock - Clock used for timestamping domain events
|
|
43
|
+
* @param interactionTimeout - Default timeout for actor interactions
|
|
44
|
+
* @param sceneIdFactory - Factory for creating scene correlation IDs
|
|
45
|
+
* @param actorLifecycleManager - Optional custom ActorLifecycleManager instance.
|
|
46
|
+
* When provided, allows test runner adapters to control actor lifecycle programmatically.
|
|
47
|
+
* If not provided, a default manager is created.
|
|
48
|
+
*/
|
|
49
|
+
constructor(cast: Cast, manager: StageManager, errors: ErrorFactory, clock: Clock, interactionTimeout: Duration, sceneIdFactory?: CorrelationIdFactory, actorLifecycleManager?: ActorLifecycleManager);
|
|
64
50
|
configure(options: Pick<SerenityConfig, 'actors' | 'cueTimeout' | 'interactionTimeout' | 'diffFormatter'>): void;
|
|
65
51
|
/**
|
|
66
52
|
* An alias for [`Stage.actor`](https://serenity-js.org/api/core/class/Stage/#actor)
|
|
@@ -97,7 +83,7 @@ export declare class Stage implements EmitsDomainEvents {
|
|
|
97
83
|
engage(actors: Cast): void;
|
|
98
84
|
/**
|
|
99
85
|
* Assigns listeners to be notified of [Serenity/JS domain events](https://serenity-js.org/api/core-events/class/DomainEvent/)
|
|
100
|
-
* emitted via [`Stage.announce`](https://serenity-js.org/api/core/class/Stage/#announce).
|
|
86
|
+
* emitted via [`Stage.announce`](https://serenity-js.org/api/core/class/Stage/#announce).
|
|
101
87
|
*
|
|
102
88
|
* @param listeners
|
|
103
89
|
*/
|
|
@@ -110,6 +96,8 @@ export declare class Stage implements EmitsDomainEvents {
|
|
|
110
96
|
*/
|
|
111
97
|
announce(...events: Array<DomainEvent>): void;
|
|
112
98
|
private announceSingle;
|
|
99
|
+
private notifyOfStageExit;
|
|
100
|
+
private dismissActorsIn;
|
|
113
101
|
/**
|
|
114
102
|
* Returns current time. This method should be used whenever
|
|
115
103
|
* [`DomainEvent`](https://serenity-js.org/api/core-events/class/DomainEvent/) objects are instantiated by you programmatically.
|
|
@@ -161,9 +149,5 @@ export declare class Stage implements EmitsDomainEvents {
|
|
|
161
149
|
*/
|
|
162
150
|
waitForNextCue(): Promise<void>;
|
|
163
151
|
createError<RE extends RuntimeError>(errorType: new (...args: any[]) => RE, options: ErrorOptions): RE;
|
|
164
|
-
private instantiatedActorCalled;
|
|
165
|
-
private notifyOfStageExit;
|
|
166
|
-
private dismiss;
|
|
167
|
-
private typeOf;
|
|
168
152
|
}
|
|
169
153
|
//# sourceMappingURL=Stage.d.ts.map
|
package/esm/stage/Stage.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Stage.d.ts","sourceRoot":"","sources":["../../src/stage/Stage.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACzD,OAAO,
|
|
1
|
+
{"version":3,"file":"Stage.d.ts","sourceRoot":"","sources":["../../src/stage/Stage.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACzD,OAAO,EACH,YAAY,EACZ,KAAK,YAAY,EAEjB,KAAK,YAAY,EACpB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAKH,KAAK,WAAW,EAChB,KAAK,iBAAiB,EAIzB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,KAAK,eAAe,EAAE,aAAa,EAAE,KAAK,oBAAoB,EAAQ,MAAM,mBAAmB,CAAC;AACzG,OAAO,KAAK,EAAE,KAAK,EAAC,MAAM,wBAAwB,CAAC;AACnD,OAAO,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AACzE,OAAO,EAAE,qBAAqB,EAAmB,MAAM,4BAA4B,CAAC;AACpF,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AACxE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEtD;;;;;;;;;;;;;;;GAeG;AACH,qBAAa,KAAM,YAAW,iBAAiB;IAyBvC,OAAO,CAAC,QAAQ,CAAC,OAAO;IACxB,OAAO,CAAC,MAAM;IACd,OAAO,CAAC,QAAQ,CAAC,K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