@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,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Note = void 0;
4
+ const io_1 = require("../../io");
4
5
  const abilities_1 = require("../abilities");
5
6
  const Question_1 = require("../Question");
6
7
  /**
@@ -46,8 +47,9 @@ class Note extends Question_1.Question {
46
47
  * @param {Question<Promise<Answer>> | Question<Answer> | string} topic
47
48
  */
48
49
  constructor(topic) {
49
- super(`a note of ${topic}`);
50
+ super();
50
51
  this.topic = topic;
52
+ this.subject = (0, io_1.formatted) `a note of ${topic}`;
51
53
  }
52
54
  /**
53
55
  * @desc
@@ -75,6 +77,20 @@ class Note extends Question_1.Question {
75
77
  answeredBy(actor) {
76
78
  return abilities_1.TakeNotes.as(actor).answerTo(this.topic);
77
79
  }
80
+ /**
81
+ * @desc
82
+ * Changes the description of this question's subject.
83
+ *
84
+ * @param {string} subject
85
+ * @returns {Question<T>}
86
+ */
87
+ describedAs(subject) {
88
+ this.subject = subject;
89
+ return this;
90
+ }
91
+ toString() {
92
+ return this.subject;
93
+ }
78
94
  }
79
95
  exports.Note = Note;
80
96
  //# sourceMappingURL=Note.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"Note.js","sourceRoot":"","sources":["../../../src/screenplay/questions/Note.ts"],"names":[],"mappings":";;;AAAA,4CAAyC;AAEzC,0CAAuC;AAEvC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AACH,MAAa,IAAa,SAAQ,mBAAyB;IAcvD;;OAEG;IACH,YAA6B,KAA4D;QACrF,KAAK,CAAC,aAAc,KAAM,EAAE,CAAC,CAAC;QADL,UAAK,GAAL,KAAK,CAAuD;IAEzF,CAAC;IAjBD;;;;;;;OAOG;IACH,MAAM,CAAC,EAAE,CAAI,KAAkD;QAC3D,OAAO,IAAI,IAAI,CAAI,KAAK,CAAC,CAAC;IAC9B,CAAC;IASD;;;;;;;;;;;OAWG;IACH,UAAU,CAAC,KAAuC;QAC9C,OAAO,qBAAS,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IACpD,CAAC;CACJ;AApCD,oBAoCC"}
1
+ {"version":3,"file":"Note.js","sourceRoot":"","sources":["../../../src/screenplay/questions/Note.ts"],"names":[],"mappings":";;;AAAA,iCAAqC;AACrC,4CAAyC;AAEzC,0CAAuC;AAEvC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AACH,MAAa,IAAa,SAAQ,mBAAyB;IAgBvD;;OAEG;IACH,YAA6B,KAA4D;QACrF,KAAK,EAAE,CAAC;QADiB,UAAK,GAAL,KAAK,CAAuD;QAErF,IAAI,CAAC,OAAO,GAAG,IAAA,cAAS,EAAC,aAAc,KAAM,EAAE,CAAC;IACpD,CAAC;IAlBD;;;;;;;OAOG;IACH,MAAM,CAAC,EAAE,CAAI,KAAkD;QAC3D,OAAO,IAAI,IAAI,CAAI,KAAK,CAAC,CAAC;IAC9B,CAAC;IAUD;;;;;;;;;;;OAWG;IACH,UAAU,CAAC,KAAuC;QAC9C,OAAO,qBAAS,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IACpD,CAAC;IAED;;;;;;OAMG;IACH,WAAW,CAAC,OAAe;QACvB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,OAAO,IAAI,CAAC;IAChB,CAAC;IAED,QAAQ;QACJ,OAAO,IAAI,CAAC,OAAO,CAAC;IACxB,CAAC;CACJ;AAvDD,oBAuDC"}
@@ -2,9 +2,6 @@ export * from './Check';
2
2
  export * from './Expectation';
3
3
  export * from './expectations';
4
4
  export * from './List';
5
- export * from './mappings';
6
5
  export * from './MetaQuestion';
7
6
  export * from './Note';
8
- export { Property } from './Property';
9
7
  export * from './q';
