UNPKG

selenium-state-machine

Version:
42 lines (41 loc) 1.2 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.State = void 0; const Error_1 = require("./Error"); const Provide_1 = require("./Provide"); class State { constructor(config, index, provideConfig) { this.config = config; this.index = index; this.provideConfig = provideConfig; } /** * State timeout. If it is reached, error is threw. */ get timeout() { return this.config.timeout ?? Number.POSITIVE_INFINITY; } /** * Get state name */ get name() { return this.config.name ?? this.config.f.name; } /** * Call the state function. * @param dependencies provided dependencies so far * @returns provide object */ async execute(dependencies) { const provide = new Provide_1.Provide({ provider: this, ...this.provideConfig }); const result = await this.config.f(provide, dependencies); if (result === undefined) { throw new Error_1.CriticalError(`undefined was returned in "${this.config.f?.constructor.name}".`); } return result; } } exports.State = State;