Skip to main content

externalStageCrewMember

You can think of the StageCrewMember as an in-memory microservice that reacts to Serenity/JS domain events, published by the StageManager, and originally emitted by actors performing activities and Serenity/JS test runner adapters notifying the framework about test scenario-specific events like SceneStarts or SceneFinishes.

Every stage crew member receives a reference to the stage, and therefore the stage manager, which enables them to emit domain events back.

This interface is useful when you're interested in implementing custom Serenity/JS reporters or supporting services.

Implementing a custom StageCrewMember

import { Stage, StageCrewMember } from '@serenity-js/core'
import * as events from '@serenity-js/core/lib/events'
import { ArbitraryTag } from '@serenity-js/core/lib/model'

export class TestRunnerTagger implements StageCrewMember {

static using(tagName: string) {
return new TestRunnerTagger(tagName);
}

protected constructor(
private readonly tagName: string,
private stage?: Stage,
) {
}

assignedTo(stage: Stage): StageCrewMember {
this.stage = stage;
return this;
}

notifyOf(event: events.DomainEvent): void {
if (event instanceof events.TestRunnerDetected) {
this.stage.announce(
new events.SceneTagged(
this.stage.currentSceneId(),
new ArbitraryTag(this.tagName),
this.stage.currentTime()
)
)
}
}
}

Using the custom StageCrewMember

import { configure } from '@serenity-js/core'

configure({
crew: [
TestRunnerTagger.using(`Node:${ process.version }`),
]
})

Learn more

Hierarchy

Implemented by

Index

Methods

externalnotifyOf

externalassignedTo