@serenity-js/core
Version:
The core Serenity/JS framework, providing the Screenplay Pattern interfaces, as well as the test reporting and integration infrastructure
53 lines • 2.86 kB
JavaScript
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.Activity = void 0;
const path_1 = __importDefault(require("path"));
const errors_1 = require("../errors");
const io_1 = require("../io");
const Describable_1 = require("./questions/Describable");
/**
* **Activities** represents [tasks](https://serenity-js.org/api/core/class/Task/) and [interactions](https://serenity-js.org/api/core/class/Interaction/) to be performed by an [actor](https://serenity-js.org/api/core/class/Actor/).
*
* Learn more about:
* - [Performing activities at multiple levels](https://serenity-js.org/handbook/design/screenplay-pattern#performing-activities-at-multiple-levels)
* - [`Actor`](https://serenity-js.org/api/core/class/Actor/)
* - [`PerformsActivities`](https://serenity-js.org/api/core/interface/PerformsActivities/)
* - [Command design pattern on Wikipedia](https://en.wikipedia.org/wiki/Command_pattern)
*
* @group Screenplay Pattern
*/
class Activity extends Describable_1.Describable {
static errorStackParser = new errors_1.ErrorStackParser();
#location;
constructor(description, location = Activity.callerLocation(5)) {
super(description);
this.#location = location;
}
/**
* Returns the location where this [`Activity`](https://serenity-js.org/api/core/class/Activity/) was instantiated.
*/
instantiationLocation() {
return this.#location;
}
static callerLocation(frameOffset) {
const originalStackTraceLimit = Error.stackTraceLimit;
Error.stackTraceLimit = 30;
const error = new Error('Caller location marker');
Error.stackTraceLimit = originalStackTraceLimit;
const nonSerenityNodeModulePattern = new RegExp(`node_modules` + `\\` + path_1.default.sep + `(?!@serenity-js` + `\\` + path_1.default.sep + `)`);
const frames = this.errorStackParser.parse(error);
const userLandFrames = frames.filter(frame => !(frame?.fileName.startsWith('node:') || // node 16 and 18
frame?.fileName.startsWith('internal') || // node 14
nonSerenityNodeModulePattern.test(frame?.fileName) // ignore node_modules, except for @serenity-js/*
));
const index = Math.min(Math.max(1, frameOffset), userLandFrames.length - 1);
// use the desired user-land frame, or the last one from the stack trace for internal invocations
const invocationFrame = userLandFrames[index] || frames.at(-1);
return new io_1.FileSystemLocation(io_1.Path.from(invocationFrame.fileName?.replace(/^file:/, '')), invocationFrame.lineNumber, invocationFrame.columnNumber);
}
}
exports.Activity = Activity;
//# sourceMappingURL=Activity.js.map
;