@serenity-js/core 2.32.2 → 3.0.0-rc.0

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 (181) hide show
  1. package/CHANGELOG.md +64 -0
  2. package/lib/index.d.ts +2 -1
  3. package/lib/index.js +4 -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/collections/index.d.ts +0 -1
  8. package/lib/io/collections/index.js +0 -1
  9. package/lib/io/collections/index.js.map +1 -1
  10. package/lib/io/format.d.ts +37 -0
  11. package/lib/io/format.js +49 -0
  12. package/lib/io/format.js.map +1 -0
  13. package/lib/io/formatted.d.ts +5 -1
  14. package/lib/io/formatted.js +6 -13
  15. package/lib/io/formatted.js.map +1 -1
  16. package/lib/io/index.d.ts +1 -0
  17. package/lib/io/index.js +1 -0
  18. package/lib/io/index.js.map +1 -1
  19. package/lib/io/inspected.d.ts +9 -1
  20. package/lib/io/inspected.js +50 -14
  21. package/lib/io/inspected.js.map +1 -1
  22. package/lib/model/Timestamp.d.ts +4 -2
  23. package/lib/model/Timestamp.js +8 -2
  24. package/lib/model/Timestamp.js.map +1 -1
  25. package/lib/screenplay/Question.d.ts +6 -83
  26. package/lib/screenplay/Question.js +14 -98
  27. package/lib/screenplay/Question.js.map +1 -1
  28. package/lib/screenplay/actor/Actor.js +2 -2
  29. package/lib/screenplay/actor/Actor.js.map +1 -1
  30. package/lib/screenplay/index.d.ts +1 -1
  31. package/lib/screenplay/index.js +1 -1
  32. package/lib/screenplay/index.js.map +1 -1
  33. package/lib/screenplay/model/Adapter.d.ts +8 -0
  34. package/lib/screenplay/{questions/proxies/PropertyPathKey.js → model/Adapter.js} +1 -1
  35. package/lib/screenplay/model/Adapter.js.map +1 -0
  36. package/lib/screenplay/model/createAdapter.d.ts +3 -0
  37. package/lib/screenplay/model/createAdapter.js +112 -0
  38. package/lib/screenplay/model/createAdapter.js.map +1 -0
  39. package/lib/screenplay/model/index.d.ts +2 -0
  40. package/lib/screenplay/{tasks → model}/index.js +2 -1
  41. package/lib/screenplay/model/index.js.map +1 -0
  42. package/lib/screenplay/questions/Expectation.d.ts +11 -0
  43. package/lib/screenplay/questions/Expectation.js +18 -1
  44. package/lib/screenplay/questions/Expectation.js.map +1 -1
  45. package/lib/screenplay/questions/List.d.ts +10 -0
  46. package/lib/screenplay/questions/List.js +16 -1
  47. package/lib/screenplay/questions/List.js.map +1 -1
  48. package/lib/screenplay/questions/Note.d.ts +10 -0
  49. package/lib/screenplay/questions/Note.js +17 -1
  50. package/lib/screenplay/questions/Note.js.map +1 -1
  51. package/lib/screenplay/questions/index.d.ts +0 -3
  52. package/lib/screenplay/questions/index.js +0 -5
  53. package/lib/screenplay/questions/index.js.map +1 -1
  54. package/lib/screenplay/questions/lists/ArrayListAdapter.js +20 -5
  55. package/lib/screenplay/questions/lists/ArrayListAdapter.js.map +1 -1
  56. package/package.json +10 -10
  57. package/src/index.ts +2 -1
  58. package/src/io/ErrorSerialiser.ts +5 -1
  59. package/src/io/collections/index.ts +0 -1
  60. package/src/io/format.ts +46 -0
  61. package/src/io/formatted.ts +7 -15
  62. package/src/io/index.ts +1 -0
  63. package/src/io/inspected.ts +66 -14
  64. package/src/model/Timestamp.ts +10 -2
  65. package/src/screenplay/Question.ts +21 -119
  66. package/src/screenplay/actor/Actor.ts +2 -2
  67. package/src/screenplay/index.ts +1 -1
  68. package/src/screenplay/model/Adapter.ts +14 -0
  69. package/src/screenplay/model/createAdapter.ts +142 -0
  70. package/src/screenplay/model/index.ts +2 -0
  71. package/src/screenplay/questions/Expectation.ts +20 -1
  72. package/src/screenplay/questions/List.ts +19 -1
  73. package/src/screenplay/questions/Note.ts +21 -1
  74. package/src/screenplay/questions/index.ts +0 -3
  75. package/src/screenplay/questions/lists/ArrayListAdapter.ts +21 -2
  76. package/lib/decorators/pending.d.ts +0 -0
  77. package/lib/decorators/pending.js +0 -2
  78. package/lib/decorators/pending.js.map +0 -1
  79. package/lib/decorators/step.d.ts +0 -0
  80. package/lib/decorators/step.js +0 -2
  81. package/lib/decorators/step.js.map +0 -1
  82. package/lib/io/collections/mappable.d.ts +0 -52
  83. package/lib/io/collections/mappable.js +0 -28
  84. package/lib/io/collections/mappable.js.map +0 -1
  85. package/lib/screenplay/questions/Property.d.ts +0 -91
  86. package/lib/screenplay/questions/Property.js +0 -99
  87. package/lib/screenplay/questions/Property.js.map +0 -1
  88. package/lib/screenplay/questions/Transform.d.ts +0 -31
  89. package/lib/screenplay/questions/Transform.js +0 -46
  90. package/lib/screenplay/questions/Transform.js.map +0 -1
  91. package/lib/screenplay/questions/mappings/AnswerMappingFunction.d.ts +0 -11
  92. package/lib/screenplay/questions/mappings/AnswerMappingFunction.js +0 -3
  93. package/lib/screenplay/questions/mappings/AnswerMappingFunction.js.map +0 -1
  94. package/lib/screenplay/questions/mappings/index.d.ts +0 -2
  95. package/lib/screenplay/questions/mappings/index.js +0 -15
  96. package/lib/screenplay/questions/mappings/index.js.map +0 -1
  97. package/lib/screenplay/questions/mappings/string/append.d.ts +0 -14
  98. package/lib/screenplay/questions/mappings/string/append.js +0 -25
  99. package/lib/screenplay/questions/mappings/string/append.js.map +0 -1
  100. package/lib/screenplay/questions/mappings/string/index.d.ts +0 -11
  101. package/lib/screenplay/questions/mappings/string/index.js +0 -24
  102. package/lib/screenplay/questions/mappings/string/index.js.map +0 -1
  103. package/lib/screenplay/questions/mappings/string/normalize.d.ts +0 -20
  104. package/lib/screenplay/questions/mappings/string/normalize.js +0 -30
  105. package/lib/screenplay/questions/mappings/string/normalize.js.map +0 -1
  106. package/lib/screenplay/questions/mappings/string/replace.d.ts +0 -17
  107. package/lib/screenplay/questions/mappings/string/replace.js +0 -30
  108. package/lib/screenplay/questions/mappings/string/replace.js.map +0 -1
  109. package/lib/screenplay/questions/mappings/string/slice.d.ts +0 -28
  110. package/lib/screenplay/questions/mappings/string/slice.js +0 -47
  111. package/lib/screenplay/questions/mappings/string/slice.js.map +0 -1
  112. package/lib/screenplay/questions/mappings/string/split.d.ts +0 -19
  113. package/lib/screenplay/questions/mappings/string/split.js +0 -36
  114. package/lib/screenplay/questions/mappings/string/split.js.map +0 -1
  115. package/lib/screenplay/questions/mappings/string/toLocaleLowerCase.d.ts +0 -17
  116. package/lib/screenplay/questions/mappings/string/toLocaleLowerCase.js +0 -28
  117. package/lib/screenplay/questions/mappings/string/toLocaleLowerCase.js.map +0 -1
  118. package/lib/screenplay/questions/mappings/string/toLocaleUpperCase.d.ts +0 -17
  119. package/lib/screenplay/questions/mappings/string/toLocaleUpperCase.js +0 -29
  120. package/lib/screenplay/questions/mappings/string/toLocaleUpperCase.js.map +0 -1
  121. package/lib/screenplay/questions/mappings/string/toLowerCase.d.ts +0 -10
  122. package/lib/screenplay/questions/mappings/string/toLowerCase.js +0 -19
  123. package/lib/screenplay/questions/mappings/string/toLowerCase.js.map +0 -1
  124. package/lib/screenplay/questions/mappings/string/toNumber.d.ts +0 -10
  125. package/lib/screenplay/questions/mappings/string/toNumber.js +0 -18
  126. package/lib/screenplay/questions/mappings/string/toNumber.js.map +0 -1
  127. package/lib/screenplay/questions/mappings/string/toUpperCase.d.ts +0 -10
  128. package/lib/screenplay/questions/mappings/string/toUpperCase.js +0 -19
  129. package/lib/screenplay/questions/mappings/string/toUpperCase.js.map +0 -1
  130. package/lib/screenplay/questions/mappings/string/trim.d.ts +0 -12
  131. package/lib/screenplay/questions/mappings/string/trim.js +0 -21
  132. package/lib/screenplay/questions/mappings/string/trim.js.map +0 -1
  133. package/lib/screenplay/questions/proxies/PropertyPathKey.d.ts +0 -4
  134. package/lib/screenplay/questions/proxies/PropertyPathKey.js.map +0 -1
  135. package/lib/screenplay/questions/proxies/createMetaQuestionProxy.d.ts +0 -14
  136. package/lib/screenplay/questions/proxies/createMetaQuestionProxy.js +0 -35
  137. package/lib/screenplay/questions/proxies/createMetaQuestionProxy.js.map +0 -1
  138. package/lib/screenplay/questions/proxies/createQuestionProxy.d.ts +0 -13
  139. package/lib/screenplay/questions/proxies/createQuestionProxy.js +0 -34
  140. package/lib/screenplay/questions/proxies/createQuestionProxy.js.map +0 -1
  141. package/lib/screenplay/questions/proxies/describePath.d.ts +0 -5
  142. package/lib/screenplay/questions/proxies/describePath.js +0 -19
  143. package/lib/screenplay/questions/proxies/describePath.js.map +0 -1
  144. package/lib/screenplay/questions/proxies/index.d.ts +0 -2
  145. package/lib/screenplay/questions/proxies/index.js +0 -15
  146. package/lib/screenplay/questions/proxies/index.js.map +0 -1
  147. package/lib/screenplay/questions/proxies/key.d.ts +0 -8
  148. package/lib/screenplay/questions/proxies/key.js +0 -16
  149. package/lib/screenplay/questions/proxies/key.js.map +0 -1
  150. package/lib/screenplay/tasks/Loop.d.ts +0 -198
  151. package/lib/screenplay/tasks/Loop.js +0 -222
  152. package/lib/screenplay/tasks/Loop.js.map +0 -1
  153. package/lib/screenplay/tasks/index.d.ts +0 -1
  154. package/lib/screenplay/tasks/index.js.map +0 -1
  155. package/src/decorators/pending.ts +0 -1
  156. package/src/decorators/step.ts +0 -1
  157. package/src/io/collections/mappable.ts +0 -60
  158. package/src/screenplay/questions/Property.ts +0 -98
  159. package/src/screenplay/questions/Transform.ts +0 -50
  160. package/src/screenplay/questions/mappings/AnswerMappingFunction.ts +0 -13
  161. package/src/screenplay/questions/mappings/index.ts +0 -2
  162. package/src/screenplay/questions/mappings/string/append.ts +0 -28
  163. package/src/screenplay/questions/mappings/string/index.ts +0 -11
  164. package/src/screenplay/questions/mappings/string/normalize.ts +0 -33
  165. package/src/screenplay/questions/mappings/string/replace.ts +0 -34
  166. package/src/screenplay/questions/mappings/string/slice.ts +0 -53
  167. package/src/screenplay/questions/mappings/string/split.ts +0 -38
  168. package/src/screenplay/questions/mappings/string/toLocaleLowerCase.ts +0 -31
  169. package/src/screenplay/questions/mappings/string/toLocaleUpperCase.ts +0 -30
  170. package/src/screenplay/questions/mappings/string/toLowerCase.ts +0 -20
  171. package/src/screenplay/questions/mappings/string/toNumber.ts +0 -19
  172. package/src/screenplay/questions/mappings/string/toUpperCase.ts +0 -20
  173. package/src/screenplay/questions/mappings/string/trim.ts +0 -22
  174. package/src/screenplay/questions/proxies/PropertyPathKey.ts +0 -4
  175. package/src/screenplay/questions/proxies/createMetaQuestionProxy.ts +0 -51
  176. package/src/screenplay/questions/proxies/createQuestionProxy.ts +0 -49
  177. package/src/screenplay/questions/proxies/describePath.ts +0 -23
  178. package/src/screenplay/questions/proxies/index.ts +0 -2
  179. package/src/screenplay/questions/proxies/key.ts +0 -14
  180. package/src/screenplay/tasks/Loop.ts +0 -240
  181. package/src/screenplay/tasks/index.ts +0 -1
@@ -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';