UNPKG

1.29 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3const engine_1 = require("@dxcli/engine");
4const _1 = require(".");
5exports.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//# sourceMappingURL=command.js.map
\No newline at end of file