1
- import { program , Command , Option , CommanderError , InvalidArgumentError , InvalidOptionArgumentError , Help , createCommand } from '../' ;
1
+ import {
2
+ program ,
3
+ Command ,
4
+ Option ,
5
+ Argument ,
6
+ Help ,
7
+ CommanderError ,
8
+ InvalidArgumentError ,
9
+ InvalidOptionArgumentError ,
10
+ createCommand ,
11
+ createOption ,
12
+ createArgument
13
+ } from '../' ;
2
14
3
- import * as commander from '../' ;
15
+ import * as commander from '../' ; // This does interesting things when esModuleInterop is true!
4
16
5
17
// Do some simple checks that expected imports are available at runtime.
6
18
// Similar tests to esm-imports-test.js
@@ -11,38 +23,94 @@ function checkClass(obj: object, name: string): void {
11
23
expect ( obj . constructor . name ) . toEqual ( name ) ;
12
24
}
13
25
14
- test ( 'legacy default export of global Command' , ( ) => {
15
- checkClass ( commander , 'Command' ) ;
16
- } ) ;
26
+ describe ( 'named imports' , ( ) => {
27
+ test ( 'program' , ( ) => {
28
+ checkClass ( program , 'Command' ) ;
29
+ } ) ;
17
30
18
- test ( 'program ' , ( ) => {
19
- checkClass ( program , 'Command' ) ;
20
- } ) ;
31
+ test ( 'Command ' , ( ) => {
32
+ checkClass ( new Command ( 'name' ) , 'Command' ) ;
33
+ } ) ;
21
34
22
- test ( 'createCommand ' , ( ) => {
23
- checkClass ( createCommand ( ) , 'Command ' ) ;
24
- } ) ;
35
+ test ( 'Option ' , ( ) => {
36
+ checkClass ( new Option ( '-e, --example' , 'description' ) , 'Option ' ) ;
37
+ } ) ;
25
38
26
- test ( 'Command ' , ( ) => {
27
- checkClass ( new Command ( 'name' ) , 'Command ' ) ;
28
- } ) ;
39
+ test ( 'Argument ' , ( ) => {
40
+ checkClass ( new Argument ( '<foo>' , 'description' ) , 'Argument ' ) ;
41
+ } ) ;
29
42
30
- test ( 'Option ' , ( ) => {
31
- checkClass ( new Option ( '-e, --example' , 'description' ) , 'Option ' ) ;
32
- } ) ;
43
+ test ( 'Help ' , ( ) => {
44
+ checkClass ( new Help ( ) , 'Help ' ) ;
45
+ } ) ;
33
46
34
- test ( 'CommanderError' , ( ) => {
35
- checkClass ( new CommanderError ( 1 , 'code' , 'failed' ) , 'CommanderError' ) ;
36
- } ) ;
47
+ test ( 'CommanderError' , ( ) => {
48
+ checkClass ( new CommanderError ( 1 , 'code' , 'failed' ) , 'CommanderError' ) ;
49
+ } ) ;
37
50
38
- test ( 'InvalidArgumentError' , ( ) => {
39
- checkClass ( new InvalidArgumentError ( 'failed' ) , 'InvalidArgumentError' ) ;
40
- } ) ;
51
+ test ( 'InvalidArgumentError' , ( ) => {
52
+ checkClass ( new InvalidArgumentError ( 'failed' ) , 'InvalidArgumentError' ) ;
53
+ } ) ;
54
+
55
+ test ( 'InvalidOptionArgumentError' , ( ) => { // Deprecated
56
+ checkClass ( new InvalidOptionArgumentError ( 'failed' ) , 'InvalidArgumentError' ) ;
57
+ } ) ;
58
+
59
+ test ( 'createCommand' , ( ) => {
60
+ checkClass ( createCommand ( 'foo' ) , 'Command' ) ;
61
+ } ) ;
62
+
63
+ test ( 'createOption' , ( ) => {
64
+ checkClass ( createOption ( '-e, --example' , 'description' ) , 'Option' ) ;
65
+ } ) ;
41
66
42
- test ( 'InvalidOptionArgumentError' , ( ) => { // Deprecated
43
- checkClass ( new InvalidOptionArgumentError ( 'failed' ) , 'InvalidArgumentError' ) ;
67
+ test ( 'createArgument' , ( ) => {
68
+ checkClass ( createArgument ( '<foo>' , 'description' ) , 'Argument' ) ;
69
+ } ) ;
44
70
} ) ;
45
71
46
- test ( 'Help' , ( ) => {
47
- checkClass ( new Help ( ) , 'Help' ) ;
72
+ describe ( 'import * as commander' , ( ) => {
73
+ test ( 'program' , ( ) => {
74
+ checkClass ( commander . program , 'Command' ) ;
75
+ } ) ;
76
+
77
+ test ( 'Command' , ( ) => {
78
+ checkClass ( new commander . Command ( 'name' ) , 'Command' ) ;
79
+ } ) ;
80
+
81
+ test ( 'Option' , ( ) => {
82
+ checkClass ( new commander . Option ( '-e, --example' , 'description' ) , 'Option' ) ;
83
+ } ) ;
84
+
85
+ test ( 'Argument' , ( ) => {
86
+ checkClass ( new commander . Argument ( '<foo>' , 'description' ) , 'Argument' ) ;
87
+ } ) ;
88
+
89
+ test ( 'Help' , ( ) => {
90
+ checkClass ( new commander . Help ( ) , 'Help' ) ;
91
+ } ) ;
92
+
93
+ test ( 'CommanderError' , ( ) => {
94
+ checkClass ( new commander . CommanderError ( 1 , 'code' , 'failed' ) , 'CommanderError' ) ;
95
+ } ) ;
96
+
97
+ test ( 'InvalidArgumentError' , ( ) => {
98
+ checkClass ( new commander . InvalidArgumentError ( 'failed' ) , 'InvalidArgumentError' ) ;
99
+ } ) ;
100
+
101
+ test ( 'InvalidOptionArgumentError' , ( ) => { // Deprecated
102
+ checkClass ( new commander . InvalidOptionArgumentError ( 'failed' ) , 'InvalidArgumentError' ) ;
103
+ } ) ;
104
+
105
+ test ( 'createCommand' , ( ) => {
106
+ checkClass ( commander . createCommand ( 'foo' ) , 'Command' ) ;
107
+ } ) ;
108
+
109
+ test ( 'createOption' , ( ) => {
110
+ checkClass ( commander . createOption ( '-e, --example' , 'description' ) , 'Option' ) ;
111
+ } ) ;
112
+
113
+ test ( 'createArgument' , ( ) => {
114
+ checkClass ( commander . createArgument ( '<foo>' , 'description' ) , 'Argument' ) ;
115
+ } ) ;
48
116
} ) ;
0 commit comments