/
cli-executer.test.js
65 lines (54 loc) · 2.07 KB
/
cli-executer.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
jest.mock('enquirer');
describe('CLI Executer', () => {
let cliExecuter = null;
let multiCalls = 0;
let multiChoices = null;
let multiMapper = null;
let inputCalls = 0;
const inputConstructorObjs = [];
beforeAll(() => {
let inputRunCount = 0;
const enquirer = require('enquirer');
enquirer.MultiSelect = class MultiSelect {
constructor(obj) {
multiCalls++;
multiChoices = obj.choices;
multiMapper = obj.result;
}
run() {
return ['--config', '--entry', '--progress'];
}
};
enquirer.Input = class Input {
constructor(obj) {
this.mapper = obj.result;
inputCalls++;
inputConstructorObjs.push(obj);
}
run() {
inputRunCount++;
return this.mapper(`test${inputRunCount}`);
}
};
cliExecuter = require('../lib/utils/cli-executer');
});
it('runs enquirer options then runs webpack', async () => {
const args = await cliExecuter();
expect(args.length).toBe(5);
// check that webpack options are actually being displayed that
// the user can select from
expect(multiCalls).toEqual(1);
expect(multiChoices instanceof Array).toBeTruthy();
expect(multiChoices.length > 0).toBeTruthy();
expect(multiChoices[0]).toMatch(/--entry/);
// ensure flag names are parsed out correctly
expect(typeof multiMapper).toEqual('function');
expect(multiMapper(['--test1: test flag', '--test2: test flag 2'])).toEqual(['--test1', '--test2']);
// check that the user is then prompted to set values to
// some flags
expect(inputCalls).toEqual(2);
expect(inputConstructorObjs.length).toEqual(2);
expect(inputConstructorObjs[0].message).toEqual('Enter value of the --config flag');
expect(inputConstructorObjs[1].message).toEqual('Enter value of the --entry flag');
});
});