10
- export * from './Transform';
@@ -10,16 +10,11 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
10
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
11
  };
12
12
  Object.defineProperty(exports, "__esModule", { value: true });
13
- exports.Property = void 0;
14
13
  __exportStar(require("./Check"), exports);
15
14
  __exportStar(require("./Expectation"), exports);
16
15
  __exportStar(require("./expectations"), exports);
17
16
  __exportStar(require("./List"), exports);
18
- __exportStar(require("./mappings"), exports);
19
17
  __exportStar(require("./MetaQuestion"), exports);
20
18
  __exportStar(require("./Note"), exports);
21
- var Property_1 = require("./Property");
22
- Object.defineProperty(exports, "Property", { enumerable: true, get: function () { return Property_1.Property; } });
23
19
  __exportStar(require("./q"), exports);
24
- __exportStar(require("./Transform"), exports);
25
20
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/screenplay/questions/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,0CAAwB;AACxB,gDAA8B;AAC9B,iDAA+B;AAC/B,yCAAuB;AACvB,6CAA2B;AAC3B,iDAA+B;AAC/B,yCAAuB;AACvB,uCAAsC;AAA7B,oGAAA,QAAQ,OAAA;AACjB,sCAAoB;AACpB,8CAA4B"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/screenplay/questions/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,0CAAwB;AACxB,gDAA8B;AAC9B,iDAA+B;AAC/B,yCAAuB;AACvB,iDAA+B;AAC/B,yCAAuB;AACvB,sCAAoB"}
@@ -1,11 +1,9 @@
1
1
  export * from './Cast';
2
2
  export * from './Clock';
3
3
  export * from './crew';
4
- export * from './DressingRoom';
5
4
  export * from './ListensToDomainEvents';
6
5
  export * from './Stage';
7
6
  export * from './StageCrewMember';
8
7
  export * from './StageCrewMemberBuilder';
9
8
  export * from './StageCrewMemberBuilderDependencies';
10
9
  export * from './StageManager';
11
- export * from './WithStage';
@@ -13,12 +13,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
13
13
  __exportStar(require("./Cast"), exports);
14
14
  __exportStar(require("./Clock"), exports);
15
15
  __exportStar(require("./crew"), exports);
16
- __exportStar(require("./DressingRoom"), exports);
17
16
  __exportStar(require("./ListensToDomainEvents"), exports);
18
17
  __exportStar(require("./Stage"), exports);
19
18
  __exportStar(require("./StageCrewMember"), exports);
20
19
  __exportStar(require("./StageCrewMemberBuilder"), exports);
21
20
  __exportStar(require("./StageCrewMemberBuilderDependencies"), exports);
22
21
  __exportStar(require("./StageManager"), exports);
23
- __exportStar(require("./WithStage"), exports);
24
22
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/stage/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,yCAAuB;AACvB,0CAAwB;AACxB,yCAAuB;AACvB,iDAA+B;AAC/B,0DAAwC;AACxC,0CAAwB;AACxB,oDAAkC;AAClC,2DAAyC;AACzC,uEAAqD;AACrD,iDAA+B;AAC/B,8CAA4B"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/stage/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,yCAAuB;AACvB,0CAAwB;AACxB,yCAAuB;AACvB,0DAAwC;AACxC,0CAAwB;AACxB,oDAAkC;AAClC,2DAAyC;AACzC,uEAAqD;AACrD,iDAA+B"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@serenity-js/core",
3
- "version": "2.33.1",
3
+ "version": "3.0.0-rc.11",
4
4
  "description": "Serenity/JS Screenplay, reporting engine and core interfaces.",
5
5
  "author": {
6
6
  "name": "Jan Molak",
@@ -27,7 +27,7 @@
27
27
  ],
