UNPKG

@academyjs/rover

Version:

Rover allows you to learn programming interactively.

74 lines 2.38 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const runnable_1 = __importDefault(require("./runnable")); const utils_1 = require("./utils"); const { MOCHA_ID_PROP_NAME } = utils_1.constants; class Hook extends runnable_1.default { /** * Initialize a new `Hook` with the given `title` and callback `fn` */ constructor(title, fn) { super(title, "<hook>", fn); /** * Get or set the test `err`. * * @memberof Hook * @public * @param {Error} err * @return {Error} */ this.error = function (err) { if (!arguments.length) { err = this._error; this._error = null; return err; } this._error = err; }; /** * Returns an object suitable for IPC. * Functions are represented by keys beginning with `$$`. * @private * @returns {Object} */ this.serialize = function serialize() { return { $$currentRetry: this.currentRetry(), $$fullTitle: this.fullTitle(), $$isPending: Boolean(this.isPending()), $$titlePath: this.titlePath(), ctx: this.ctx && this.ctx.currentTest ? { currentTest: { title: this.ctx.currentTest.title, [MOCHA_ID_PROP_NAME]: this.ctx.currentTest.id, }, } : {}, duration: this.duration, file: this.file, parent: { $$fullTitle: this.parent.fullTitle(), [MOCHA_ID_PROP_NAME]: this.parent.id, }, state: this.state, title: this.title, type: this.type, [MOCHA_ID_PROP_NAME]: this.id, }; }; this.type = "hook"; } /** * Resets the state for a next run. */ reset() { super.reset(); delete this._error; } } exports.default = Hook; //# sourceMappingURL=hook.js.map