@serenity-js/core 3.7.2 → 3.9.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 (30) hide show
  1. package/CHANGELOG.md +27 -0
  2. package/lib/events/ActivityRelatedArtifactArchived.d.ts +1 -1
  3. package/lib/events/ActivityRelatedArtifactArchived.d.ts.map +1 -1
  4. package/lib/events/ActivityRelatedArtifactArchived.js +4 -3
  5. package/lib/events/ActivityRelatedArtifactArchived.js.map +1 -1
  6. package/lib/events/ArtifactArchived.d.ts +2 -1
  7. package/lib/events/ArtifactArchived.d.ts.map +1 -1
  8. package/lib/events/ArtifactArchived.js +5 -2
  9. package/lib/events/ArtifactArchived.js.map +1 -1
  10. package/lib/screenplay/Question.d.ts +18 -5
  11. package/lib/screenplay/Question.d.ts.map +1 -1
  12. package/lib/screenplay/Question.js +22 -20
  13. package/lib/screenplay/Question.js.map +1 -1
  14. package/lib/screenplay/questions/MetaQuestion.d.ts +8 -7
  15. package/lib/screenplay/questions/MetaQuestion.d.ts.map +1 -1
  16. package/lib/stage/crew/artifact-archiver/ArtifactArchiver.d.ts +39 -19
  17. package/lib/stage/crew/artifact-archiver/ArtifactArchiver.d.ts.map +1 -1
  18. package/lib/stage/crew/artifact-archiver/ArtifactArchiver.js +41 -21
  19. package/lib/stage/crew/artifact-archiver/ArtifactArchiver.js.map +1 -1
  20. package/lib/stage/crew/stream-reporter/StreamReporter.d.ts +44 -16
  21. package/lib/stage/crew/stream-reporter/StreamReporter.d.ts.map +1 -1
  22. package/lib/stage/crew/stream-reporter/StreamReporter.js +48 -16
  23. package/lib/stage/crew/stream-reporter/StreamReporter.js.map +1 -1
  24. package/package.json +2 -2
  25. package/src/events/ActivityRelatedArtifactArchived.ts +4 -1
  26. package/src/events/ArtifactArchived.ts +4 -0
  27. package/src/screenplay/Question.ts +67 -8
  28. package/src/screenplay/questions/MetaQuestion.ts +8 -7
  29. package/src/stage/crew/artifact-archiver/ArtifactArchiver.ts +43 -19
  30. package/src/stage/crew/stream-reporter/StreamReporter.ts +51 -16
@@ -1,12 +1,14 @@
1
1
  import type { Writable } from 'stream';
2
+ import { ensure, isDefined, isString } from 'tiny-types';
2
3
 
3
4
  import type { DomainEvent } from '../../../events';
5
+ import { FileSystem, Path } from '../../../io';
4
6
  import type { Stage } from '../../Stage';
5
7
  import type { StageCrewMember } from '../../StageCrewMember';
6
8
 
7
9
  /**
8
10
  * Serialises all the {@apilink DomainEvent} objects it receives and streams
9
- * them as [ndjson](http://ndjson.org/) to the output stream.
11
+ * them as [ndjson](http://ndjson.org/) to the output stream or file.
10
12
  *
11
13
  * Useful when debugging issues related to custom Serenity/JS test runner adapters.
12
14
  *
@@ -35,43 +37,61 @@ import type { StageCrewMember } from '../../StageCrewMember';
35
37
  * })
36
38
  * ```
37
39
  *
38
- * ## Registering `StreamReporter` using Protractor configuration
40
+ * ## Using `StreamReporter` with Playwright Test
41
+ *
42
+ * ```ts
43
+ * // playwright.config.ts
44
+ * import type { PlaywrightTestConfig } from '@serenity-js/playwright-test'
45
+ *
46
+ * const config: PlaywrightTestConfig = {
47
+ * testDir: './spec',
48
+ *
49
+ * reporter: [
50
+ * [ '@serenity-js/playwright-test', {
51
+ * crew: [
52
+ * [ '@serenity-js/core:StreamReporter', { outputFile: './events.ndjson' }]
53
+ * ]
54
+ * // other Serenity/JS config
55
+ * }]
56
+ * ],
57
+ * // other Playwright Test config
58
+ * }
59
+ * ```
60
+ *
61
+ * ## Using `StreamReporter` with Protractor
39
62
  *
40
63
  * ```js
41
64
  * // protractor.conf.js
42
- * const { StreamReporter } = require('@serenity-js/core');
43
- *
44
65
  * exports.config = {
45
66
  * framework: 'custom',
46
67
  * frameworkPath: require.resolve('@serenity-js/protractor/adapter'),
47
68
  *
48
69
  * serenity: {
49
70
  * crew: [
50
- * new StreamReporter(process.stdout),
71
+ * [ '@serenity-js/core:StreamReporter', { outputFile: './events.ndjson' }]
51
72
  * ],
52
73
  * // other Serenity/JS config
53
74
  * },
54
75
  * // other Protractor config
55
- * };
76
+ * }
56
77
  * ```
57
78
  *
58
- * ## Registering `StreamReporter` using WebdriverIO configuration
79
+ * ## Using `StreamReporter` with WebdriverIO
59
80
  *
60
81
  * ```ts
61
- * // wdio.conf.js
62
- * import { StreamReporter } from '@serenity-js/core'
82
+ * // wdio.conf.ts
63
83
  * import { WebdriverIOConfig } from '@serenity-js/webdriverio'
64
84
  *
65
85
  * export const config: WebdriverIOConfig = {
66
86
  *
67
- * framework: '@serenity-js/webdriverio',
87
+ * framework: '@serenity-js/webdriverio',
68
88
  *
69
- * serenity: {
70
- * crew: [
71
- * new StreamReporter(process.stdout),
72
- * ]
73
- * // other Serenity/JS config
74
- * },
89
+ * serenity: {
90
+ * crew: [
91
+ * '@serenity-js/serenity-bdd',
92
+ * [ '@serenity-js/core:StreamReporter', { outputFile: './events.ndjson' }]
93
+ * ]
94
+ * // other Serenity/JS config
75
95
  * },
76
96
  * // other WebdriverIO config
77
97
  * }
@@ -81,6 +101,21 @@ import type { StageCrewMember } from '../../StageCrewMember';
81
101
  */
82
102
  export class StreamReporter implements StageCrewMember {
83
103
 
104
+ /**
105
+ * Instantiates a `StreamReporter` outputting a stream of {@apilink DomainEvent|domain events}
106
+ * to an `outputFile` at the given location.
107
+ *
108
+ * @param config
109
+ */
110
+ static fromJSON(config: { outputFile: string, cwd?: string }): StageCrewMember {
111
+ const outputFile = ensure('outputFile', config?.outputFile, isDefined(), isString());
112
+ const cwd = config.cwd || process.cwd();
113
+
114
+ const fs = new FileSystem(Path.from(cwd))
115
+
116
+ return new StreamReporter(fs.createWriteStreamTo(Path.from(outputFile)));
117
+ }
118
+
84
119
  /**
85
120
  * @param {stream~Writable} output
86
121
  * A Writable stream that should receive the output