forked from OpenAPITools/openapi-generator-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommand.mock.ts
More file actions
75 lines (65 loc) · 1.69 KB
/
command.mock.ts
File metadata and controls
75 lines (65 loc) · 1.69 KB
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
66
67
68
69
70
71
72
73
74
75
export class CommandMock {
commands: {
[key: string]: {
self: CommandMock,
description: string
allowUnknownOption: boolean
action: (cmd) => unknown
options: Array<{
flags: string
description: string
defaultValue: string
}>
}
} = {};
refs: {
[key: string]: CommandMock
} = {};
private currentCommand: string;
helpInformation = jest.fn().mockReturnValue('some help text');
ensureCommand = () => {
if (!this.commands[this.currentCommand]) {
this.commands[this.currentCommand] = {
self: this,
description: '',
allowUnknownOption: false,
action: () => {},
options: [],
};
}
};
action = jest.fn().mockImplementation((action) => {
this.ensureCommand();
this.commands[this.currentCommand].action = action;
return this;
});
option = jest.fn().mockImplementation((flags, description, defaultValue) => {
const options = this.commands[this.currentCommand]?.options ?? [];
this.ensureCommand();
this.commands[this.currentCommand].options = [
...options,
{
flags,
description,
defaultValue,
},
];
return this;
});
command = jest.fn().mockImplementation((cmd) => {
this.currentCommand = cmd;
this.refs[cmd] = this;
return this;
});
allowUnknownOption = jest.fn().mockImplementation(() => {
this.ensureCommand();
this.commands[this.currentCommand].allowUnknownOption = true;
return this;
});
description = jest.fn().mockImplementation((desc) => {
this.ensureCommand();
this.commands[this.currentCommand].description = desc;
return this;
});
opts = jest.fn();
}