UNPKG

japa

Version:

Lean test runner for Node.js

41 lines (40 loc) 1.03 kB
"use strict"; /** * @module Core */ Object.defineProperty(exports, "__esModule", { value: true }); exports.Hook = void 0; /* * japa * * (c) Harminder Virk <virk@adonisjs.com> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ const Callable_1 = require("../Callable"); /** * Hook class is used for running the group hooks. */ class Hook { constructor(_resolveFn, _fn, _hookLifecycle) { this._resolveFn = _resolveFn; this._fn = _fn; this._hookLifecycle = _hookLifecycle; } /** * Run the hook. The hooks will raise errors and the parent test or * group should emit required events for them. */ async run() { try { await (0, Callable_1.Callable)(this._resolveFn, this._fn, 0); } catch (error) { error.lifecycle = this._hookLifecycle; error.fnName = this._fn.name; throw error; } } } exports.Hook = Hook;