Skip to main content

StageCrewMember

You can think of the StageCrewMember as an in-memory microservice that reacts to 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 StageCrewMember receives a reference to the Stage, and therefore StageManager as well, which enables them to emit DomainEvents 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

notifyOf

assignedTo