UNPKG

961 BJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3const load_config_1 = require("./load-config");
4// eslint-disable-next-line valid-jsdoc
5/**
6 * tests a oclif hook
7 *
8 * @example <caption>check that when the 'init' hook is ran it outputs "this output"</caption>
9 * testHook('init', {id: 'mycommand'}, {stdout: true}, output => {
10 * expect(output.stdout).to.contain('this output')
11 * })
12 *
13 * @param {string} event hook to run
14 * @param {object} hookOpts options to pass to hook. Config object will be passed automatically.
15 */
16exports.default = (event, hookOpts = {}, options = {}) => ({
17 async run(ctx) {
18 if (!event)
19 throw new Error('no hook provided');
20 if (!ctx.config)
21 ctx.config = await (0, load_config_1.loadConfig)(options).run({});
22 ctx.expectation = ctx.expectation || `runs ${event} hook`;
23 ctx.returned = await ctx.config.runHook(event, hookOpts || {});
24 },
25});