28
28
  "scripts": {
29
29
  "clean": "rimraf .nyc_output lib target",
30
- "lint": "eslint --ext ts --config ../../.eslintrc.js .",
30
+ "lint": "eslint --ext ts --config ../../.eslintrc.yml .",
31
31
  "lint:fix": "npm run lint -- --fix",
32
32
  "test": "nyc --report-dir ../../target/coverage/core mocha --config ../../.mocharc.yml 'spec/**/*.spec.*'",
33
33
  "compile": "tsc --project tsconfig.json",
@@ -36,17 +36,18 @@
36
36
  "dependencies": {
37
37
  "cuid": "^2.1.8",
38
38
  "diff": "^5.0.0",
39
- "error-stack-parser": "^2.0.6",
39
+ "error-stack-parser": "^2.0.7",
40
40
  "fast-glob": "^3.2.11",
41
41
  "filenamify": "^4.3.0",
42
42
  "graceful-fs": "^4.2.9",
43
43
  "moment": "^2.29.1",
44
44
  "semver": "^7.3.5",
45
+ "stackframe": "^1.2.0",
45
46
  "tiny-types": "^1.17.0",
46
47
  "upath": "^2.0.1"
47
48
  },
48
49
  "devDependencies": {
49
- "@documentation/esdoc-template": "2.0.0",
50
+ "@documentation/esdoc-template": "3.0.0",
50
51
  "@types/chai": "^4.3.0",
51
52
  "@types/cuid": "^1.3.1",
52
53
  "@types/diff": "^5.0.2",
@@ -67,7 +68,7 @@
67
68
  "url": "https://github.com/serenity-js/serenity-js/issues"
68
69
  },
69
70
  "engines": {
70
- "node": "^12 || ^14 || ^16",
71
+ "node": "^14 || ^16",
71
72
  "npm": "^6 || ^7 || ^8"
72
73
  },
73
74
  "nyc": {
@@ -92,5 +93,5 @@
92
93
  "cache": true,
93
94
  "all": true
94
95
  },
95
- "gitHead": "c029cb6dde88fb0f034b8471ab93e0483c8b106d"
96
+ "gitHead": "0a232ce7ff21df56a9cc9e64859af5b0bce33b32"
96
97
  }
package/src/index.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  export * from './errors';
2
2
  export * from './instance';
3
- export { Duration } from './model';
3
+ export { d, f, format } from './io';
4
+ export { Duration, Timestamp } from './model';
4
5
  export * from './screenplay';
5
6
  export * from './Serenity';
6
7
  export { SerenityConfig } from './SerenityConfig';
@@ -39,10 +39,14 @@ export class ErrorSerialiser {
39
39
  ];
40
40
 
41
41
  static serialise(error: Error): string {
42
+ const name = error && error.constructor && error.constructor.name
43
+ ? error.constructor.name
44
+ : error.name;
45
+
42
46
  const serialisedError = Object.getOwnPropertyNames(error).reduce((serialised, key) => {
43
47
  serialised[key] = error[key]
44
48
  return serialised;
45
- }, { name: error.constructor.name || error.name }) as SerialisedError;
49
+ }, { name }) as SerialisedError;
46
50
 
47
51
  return stringify(serialisedError);
48
52
  }
@@ -1,4 +1,5 @@
1
1
  import * as parser from 'error-stack-parser';
2
+ import StackFrame = require('stackframe');
2
3
 
3
4
  /**
4
5
  * @desc
@@ -9,7 +10,7 @@ import * as parser from 'error-stack-parser';
9
10
  * @package
10
11
  */
