@serenity-js/core 2.33.1 → 3.0.0-rc.11

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.
Files changed (210) hide show
  1. package/CHANGELOG.md +476 -0
  2. package/lib/index.d.ts +2 -1
  3. package/lib/index.js +6 -1
  4. package/lib/index.js.map +1 -1
  5. package/lib/io/ErrorSerialiser.js +4 -1
  6. package/lib/io/ErrorSerialiser.js.map +1 -1
  7. package/lib/io/ErrorStackParser.d.ts +2 -2
  8. package/lib/io/ErrorStackParser.js.map +1 -1
  9. package/lib/io/asyncMap.d.ts +8 -0
  10. package/lib/io/asyncMap.js +18 -0
  11. package/lib/io/asyncMap.js.map +1 -0
  12. package/lib/io/format.d.ts +39 -0
  13. package/lib/io/format.js +51 -0
  14. package/lib/io/format.js.map +1 -0
  15. package/lib/io/formatted.d.ts +5 -1
  16. package/lib/io/formatted.js +6 -13
  17. package/lib/io/formatted.js.map +1 -1
  18. package/lib/io/index.d.ts +2 -1
  19. package/lib/io/index.js +2 -1
  20. package/lib/io/index.js.map +1 -1
  21. package/lib/io/inspected.d.ts +9 -1
  22. package/lib/io/inspected.js +52 -15
  23. package/lib/io/inspected.js.map +1 -1
  24. package/lib/model/Timestamp.d.ts +4 -2
  25. package/lib/model/Timestamp.js +8 -2
  26. package/lib/model/Timestamp.js.map +1 -1
  27. package/lib/screenplay/Optional.d.ts +29 -0
  28. package/lib/{io/collections/reducible.js → screenplay/Optional.js} +1 -1
  29. package/lib/screenplay/Optional.js.map +1 -0
  30. package/lib/screenplay/Question.d.ts +41 -82
  31. package/lib/screenplay/Question.js +132 -100
  32. package/lib/screenplay/Question.js.map +1 -1
  33. package/lib/screenplay/actor/Actor.js +2 -2
  34. package/lib/screenplay/actor/Actor.js.map +1 -1
  35. package/lib/screenplay/index.d.ts +1 -1
  36. package/lib/screenplay/index.js +1 -1
  37. package/lib/screenplay/index.js.map +1 -1
  38. package/lib/screenplay/interactions/index.d.ts +0 -1
  39. package/lib/screenplay/interactions/index.js +0 -1
  40. package/lib/screenplay/interactions/index.js.map +1 -1
  41. package/lib/screenplay/questions/Check.d.ts +3 -3
  42. package/lib/screenplay/questions/Check.js +5 -7
  43. package/lib/screenplay/questions/Check.js.map +1 -1
  44. package/lib/screenplay/questions/Expectation.d.ts +15 -10
  45. package/lib/screenplay/questions/Expectation.js +28 -37
  46. package/lib/screenplay/questions/Expectation.js.map +1 -1
  47. package/lib/screenplay/questions/List.d.ts +22 -192
  48. package/lib/screenplay/questions/List.js +160 -208
  49. package/lib/screenplay/questions/List.js.map +1 -1
  50. package/lib/screenplay/questions/Note.d.ts +10 -0
  51. package/lib/screenplay/questions/Note.js +17 -1
  52. package/lib/screenplay/questions/Note.js.map +1 -1
  53. package/lib/screenplay/questions/index.d.ts +0 -3
  54. package/lib/screenplay/questions/index.js +0 -5
  55. package/lib/screenplay/questions/index.js.map +1 -1
  56. package/lib/stage/index.d.ts +0 -2
  57. package/lib/stage/index.js +0 -2
  58. package/lib/stage/index.js.map +1 -1
  59. package/package.json +7 -6
  60. package/src/index.ts +2 -1
  61. package/src/io/ErrorSerialiser.ts +5 -1
  62. package/src/io/ErrorStackParser.ts +2 -1
  63. package/src/io/asyncMap.ts +18 -0
  64. package/src/io/format.ts +49 -0
  65. package/src/io/formatted.ts +7 -15
  66. package/src/io/index.ts +2 -1
  67. package/src/io/inspected.ts +68 -15
  68. package/src/model/Timestamp.ts +10 -2
  69. package/src/screenplay/Optional.ts +30 -0
  70. package/src/screenplay/Question.ts +206 -124
  71. package/src/screenplay/actor/Actor.ts +2 -2
  72. package/src/screenplay/index.ts +1 -1
  73. package/src/screenplay/interactions/index.ts +0 -1
  74. package/src/screenplay/questions/Check.ts +10 -15
  75. package/src/screenplay/questions/Expectation.ts +47 -55
  76. package/src/screenplay/questions/List.ts +224 -233
  77. package/src/screenplay/questions/Note.ts +21 -1
  78. package/src/screenplay/questions/index.ts +0 -3
  79. package/src/stage/index.ts +0 -2
  80. package/lib/io/collections/index.d.ts +0 -2
  81. package/lib/io/collections/index.js +0 -15
  82. package/lib/io/collections/index.js.map +0 -1
  83. package/lib/io/collections/mappable.d.ts +0 -52
  84. package/lib/io/collections/mappable.js +0 -28
  85. package/lib/io/collections/mappable.js.map +0 -1
  86. package/lib/io/collections/reducible.d.ts +0 -16
  87. package/lib/io/collections/reducible.js.map +0 -1
  88. package/lib/screenplay/interactions/See.d.ts +0 -31
  89. package/lib/screenplay/interactions/See.js +0 -43
  90. package/lib/screenplay/interactions/See.js.map +0 -1
  91. package/lib/screenplay/questions/Property.d.ts +0 -91
  92. package/lib/screenplay/questions/Property.js +0 -99
  93. package/lib/screenplay/questions/Property.js.map +0 -1
  94. package/lib/screenplay/questions/Transform.d.ts +0 -31
  95. package/lib/screenplay/questions/Transform.js +0 -46
  96. package/lib/screenplay/questions/Transform.js.map +0 -1
  97. package/lib/screenplay/questions/lists/ArrayListAdapter.d.ts +0 -88
  98. package/lib/screenplay/questions/lists/ArrayListAdapter.js +0 -152
  99. package/lib/screenplay/questions/lists/ArrayListAdapter.js.map +0 -1
  100. package/lib/screenplay/questions/lists/ListAdapter.d.ts +0 -20
  101. package/lib/screenplay/questions/lists/ListAdapter.js +0 -3
  102. package/lib/screenplay/questions/lists/ListAdapter.js.map +0 -1
  103. package/lib/screenplay/questions/lists/index.d.ts +0 -2
  104. package/lib/screenplay/questions/lists/index.js +0 -15
  105. package/lib/screenplay/questions/lists/index.js.map +0 -1
  106. package/lib/screenplay/questions/mappings/AnswerMappingFunction.d.ts +0 -11
  107. package/lib/screenplay/questions/mappings/AnswerMappingFunction.js +0 -3
  108. package/lib/screenplay/questions/mappings/AnswerMappingFunction.js.map +0 -1
  109. package/lib/screenplay/questions/mappings/index.d.ts +0 -2
  110. package/lib/screenplay/questions/mappings/index.js +0 -15
  111. package/lib/screenplay/questions/mappings/index.js.map +0 -1
  112. package/lib/screenplay/questions/mappings/string/append.d.ts +0 -14
  113. package/lib/screenplay/questions/mappings/string/append.js +0 -25
  114. package/lib/screenplay/questions/mappings/string/append.js.map +0 -1
  115. package/lib/screenplay/questions/mappings/string/index.d.ts +0 -11
  116. package/lib/screenplay/questions/mappings/string/index.js +0 -24
  117. package/lib/screenplay/questions/mappings/string/index.js.map +0 -1
  118. package/lib/screenplay/questions/mappings/string/normalize.d.ts +0 -20
  119. package/lib/screenplay/questions/mappings/string/normalize.js +0 -30
  120. package/lib/screenplay/questions/mappings/string/normalize.js.map +0 -1
  121. package/lib/screenplay/questions/mappings/string/replace.d.ts +0 -17
  122. package/lib/screenplay/questions/mappings/string/replace.js +0 -30
  123. package/lib/screenplay/questions/mappings/string/replace.js.map +0 -1
  124. package/lib/screenplay/questions/mappings/string/slice.d.ts +0 -28
  125. package/lib/screenplay/questions/mappings/string/slice.js +0 -47
  126. package/lib/screenplay/questions/mappings/string/slice.js.map +0 -1
  127. package/lib/screenplay/questions/mappings/string/split.d.ts +0 -19
  128. package/lib/screenplay/questions/mappings/string/split.js +0 -36
  129. package/lib/screenplay/questions/mappings/string/split.js.map +0 -1
  130. package/lib/screenplay/questions/mappings/string/toLocaleLowerCase.d.ts +0 -17
  131. package/lib/screenplay/questions/mappings/string/toLocaleLowerCase.js +0 -28
  132. package/lib/screenplay/questions/mappings/string/toLocaleLowerCase.js.map +0 -1
  133. package/lib/screenplay/questions/mappings/string/toLocaleUpperCase.d.ts +0 -17
  134. package/lib/screenplay/questions/mappings/string/toLocaleUpperCase.js +0 -29
  135. package/lib/screenplay/questions/mappings/string/toLocaleUpperCase.js.map +0 -1
  136. package/lib/screenplay/questions/mappings/string/toLowerCase.d.ts +0 -10
  137. package/lib/screenplay/questions/mappings/string/toLowerCase.js +0 -19
  138. package/lib/screenplay/questions/mappings/string/toLowerCase.js.map +0 -1
  139. package/lib/screenplay/questions/mappings/string/toNumber.d.ts +0 -10
  140. package/lib/screenplay/questions/mappings/string/toNumber.js +0 -18
  141. package/lib/screenplay/questions/mappings/string/toNumber.js.map +0 -1
  142. package/lib/screenplay/questions/mappings/string/toUpperCase.d.ts +0 -10
  143. package/lib/screenplay/questions/mappings/string/toUpperCase.js +0 -19
  144. package/lib/screenplay/questions/mappings/string/toUpperCase.js.map +0 -1
  145. package/lib/screenplay/questions/mappings/string/trim.d.ts +0 -12
  146. package/lib/screenplay/questions/mappings/string/trim.js +0 -21
  147. package/lib/screenplay/questions/mappings/string/trim.js.map +0 -1
  148. package/lib/screenplay/questions/proxies/PropertyPathKey.d.ts +0 -4
  149. package/lib/screenplay/questions/proxies/PropertyPathKey.js +0 -3
  150. package/lib/screenplay/questions/proxies/PropertyPathKey.js.map +0 -1
  151. package/lib/screenplay/questions/proxies/createMetaQuestionProxy.d.ts +0 -14
  152. package/lib/screenplay/questions/proxies/createMetaQuestionProxy.js +0 -35
  153. package/lib/screenplay/questions/proxies/createMetaQuestionProxy.js.map +0 -1
  154. package/lib/screenplay/questions/proxies/createQuestionProxy.d.ts +0 -13
  155. package/lib/screenplay/questions/proxies/createQuestionProxy.js +0 -34
  156. package/lib/screenplay/questions/proxies/createQuestionProxy.js.map +0 -1
  157. package/lib/screenplay/questions/proxies/describePath.d.ts +0 -5
  158. package/lib/screenplay/questions/proxies/describePath.js +0 -19
  159. package/lib/screenplay/questions/proxies/describePath.js.map +0 -1
  160. package/lib/screenplay/questions/proxies/index.d.ts +0 -2
  161. package/lib/screenplay/questions/proxies/index.js +0 -15
  162. package/lib/screenplay/questions/proxies/index.js.map +0 -1
  163. package/lib/screenplay/questions/proxies/key.d.ts +0 -8
  164. package/lib/screenplay/questions/proxies/key.js +0 -16
  165. package/lib/screenplay/questions/proxies/key.js.map +0 -1
  166. package/lib/screenplay/tasks/Loop.d.ts +0 -198
  167. package/lib/screenplay/tasks/Loop.js +0 -222
  168. package/lib/screenplay/tasks/Loop.js.map +0 -1
  169. package/lib/screenplay/tasks/index.d.ts +0 -1
  170. package/lib/screenplay/tasks/index.js +0 -14
  171. package/lib/screenplay/tasks/index.js.map +0 -1
  172. package/lib/stage/DressingRoom.d.ts +0 -37
  173. package/lib/stage/DressingRoom.js +0 -53
  174. package/lib/stage/DressingRoom.js.map +0 -1
  175. package/lib/stage/WithStage.d.ts +0 -51
  176. package/lib/stage/WithStage.js +0 -3
  177. package/lib/stage/WithStage.js.map +0 -1
  178. package/src/io/collections/index.ts +0 -2
  179. package/src/io/collections/mappable.ts +0 -60
  180. package/src/io/collections/reducible.ts +0 -16
  181. package/src/screenplay/interactions/See.ts +0 -45
  182. package/src/screenplay/questions/Property.ts +0 -98
  183. package/src/screenplay/questions/Transform.ts +0 -51
  184. package/src/screenplay/questions/lists/ArrayListAdapter.ts +0 -186
  185. package/src/screenplay/questions/lists/ListAdapter.ts +0 -33
  186. package/src/screenplay/questions/lists/index.ts +0 -2
  187. package/src/screenplay/questions/mappings/AnswerMappingFunction.ts +0 -13
  188. package/src/screenplay/questions/mappings/index.ts +0 -2
  189. package/src/screenplay/questions/mappings/string/append.ts +0 -28
  190. package/src/screenplay/questions/mappings/string/index.ts +0 -11
  191. package/src/screenplay/questions/mappings/string/normalize.ts +0 -33
  192. package/src/screenplay/questions/mappings/string/replace.ts +0 -34
  193. package/src/screenplay/questions/mappings/string/slice.ts +0 -53
  194. package/src/screenplay/questions/mappings/string/split.ts +0 -38
  195. package/src/screenplay/questions/mappings/string/toLocaleLowerCase.ts +0 -31
  196. package/src/screenplay/questions/mappings/string/toLocaleUpperCase.ts +0 -30
  197. package/src/screenplay/questions/mappings/string/toLowerCase.ts +0 -20
  198. package/src/screenplay/questions/mappings/string/toNumber.ts +0 -19
  199. package/src/screenplay/questions/mappings/string/toUpperCase.ts +0 -20
  200. package/src/screenplay/questions/mappings/string/trim.ts +0 -22
  201. package/src/screenplay/questions/proxies/PropertyPathKey.ts +0 -4
  202. package/src/screenplay/questions/proxies/createMetaQuestionProxy.ts +0 -51
  203. package/src/screenplay/questions/proxies/createQuestionProxy.ts +0 -49
  204. package/src/screenplay/questions/proxies/describePath.ts +0 -23
  205. package/src/screenplay/questions/proxies/index.ts +0 -2
  206. package/src/screenplay/questions/proxies/key.ts +0 -14
  207. package/src/screenplay/tasks/Loop.ts +0 -240
  208. package/src/screenplay/tasks/index.ts +0 -1
  209. package/src/stage/DressingRoom.ts +0 -53
  210. package/src/stage/WithStage.ts +0 -52
