@serenity-js/core
Version:
The core Serenity/JS framework, providing the Screenplay Pattern interfaces, as well as the test reporting and integration infrastructure
62 lines • 2.38 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.Log = void 0;
const io_1 = require("../../io");
const stringified_1 = require("../../io/stringified");
const model_1 = require("../../model");
const Interaction_1 = require("../Interaction");
/**
* Instructs the [`Actor`](https://serenity-js.org/api/core/class/Actor/)
* to [collect](https://serenity-js.org/api/core/interface/CollectsArtifacts/) arbitrary static values
* and answers to [answerables](https://serenity-js.org/api/core/#Answerable),
* so that they can be sent to the [stage crew members](https://serenity-js.org/api/core/interface/StageCrewMember/)
* and printed to the terminal by the [`ConsoleReporter`](https://serenity-js.org/api/console-reporter/class/ConsoleReporter/)
* or attached to the HTML report by the [`SerenityBDDReporter`](https://serenity-js.org/api/serenity-bdd/class/SerenityBDDReporter/).
*
* ## Logging static and `Answerable` values
*
* ```ts
* import { actorCalled, Log } from '@serenity-js/core'
* import { Page } from '@serenity-js/web'
*
* await actorCalled('Laura').attemptsTo(
* Log.the('Current page', Page.current().title(), Page.current().url()),
* )
* ```
*
* @group Activities
*/
class Log extends Interaction_1.Interaction {
items;
/**
* Instantiates a new [interaction](https://serenity-js.org/api/core/class/Interaction/) to [`Log`](https://serenity-js.org/api/core/class/Log/)
*
* Note that this method accepts [variable number of arguments](https://www.typescriptlang.org/docs/handbook/functions.html#rest-parameters),
* so that you can easily log several values at the same time.
*
* @param items
* The items to be logged
*/
static the(...items) {
return new Log(items);
}
/**
* @param items
* The items to be logged
*/
constructor(items) {
super(`#actor logs: ${items.map(item => (0, io_1.d) `${item}`).join(', ')}`);
this.items = items;
}
/**
* @inheritDoc
*/
async performAs(actor) {
for (const item of this.items) {
const data = await actor.answer(item);
actor.collect(model_1.LogEntry.fromJSON({ data: (0, stringified_1.stringified)(data) }), new model_1.Name((0, io_1.d) `${item}`));
}
}
}
exports.Log = Log;
//# sourceMappingURL=Log.js.map
;