11
12
  export class ErrorStackParser {
12
- parse(error: Error): parser.StackFrame[] {
13
+ parse(error: Error): StackFrame[] {
13
14
  return parser.parse(error);
14
15
  }
15
16
  }
@@ -0,0 +1,18 @@
1
+ /**
2
+ * @desc
3
+ * Maps an Array<Item_Type> to an Array<Result_Type>, one element at a time.
4
+ *
5
+ * @param {Array<Item_Type>} items
6
+ * @param {function(item: Item_Type): Promise<Result_Type>} mappingFunction
7
+ */
8
+ export function asyncMap<Item_Type, Result_Type>(items: Item_Type[], mappingFunction: (item: Item_Type) => Promise<Result_Type> | Result_Type): Promise<Result_Type[]> {
9
+ return items.reduce(
10
+ (previous, item) =>
11
+ previous.then(async (acc) => {
12
+ const result = await mappingFunction(item);
13
+
14
+ return acc.concat(result);
15
+ })
16
+ , Promise.resolve([])
17
+ );
18
+ }
@@ -0,0 +1,49 @@
1
+ import { Answerable } from '../screenplay';
2
+ import { inspected } from './inspected';
3
+
4
+ /**
5
+ * @desc
6
+ * A factory function returning a tag function that produces a human-readable description of a template containing one or more {@link Answerable}s.
7
+ *
8
+ * @link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals#Tagged_template_literals
9
+ *
10
+ * @example
11
+ * import { format, Question } from '@serenity-js/core';
12
+ *
13
+ * const someQuestion = () =>
14
+ * Question.about('some question', actor => 'some value');
15
+ *
16
+ * format({ markQuestions: true }) `actor answers ${ question() }`;
17
+ * // returns: actor answers <<some question>>
18
+ *
19
+ * format({ markQuestions: false }) `actor answers ${ question() }`;
20
+ * // returns: actor answers <<some question>>
21
+ *
22
+ * @example <caption>Aliasing</caption>
23
+ * import { format, Question } from '@serenity-js/core';
24
+ *
25
+ * const f = format({ markQuestions: true });
26
+ *
27
+ * const someQuestion = () =>
28
+ * Question.about('some question', actor => 'some value');
29
+ *
30
+ * f `actor answers ${ question() }`;
31
+ * // produces: actor answers <<some question>>
32
+ *
33
+ * @param {object} config
34
+ * - `markQuestions`: boolean - if set to true, descriptions of questions passed in as arguments will be surrounded with double angled brackets, i.e. `<<description>>`
35
+ * @returns {function(templates: TemplateStringsArray, placeholders: ...Array<Answerable<any>>): string}
36
+ */
37
+ export function format(config: { markQuestions: boolean }): (templates: TemplateStringsArray, ...placeholders: Array<Answerable<any>>) => string {
38
+ return (templates: TemplateStringsArray, ...placeholders: Array<Answerable<any>>): string => {
39
+ return templates
40
+ .map((template, i) => i < placeholders.length
41
+ ? [ template, inspected(placeholders[i], { inline: true, markQuestions: config.markQuestions }) ]
42
+ : [ template ])
43
+ .reduce((acc, tuple) => acc.concat(tuple))
44
+ .join('');
45
+ }
46
+ }
47
+
48
+ export const f = format({ markQuestions: true });
49
+ export const d = format({ markQuestions: false });
@@ -1,28 +1,20 @@
1
- import { Answerable } from '../screenplay/Answerable';
2
- import { inspected } from './inspected';
1
+ import { Answerable } from '../screenplay';
2
+ import { format } from './format';
3
3
 
4
4
  /**
5
5
  * @desc
6
6
  * A tag function returning a human-readable description of a template containing one or more {@link Answerable}s.
7
+ * This function is deprecated, please use {@link format} instead.
7
8
  *
8
9
  * @link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals#Tagged_template_literals
9
10
  *
11
+ *
12
+ * @deprecated
13
+ *
10
14
  * @param {TemplateStringsArray} templates
11
15
  * @param {Array<Answerable<any>>} placeholders
12
16
  * @returns {string}
13
17
  */
14
18
  export function formatted(templates: TemplateStringsArray, ...placeholders: Array<Answerable<any>>): string {
15
- return templates
16
- .map((template, i) => i < placeholders.length
17
- ? [ template, compacted(inspected(placeholders[i])) ]
18
- : [ template ])
19
- .reduce((acc, tuple) => acc.concat(tuple))
20
- .join('');
21
- }
22
-
23
- /** @private */
24
- function compacted(multiline: string) {
25
- return multiline
26
- .replace(/\r?\n/g, ' ')
27
- .replace(/\s+/g, ' ');
19
+ return format({ markQuestions: false })(templates, ...placeholders);
28
20
  }
package/src/io/index.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  export * from './AssertionReportDiffer';
2
- export * from './collections';
2
+ export * from './asyncMap';
3
3
  export * from './commaSeparated';
4
4
  export * from './Config';
5
5
  export * from './ErrorSerialiser';
@@ -7,6 +7,7 @@ export * from './ErrorStackParser';
7
7
  export * from './FileFinder';
8
8
  export * from './FileSystem';
9
9
  export * from './FileSystemLocation';
10
+ export * from './format';
10
11
  export * from './formatted';
11
12
  export * from './json';
12
13
  export * from './ModuleLoader';
@@ -3,6 +3,11 @@ import { inspect } from 'util';
3
3
  import { Answerable } from '../screenplay/Answerable';
4
4
  import { Question } from '../screenplay/Question';
5
5
 
6
+ interface InspectedConfig {
7
+ inline: boolean;
8
+ markQuestions?: boolean;
9
+ }
10
+
6
11
  /**
7
12
  * @desc
8
13
  * Provides a human-readable description of the {@link Answerable<T>}.
@@ -10,27 +15,29 @@ import { Question } from '../screenplay/Question';
10
15
  *
11
16
  * @public
12
17
  * @param {Answerable<any>} value
18
+ * @param config
19
+ * - inline - Return a single-line string instead of the default potentially multi-line description
20
+ * - markQuestions - Surround the description of async values, such as Promises and Questions with <<value>>
13
21
  * @return {string}
14
22
  */
15
- export function inspected(value: Answerable<any>): string {
23
+ export function inspected(value: Answerable<any>, config?: InspectedConfig): string {
24
+
25
+ const { inline, markQuestions } = { inline: false, markQuestions: false, ...config };
26
+
16
27
  if (! isDefined(value)) {
17
28
  return inspect(value);
18
29
  }
19
30
 
20
31
  if (Array.isArray(value)) {
21
- return [
22
- '[',
23
- value.map(item => ` ${ inspected(item) }`).join(',\n'),
24
- ']',
25
- ].join('\n');
32
+ return stringifiedArray(value, inline);
26
33
  }
27
34
 
28
35
  if (isAPromise(value)) {
29
- return `a Promise`;
36
+ return markAs('Promise', true);
30
37
  }
31
38
 
32
39
  if (Question.isAQuestion(value)) {
33
- return value.toString();
40
+ return markAs(value.toString(), markQuestions);
34
41
  }
35
42
 
36
43
  if (isADate(value)) {
@@ -45,15 +52,49 @@ export function inspected(value: Answerable<any>): string {
45
52
  return value.inspect();
46
53
  }
47
54
 
48
- if (isANamedFunction(value)) {
49
- return `${ value.name } property`;
55
+ if (isAFunction(value)) {
56
+ return hasName(value)
57
+ ? value.name
58
+ : markAs(`Function`, true);
50
59
  }
51
60
 
52
61
  if (! hasCustomInspectionFunction(value) && isPlainObject(value) && isSerialisableAsJSON(value)) {
53
- return JSON.stringify(value, undefined, 4);
62
+ return stringifiedToJson(value, inline);
54
63
  }
55
64
 
56
- return inspect(value, { breakLength: Number.POSITIVE_INFINITY, compact: true, sorted: false });
65
+ return inspect(value, { breakLength: Number.POSITIVE_INFINITY, compact: inline ? 3 : false, sorted: false });
66
+ }
67
+
68
+ function stringifiedToJson(value: any, inline: boolean): string {
69
+ const indentation = inline ? 0 : 4;
70
+
71
+ return JSON.stringify(value, undefined, indentation);
72
+ }
73
+
74
+ function stringifiedArray(value: any[], inline: boolean): string {
75
+ const indentation = inline ? '' : ' ';
76
+ const separator = inline ? ' ' : '\n';
77
+
78
+ const inspectedItem = (item: unknown, index: number) =>
79
+ [
80
+ indentation,
81
+ inspected(item, { inline, markQuestions: true }),
82
+ index < value.length - 1 ? ',' : ''
83
+ ].join('')
84
+
85
+ return [
86
+ '[',
87
+ ...value.map(inspectedItem),
88
+ ']',
89
+ ].join(separator);
90
+ }
91
+
92
+ function markAs(value: string, markValue: boolean): string {
93
+ const [left, right] = markValue && ! value.startsWith('<<')
94
+ ? [ '<<', '>>' ]
95
+ : ['', ''];
96
+
97
+ return [ left, value, right ].join('');
57
98
  }
58
99
 
59
100
  /**
@@ -111,7 +152,8 @@ function isADate(v: Answerable<any>): v is Date {
111
152
  * @param {Answerable<any>} v
112
153
  */
113
154
  function isAPromise<T>(v: Answerable<T>): v is Promise<T> {
114
- return !! (v as any).then;
155
+ return typeof v === 'object'
156
+ && 'then' in v;
115
157
  }
116
158
 
117
159
  /**
@@ -121,8 +163,19 @@ function isAPromise<T>(v: Answerable<T>): v is Promise<T> {
121
163
  * @private
122
164
  * @param {Answerable<any>} v
123
165
  */
124
- function isANamedFunction(v: any): v is { name: string } {
125
- return Object.prototype.toString.call(v) === '[object Function]' && (v as any).name !== '';
166
+ function isAFunction(v: any): v is Function { // eslint-disable-line @typescript-eslint/ban-types
167
+ return Object.prototype.toString.call(v) === '[object Function]';
168
+ }
169
+
170
+ /**
171
+ * @desc
172
+ * Checks if the value is has a property called 'name' with a non-empty value.
173
+ *
174
+ * @private
175
+ * @param {Answerable<any>} v
176
+ */
177
+ function hasName(v: any): v is { name: string } {
178
+ return typeof (v as any).name === 'string' && (v as any).name !== '';
126
179
  }
127
180
 
128
181
  /**
@@ -8,7 +8,11 @@ export class Timestamp extends TinyType {
8
8
  return new Timestamp(new Date(ensure(Timestamp.name, v, isSerialisedISO8601Date())));
9
9
  }
10
10
 
11
- static fromMillisecondTimestamp(v: number): Timestamp {
11
+ static fromTimestampInSeconds(v: number): Timestamp {
12
+ return Timestamp.fromTimestampInMilliseconds(v * 1000);
13
+ }
14
+
15
+ static fromTimestampInMilliseconds(v: number): Timestamp {
12
16
  return new Timestamp(moment(v).toDate());
13
17
  }
14
18
 
@@ -29,10 +33,14 @@ export class Timestamp extends TinyType {
29
33
  return new Timestamp(moment(this.value).subtract(duration.inMilliseconds(), 'ms').toDate());
30
34
  }
31
35
 
32
- toMillisecondTimestamp(): number {
36
+ toMilliseconds(): number {
33
37
  return moment(this.value).valueOf();
34
38
  }
35
39
 
40
+ toSeconds(): number {
41
+ return moment(this.value).unix();
42
+ }
43
+
36
44
  toJSON(): string {
37
45
  return this.value.toJSON();
38
46
  }
@@ -0,0 +1,30 @@
1
+ import { Answerable } from './Answerable';
2
+
3
+ /**
4
+ * @desc
5
+ * `Optional` is a container object, which holds a value that may or may not be "present",
6
+ *
7
+ * The meaning of being "present" depends on the context and typically means a value that:
8
+ * - is other than `null` or `undefined`
9
+ * - is retrievable, so retrieving it doesn't throw any errors
10
+ *
11
+ * Additionally, `Optional` can also have a context-specific meaning. For example, `Optional#isPresent()`:
12
+ * - in the context of a `PageElement` means that the element exists in the DOM.
13
+ * - in the context of a `ModalWindow` means that the modal window is open.
14
+ * - in the case of a REST API response, `LastResponse.body().books[0].author.name.isPresent()`
15
+ * will inform us if a given entry exists (so `books[0].author.name`),
16
+ * and if all the links of the property chain leading to the entry of interest exist too
17
+ * (so `books` is present, and so is `books[0]`, `books[0].author`, `books[0].author.name`).
18
+ *
19
+ * @public
20
+ */
21
+ export interface Optional {
22
+ /**
23
+ * @desc
24
+ * Returns an {@link Answerable} that resolves to `true` when the optional value
25
+ * is present, `false` otherwise.
26
+ *
27
+ * @returns {Answerable<boolean>}
28
+ */
29
+ isPresent(): Answerable<boolean>;
30
+ }