1
1
import parseArgs from '../src/parse-args' ;
2
2
3
+ const log = jest . fn ( ) ;
4
+ // @ts -ignore
5
+ global . console = { log } ;
6
+
3
7
describe ( 'root parser' , ( ) => {
4
- test ( 'should print version' , ( ) => {
5
- console . log = jest . fn ( ) ;
8
+ beforeEach ( ( ) => {
9
+ log . mockClear ( ) ;
10
+ } ) ;
6
11
12
+ test ( 'should print version' , ( ) => {
7
13
parseArgs ( '--version' . split ( ' ' ) ) ;
8
-
9
- expect ( console . log ) . toHaveBeenCalled ( ) ;
14
+ expect ( log ) . toHaveBeenCalled ( ) ;
10
15
} ) ;
11
16
12
17
test ( 'should print help' , ( ) => {
13
- console . log = jest . fn ( ) ;
14
-
15
18
parseArgs ( '--help' . split ( ' ' ) ) ;
16
-
17
- expect ( console . log ) . toHaveBeenCalled ( ) ;
19
+ expect ( log ) . toHaveBeenCalled ( ) ;
18
20
} ) ;
19
21
20
22
test ( 'should print help for simple command' , ( ) => {
21
- console . log = jest . fn ( ) ;
22
-
23
23
parseArgs ( 'init --help' . split ( ' ' ) ) ;
24
-
25
- expect ( console . log ) . toHaveBeenCalled ( ) ;
24
+ expect ( log ) . toHaveBeenCalled ( ) ;
26
25
} ) ;
27
26
28
27
test ( 'should print help for complex command' , ( ) => {
29
- console . log = jest . fn ( ) ;
30
-
31
28
parseArgs ( 'pr --help' . split ( ' ' ) ) ;
32
-
33
- expect ( console . log ) . toHaveBeenCalled ( ) ;
29
+ expect ( log ) . toHaveBeenCalled ( ) ;
34
30
} ) ;
35
31
36
32
test ( 'should exit when required arg is not included' , ( ) => {
@@ -40,14 +36,13 @@ describe('root parser', () => {
40
36
} ) ;
41
37
42
38
test ( 'should exit when required string is provided as flag' , ( ) => {
43
- console . log = jest . fn ( ) as any ;
44
39
process . exit = jest . fn ( ) as any ;
45
40
parseArgs ( [ 'pr-check' , '--pr' , '24' , '--url' ] ) ;
46
41
expect ( process . exit ) . toHaveBeenCalled ( ) ;
47
42
} ) ;
48
43
49
44
test ( 'should parse just provided args' , ( ) => {
50
- expect ( parseArgs ( 'label --pr 2 --owner adam' . split ( ' ' ) ) ) . toEqual ( [
45
+ expect ( parseArgs ( 'label --pr 2 --owner adam' . split ( ' ' ) ) ) . toStrictEqual ( [
51
46
'label' ,
52
47
{
53
48
pr : 2 ,
@@ -57,7 +52,7 @@ describe('root parser', () => {
57
52
} ) ;
58
53
59
54
test ( 'should parse args as camelCase' , ( ) => {
60
- expect ( parseArgs ( 'changelog -d' . split ( ' ' ) ) ) . toEqual ( [
55
+ expect ( parseArgs ( 'changelog -d' . split ( ' ' ) ) ) . toStrictEqual ( [
61
56
'changelog' ,
62
57
{
63
58
dryRun : true
@@ -72,7 +67,7 @@ describe('root parser', () => {
72
67
} ) ;
73
68
74
69
test ( 'allow array of options to or' , ( ) => {
75
- expect ( parseArgs ( [ 'comment' , '--message' , 'foo' ] ) ) . toEqual ( [
70
+ expect ( parseArgs ( [ 'comment' , '--message' , 'foo' ] ) ) . toStrictEqual ( [
76
71
'comment' ,
77
72
{
78
73
message : 'foo'
@@ -81,7 +76,7 @@ describe('root parser', () => {
81
76
} ) ;
82
77
83
78
test ( 'allow edit in comment' , ( ) => {
84
- expect ( parseArgs ( [ 'comment' , '--edit' , '--message' , 'foo' ] ) ) . toEqual ( [
79
+ expect ( parseArgs ( [ 'comment' , '--edit' , '--message' , 'foo' ] ) ) . toStrictEqual ( [
85
80
'comment' ,
86
81
{
87
82
edit : true ,
0 commit comments