UNPKG

1.03 kBJavaScriptView Raw
1"use strict";
2/**
3 * @module Core
4 */
5Object.defineProperty(exports, "__esModule", { value: true });
6exports.Hook = void 0;
7/*
8 * japa
9 *
10 * (c) Harminder Virk <virk@adonisjs.com>
11 *
12 * For the full copyright and license information, please view the LICENSE
13 * file that was distributed with this source code.
14*/
15const Callable_1 = require("../Callable");
16/**
17 * Hook class is used for running the group hooks.
18 */
19class Hook {
20 constructor(_resolveFn, _fn, _hookLifecycle) {
21 this._resolveFn = _resolveFn;
22 this._fn = _fn;
23 this._hookLifecycle = _hookLifecycle;
24 }
25 /**
26 * Run the hook. The hooks will raise errors and the parent test or
27 * group should emit required events for them.
28 */
29 async run() {
30 try {
31 await (0, Callable_1.Callable)(this._resolveFn, this._fn, 0);
32 }
33 catch (error) {
34 error.lifecycle = this._hookLifecycle;
35 error.fnName = this._fn.name;
36 throw error;
37 }
38 }
39}
40exports.Hook = Hook;