Skip to content

Commit

Permalink
feat(web): give Photographer control over announcing a new photo
Browse files Browse the repository at this point in the history
give the Photographer the chance to intercept creation of artifact in file system

Related tickets: serenity-js#1996
  • Loading branch information
viper3400 committed Nov 5, 2023
1 parent 72d489a commit 15b40e7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
4 changes: 3 additions & 1 deletion packages/web/src/stage/crew/photographer/Photographer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,9 @@ export class Photographer implements StageCrewMember {
}

if (event instanceof ActivityStarts || event instanceof ActivityFinished) {
this.photoTakingStrategy.considerTakingPhoto(event, this.stage);
this.photoTakingStrategy.considerTakingPhoto(event, this.stage).then( (artifact) => {
if (artifact) this.stage.announce(artifact);
})
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export abstract class PhotoTakingStrategy {
* @param stage
* The Stage that holds reference to the Actor in the spotlight
*/
async considerTakingPhoto(event: ActivityStarts | ActivityFinished, stage: Stage): Promise<void> {
async considerTakingPhoto(event: ActivityStarts | ActivityFinished, stage: Stage): Promise<void | ActivityRelatedArtifactGenerated> {
if (! this.shouldTakeAPhotoOf(event)) {
return void 0;
}
Expand Down Expand Up @@ -61,18 +61,21 @@ export abstract class PhotoTakingStrategy {
context = [ capabilities.platformName, capabilities.browserName, capabilities.browserVersion ],
photoName = this.combinedNameFrom(...context, nameSuffix);

stage.announce(new ActivityRelatedArtifactGenerated(
const artifact = new ActivityRelatedArtifactGenerated(
event.sceneId,
event.activityId,
photoName,
Photo.fromBase64(screenshot),
stage.currentTime(),
));
)

return stage.announce(new AsyncOperationCompleted(
stage.announce(new AsyncOperationCompleted(
id,
stage.currentTime(),
));

return new Promise<ActivityRelatedArtifactGenerated>( (resolve) =>
resolve(artifact));
}
catch (error) {
if (this.shouldIgnore(error)) {
Expand Down

0 comments on commit 15b40e7

Please sign in to comment.