@@ -1,49 +0,0 @@
1
- /* eslint-disable @typescript-eslint/ban-types */
2
- import { formatted } from '../../../io';
3
- import { Answerable } from '../../Answerable';
4
- import { Question } from '../../Question';
5
- import { describePath } from './describePath';
6
- import { key } from './key';
7
- import { PropertyPathKey } from './PropertyPathKey';
8
-
9
- /**
10
- * @package
11
- */
12
- export type WithPropertiesAsQuestions<Original_Type> = {
13
- [Key in keyof Original_Type]: Original_Type[Key] extends object
14
- ? Question<Promise<Original_Type[Key]>> & WithPropertiesAsQuestions<Original_Type[Key]>
15
- : Question<Promise<Original_Type[Key]>>
16
- }
17
-
18
- /**
19
- * @package
20
- */
21
- export function createQuestionProxy<Original_Type extends object>(subject: Answerable<Original_Type>, path: PropertyPathKey[] = []): WithPropertiesAsQuestions<Original_Type> {
22
-
23
- const empty = {};
24
-
25
- return new Proxy<Original_Type>(empty as any, {
26
- get(target: unknown, name: PropertyPathKey) {
27
-
28
- if (key(name).isOneOf<Question<any>>('answeredBy', 'describedAs', 'map', 'toString')) {
29
-
30
- const question = Question.about(formatted `property ${ describePath(path) } of ${ subject }`, actor => {
31
- return actor.answer(subject).then(answer => {
32
-
33
- return path.reduce((subObject, keyName, index) => {
34
- if (keyName in subObject) {
35
- return subObject[keyName];
36
- }
37
- throw new Error(formatted `property ${ describePath(path.slice(0, index + 1)) } of ${ subject } doesn't exist`);
38
- }, answer);
39
-
40
- })
41
- });
42
-
43
- return question[name].bind(question); // eslint-disable-line unicorn/prefer-prototype-methods
44
- }
45
-
46
- return createQuestionProxy(subject, path.concat(name));
47
- }
48
- }) as WithPropertiesAsQuestions<Original_Type>;
49
- }
@@ -1,23 +0,0 @@
1
- import { PropertyPathKey } from './PropertyPathKey';
2
-
3
- /**
4
- * @package
5
- */
6
- export function describePath(parts: PropertyPathKey[]): string {
7
- return parts.reduce(
8
- (acc, segment) =>
9
- acc.concat(
10
- isNumber(segment)
11
- ? `[${ segment }]`
12
- : segment
13
- ),
14
- [],
15
- ).join('.');
16
- }
17
-
18
- /**
19
- * @private
20
- */
21
- function isNumber(segment: PropertyPathKey): segment is number {
22
- return Number.parseInt(String(segment), 10).toString() === segment;
23
- }
@@ -1,2 +0,0 @@
1
- export * from './createMetaQuestionProxy';
2
- export * from './createQuestionProxy';
@@ -1,14 +0,0 @@
1
- /* eslint-disable @typescript-eslint/ban-types,@typescript-eslint/explicit-module-boundary-types */
2
- import { PropertyPathKey } from './PropertyPathKey';
3
-
4
- /**
5
- * @package
6
- * @param {PropertyPathKey} keyName
7
- */
8
- export function key(keyName: PropertyPathKey) {
9
- return {
10
- isOneOf<T extends object = object>(...keys: Array<keyof T>) {
11
- return !!~keys.indexOf(keyName as any);
12
- }
13
- }
14
- }
@@ -1,240 +0,0 @@
1
- import { formatted, Reducible } from '../../io';
2
- import { Activity } from '../Activity';
3
- import { AnswersQuestions, PerformsActivities, UsesAbilities } from '../actor';
4
- import { Answerable } from '../Answerable';
5
- import { Question } from '../Question';
6
- import { Task } from '../Task';
7
-
8
- /**
9
- * @desc
10
- * Enables the {@link Actor} to iterate over a list of items produced by any {@link Answerable}.
11
- *
12
- * You can think of `Loop` as a more sophisticated Screenplay-style equivalent of
13
- * [`Array.forEach`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach).
14
- * `Loop` is capable of working with both synchronous data structures,
15
- * such as [`Array`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)
16
- * and `Question<Array<T>>`,
17
- * as well as asynchronous ones, so `Promise<Array<T>>` and `Question<Promise<Array<T>>>`.
18
- *
19
- * Use {@link Loop.item} to access the current item being processed by {@link Loop}, and {@link Loop.index}
20
- * to access the index of {@link Loop.item} in the list.
21
- *
22
- * @example <caption>Basic scenario - Iterating over a static list of items</caption>
23
- * import { actorCalled, Loop, Log } from '@serenity-js/core';
24
- *
25
- * actorCalled('Joe').attemptsTo(
26
- * Loop.over([ 'apple', 'banana', 'candy' ]).to(
27
- * Log.the('current element', Loop.item<string>()),
28
- * Log.the('current index', Loop.index()),
29
- * ),
30
- * );
31
- *
32
- * @example <caption>API scenario - Iterating over items in an API response</caption>
33
- *
34
- * import { actorCalled, Loop } from '@serenity-js/core';
35
- * import { Send, GetRequest, CallAnApi, LastResponse } from '@serenity-js/rest';
36
- * import { Ensure, property, isGreaterThan } from '@serenity-js/assertions';
37
- *
38
- * interface TodoItem {
39
- * userId: number;
40
- * id: number;
41
- * title: string;
42
- * completed: boolean;
43
- * }
44
- *
45
- * actorCalled('Joe').whoCan(
46
- * CallAnApi.at('https://jsonplaceholder.typicode.com')
47
- * ).attemptsTo(
48
- * Send.a(GetRequest.to('/todos')),
49
- * Loop.over(LastResponse.body<TodoItem[]>()).to(
50
- * Ensure.that(
51
- * Loop.item<TodoItem>(),
52
- * property('userId', isGreaterThan(0)),
53
- * ),
54
- * )
55
- * );
56
- *
57
- * @example <caption>UI scenario - Example widget</caption>
58
- * <nav>
59
- * <div data-test="cookies">
60
- * <label for="functional-cookies">
61
- * <input type="checkbox" id="functional-cookies" />Allow functional cookies
62
- * </label>
63
- * <label for="performance-cookies">
64
- * <input type="checkbox" id="performance-cookies" />Allow performance cookies
65
- * </label>
66
- * <label for="advertising-cookies">
67
- * <input type="checkbox" id="advertising-cookies" />Allow advertising cookies
68
- * </label>
69
- * </div>
70
- * </nav>
71
- *
72
- * @example <caption>UI scenario - Lean Page Object</caption>
73
- * import { Target } from '@serenity-js/protractor';
74
- * import { browser, by } from 'protractor';
75
- *
76
- * class Cookies {
77
- * static labels = Target.all('cookie options')
78
- * .located(by.css('[data-test="cookies"]'));
79
- *
80
- * static checkbox = Target.the('checkbox')
81
- * .located(by.tagName('input')),
82
- * }
83
- *
84
- * @example <caption>UI scenario - Performing the same set of activities with each element</caption>
85
- * import { actorCalled, Loop } from '@serenity-js/core';
86
- * import { Click, Text, isSelected } from '@serenity-js/protractor';
87
- * import { Ensure, startsWith } from '@serenity-js/assertions';
88
- * import { protractor } from 'protractor';
89
- *
90
- * actorCalled('Joe')
91
- * .whoCan(BrowseTheWeb.using(protractor.browser))
92
- * .attemptsTo(
93
- * Loop.over(Cookies.labels).to(
94
- * Ensure.that(
95
- * Text.of(Loop.item<ElementFinder>()),
96
- * startsWith('Allow'),
97
- * ),
98
- *
99
- * Click.on(Loop.item<ElementFinder>()),
100
- * Ensure.that(
101
- * Cookies.checkbox.of(Loop.item<ElementFinder>()),
102
- * isSelected(),
103
- * ),
104
- * ),
105
- * );
106
- *
107
- * @extends {Task}
108
- *
109
- * @see {@link Loop.item}
110
- * @see {@link Loop.index}
111
- * @see {@link Question}
112
- */
113
- export class Loop<Item> extends Task {
114
- private static currentItem: unknown = undefined;
115
- private static currentIndex = 0;
116
-
117
- /**
118
- * @desc
119
- * Instantiates a {@link Task} to {@link Loop}
120
- * that enables the {@link Actor} to iterate over `items`
121
- * to perform some `activities`.
122
- *
123
- * @param {items: Answerable<ReducibleCollection>} items
124
- * @returns {LoopBuilder}
125
- */
126
- static over<T>(items: Answerable<Reducible>): { to: (...activities: Activity[]) => Loop<T> } {
127
- return {
128
- to: (...activities: Activity[]) =>
129
- new Loop<T>(items, activities)
130
- }
131
- }
132
-
133
- /**
134
- * @desc
135
- * Returns the current item being processed by {@link Loop.over}.
136
- *
137
- * **Please note** that in order for the TypeScript transpiler to understand the exact `ExpectedType`
138
- * of the {@link Question} produced by this method you can optionally configure it with
139
- * a [_type variable_](https://www.typescriptlang.org/docs/handbook/generics.html).
140
- *
141
- * For example, configuring the method with type variable of `string`, so `Loop.item<string>()`,
142
- * tells the transpiler that a `Question<string>` will be returned.
143
- *
144
- * If the type variable is not configured, the transpiler assumes that returned type is a
145
- * `Question<any>`. This means that while your code could still work, you'd miss out
146
- * on checking provided by TypeScript.
147
- *
148
- * @returns {Question<ExpectedType>}
149
- */
150
- static item<ExpectedType = any>(): Question<ExpectedType> {
151
- return Question.about<ExpectedType>(`current loop item`, actor =>
152
- Loop.currentItem as ExpectedType,
153
- );
154
- }
155
-
156
- /**
157
- * @desc
158
- * Returns the index of current {@link Loop.item} in the `Answerable<Array>` given to {@link Loop.over}.
159
- *
160
- * The index starts at `0`.
161
- *
162
- * @returns {Question<number>}
163
- */
164
- static index(): Question<number> {
165
- return Question.about<number>(`current loop index`, actor =>
166
- Loop.currentIndex,
167
- );
168
- }
169
-
170
- /**
171
- * @param {Answerable<Reducible>} items
172
- * @param {Activity[]} activities
173
- */
174
- constructor(
175
- private readonly items: Answerable<Reducible>,
176
- private readonly activities: Activity[]
177
- ) {
178
- super();
179
- }
180
-
181
- /**
182
- * @desc
183
- * Makes the provided {@link Actor}
184
- * perform this {@link Task}.
185
- *
186
- * @param {PerformsActivities & UsesAbilities & AnswersQuestions} actor
187
- * @returns {Promise<void>}
188
- *
189
- * @see {@link Actor}
190
- * @see {@link PerformsActivities}
191
- * @see {@link UsesAbilities}
192
- * @see {@link AnswersQuestions}
193
- */
194
- performAs(actor: PerformsActivities & UsesAbilities & AnswersQuestions): PromiseLike<void> | PromiseLike<any> {
195
- return actor.answer(this.items)
196
- .then(items =>
197
- items.reduce((previous: Promise<void>, current: Item, index: number) => {
198
- return previous.then(() => {
199
- Loop.currentIndex = index;
200
- Loop.currentItem = current;
201
-
202
- return actor.attemptsTo(
203
- ...this.activities
204
- );
205
- });
206
- }, Promise.resolve(void 0))
207
- );
208
- }
209
-
210
- /**
211
- * @desc
212
- * Generates a description to be used when reporting this {@link Activity}.
213
- *
214
- * @returns {string}
215
- */
216
- toString(): string {
217
- const description = Array.isArray(this.items)
218
- ? `a list of ${ this.items.length } item${ this.items.length !== 1 ? 's' : '' }`
219
- : formatted `${ this.items }`;
220
-
221
- return `#actor loops over ${ description }`;
222
- }
223
- }
224
-
225
- /**
226
- * @typedef {Object} LoopBuilder
227
- * @property {function(...activities: Activity[]): Loop} to
228
- *
229
- * @example <caption>Basic scenario - Iterating over a static list of items</caption>
230
- * import { actorCalled, Loop, Log } from '@serenity-js/core';
231
- *
232
- * actorCalled('Joe').attemptsTo(
233
- * Loop.over([ 'apple', 'banana', 'candy' ]).to(
234
- * Log.the('current element', Loop.item<string>()),
235
- * ),
236
- * );
237
- *
238
- * @see {@link Loop}
239
- * @see {@link Loop.over}
240
- */
@@ -1 +0,0 @@
1
- export * from './Loop';
@@ -1,53 +0,0 @@
1
- import { Ability, Actor } from '../screenplay';
2
-
3
- /**
4
- * @desc
5
- * Prepares the {@link Actor} for the performance.
6
- *
7
- * @example <caption>A dressing room for actors interacting with a Web UI</caption>
8
- *
9
- * import { serenity, Actor, DressingRoom } from '@serenity-js/core'
10
- * import { BrowseTheWeb } from '@serenity-js/protractor'
11
- * import { protractor } from 'protractor'
12
- *
13
- * class UIActors implements DressingRoom {
14
- * prepare(actor: Actor) {
15
- * return actor.whoCan(BrowseTheWeb.using(protractor.browser));
16
- * }
17
- * }
18
- *
19
- * const stage = serenity.callToStageFor(new UIActors());
20
- *
21
- * @see {@link Stage}
22
- * @see {@link Cast}
23
- * @interface
24
- *
25
- * @deprecated Please use the Cast instead
26
- */
27
- export abstract class DressingRoom {
28
- /**
29
- * @desc
30
- * Creates a generic `DressingRoom` implementation, where every actor
31
- * is given all the abilities specified when the method is called.
32
- *
33
- * @param {Ability[]} abilities
34
- * @returns {DressingRoom}
35
- */
36
- static whereEveryoneCan(...abilities: Ability[]): DressingRoom {
37
- return new GenericDressingRoom(abilities);
38
- }
39
-
40
- abstract prepare(actor: Actor): Actor;
41
- }
42
-
43
- /**
44
- * @package
45
- */
46
- class GenericDressingRoom implements DressingRoom {
47
- constructor(private readonly abilities: Ability[]) {
48
- }
49
-
50
- prepare(actor: Actor): Actor {
51
- return actor.whoCan(...this.abilities);
52
- }
53
- }
@@ -1,52 +0,0 @@
1
- import { Stage } from './Stage';
2
-
3
- /**
4
- * @desc Makes the {@link Stage} object setup in your test runner configuration visible
5
- * to test steps or test scenarios.
6
- *
7
- * When using Cucumber, the {@link Stage} is typically set up using the Cucumber World Constructor.
8
- * When using Jasmine, the {@link Stage} is typically set up in the `beforeEach` step.
9
- *
10
- * @see https://github.com/cucumber/cucumber-js/blob/v5.0.1/docs/support_files/api_reference.md
11
- * @see https://github.com/cucumber/cucumber-js/blob/v5.0.1/docs/support_files/step_definitions.md
12
- * @see https://www.typescriptlang.org/docs/handbook/functions.html#this-parameters
13
- *
14
- * @example <caption>Usage with Cucumber.js</caption>
15
- * // features/support/configure_serenity.ts
16
- * import { WithStage } from '@serenity-js/core';
17
- * import { setWorldConstructor } from 'cucumber';
18
- *
19
- * setWorldConstructor(function (this: WithStage, { parameters }) {
20
- * this.stage = serenity.callToStageFor(new SomeImplementationOfTheCastInterface());
21
- * });
22
- *
23
- * // features/step_definitions/some.steps.ts
24
- * import { WithStage } from '@serenity-js/cucumber';
25
- *
26
- * Given(/(.*?) is a registered customer/, function (this: WithStage, actorName: string) {
27
- * return this.stage.actor(actorName).attemptsTo(
28
- *
29
- * );
30
- * });
31
- *
32
- * @example <caption>Usage with Jasmine</caption>
33
- * // spec/some.spec.ts
34
- * import { serenity, WithStage } from '@serenity-js/core';
35
- *
36
- * describe('Using the Stage', () => {
37
- * beforeEach(function (this: WithStage) {
38
- * this.stage = serenity.callToStageFor(new SomeImplementationOfTheCastInterface());
39
- * });
40
- *
41
- * it('makes it easy to access the Actors', function(this: WithStage) {
42
- * return this.stage.theActorCalled('Barry').attemptsTo(
43
- * // tasks
44
- * );
45
- * })
46
- * });
47
- *
48
- * @deprecated Please use serenity.actor() and serenity.actorInTheSpotlight() instead
49
- */
50
- export interface WithStage {
51
- stage: Stage;
52
- }