1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | const engine_1 = require("@dxcli/engine");
|
4 | const _1 = require(".");
|
5 | exports.testCommand = (args, opts, fn) => {
|
6 | const description = opts.description || args.join(' ');
|
7 | let test = _1.it;
|
8 | if (opts.stdout)
|
9 | test = test.stdout;
|
10 | if (opts.stderr)
|
11 | test = test.stderr;
|
12 | test(description, async () => {
|
13 | const exit = opts.exit || 0;
|
14 | try {
|
15 | await engine_1.default(args, { root: opts.root || module.parent.parent.filename });
|
16 | }
|
17 | catch (err) {
|
18 | if (err.code !== 'EEXIT')
|
19 | throw err;
|
20 | if (err['cli-ux'].exit !== exit) {
|
21 | throw new Error(`Expected exit code to be ${exit} but got ${err['cli-ux'].exit}`);
|
22 | }
|
23 | }
|
24 | if (typeof opts.stdout === 'string')
|
25 | _1.expect(_1.output.stdout).to.equal(opts.stdout);
|
26 | if (typeof opts.stderr === 'string')
|
27 | _1.expect(_1.output.stderr).to.equal(opts.stderr);
|
28 | if (!fn)
|
29 | return;
|
30 | let o = {};
|
31 | if (opts.stdout)
|
32 | o.stdout = _1.output.stdout;
|
33 | if (opts.stderr)
|
34 | o.stderr = _1.output.stderr;
|
35 | await fn(o);
|
36 | });
|
37 | };
|
38 |
|
\ | No newline at end of file |