@@ -19,6 +19,8 @@ const mockFS = require('fs-extra')
19
19
const mockScripts = require ( '@adobe/aio-app-scripts' ) ( )
20
20
21
21
beforeEach ( ( ) => {
22
+ mockScripts . undeployActions . mockReset ( )
23
+ mockScripts . undeployUI . mockReset ( )
22
24
mockFS . existsSync . mockReset ( )
23
25
jest . restoreAllMocks ( )
24
26
} )
@@ -37,15 +39,11 @@ test('aliases', async () => {
37
39
} )
38
40
39
41
test ( 'flags' , async ( ) => {
40
- expect ( typeof TheCommand . flags . actions ) . toBe ( 'object' )
41
- expect ( TheCommand . flags . actions . char ) . toBe ( 'a' )
42
- expect ( typeof TheCommand . flags . actions . description ) . toBe ( 'string' )
43
- expect ( TheCommand . flags . actions . exclusive ) . toEqual ( [ 'static' ] )
44
-
45
- expect ( typeof TheCommand . flags . static ) . toBe ( 'object' )
46
- expect ( TheCommand . flags . static . char ) . toBe ( 's' )
47
- expect ( typeof TheCommand . flags . static . description ) . toBe ( 'string' )
48
- expect ( TheCommand . flags . static . exclusive ) . toEqual ( [ 'actions' ] )
42
+ expect ( typeof TheCommand . flags [ 'skip-actions' ] ) . toBe ( 'object' )
43
+ expect ( typeof TheCommand . flags [ 'skip-actions' ] . description ) . toBe ( 'string' )
44
+
45
+ expect ( typeof TheCommand . flags [ 'skip-static' ] ) . toBe ( 'object' )
46
+ expect ( typeof TheCommand . flags [ 'skip-static' ] . description ) . toBe ( 'string' )
49
47
} )
50
48
51
49
describe ( 'run' , ( ) => {
@@ -54,6 +52,7 @@ describe('run', () => {
54
52
mockFS . existsSync . mockReset ( )
55
53
command = new TheCommand ( [ ] )
56
54
command . error = jest . fn ( )
55
+ command . log = jest . fn ( )
57
56
} )
58
57
59
58
afterEach ( ( ) => {
@@ -77,54 +76,75 @@ describe('run', () => {
77
76
expect ( mockScripts . undeployUI ) . toHaveBeenCalledTimes ( 1 )
78
77
} )
79
78
80
- test ( 'undeploy only actions' , async ( ) => {
79
+ test ( 'undeploy skip-actions' , async ( ) => {
80
+ mockFS . existsSync . mockReturnValue ( true )
81
+ command . argv = [ '--skip-actions' ]
82
+ await command . run ( )
83
+ expect ( command . error ) . toHaveBeenCalledTimes ( 0 )
84
+ expect ( mockScripts . undeployActions ) . toHaveBeenCalledTimes ( 0 )
85
+ expect ( mockScripts . undeployUI ) . toHaveBeenCalledTimes ( 1 )
86
+ } )
87
+
88
+ test ( 'undeploy skip-actions verbose' , async ( ) => {
81
89
mockFS . existsSync . mockReturnValue ( true )
82
- command . argv = [ '-a' ]
90
+ command . argv = [ '--skip-actions' , '-v' ]
91
+ await command . run ( )
92
+ expect ( command . error ) . toHaveBeenCalledTimes ( 0 )
93
+ expect ( mockScripts . undeployActions ) . toHaveBeenCalledTimes ( 0 )
94
+ expect ( mockScripts . undeployUI ) . toHaveBeenCalledTimes ( 1 )
95
+ } )
96
+
97
+ test ( 'undeploy skip static' , async ( ) => {
98
+ mockFS . existsSync . mockReturnValue ( true )
99
+ command . argv = [ '--skip-static' ]
83
100
await command . run ( )
84
101
expect ( command . error ) . toHaveBeenCalledTimes ( 0 )
85
102
expect ( mockScripts . undeployActions ) . toHaveBeenCalledTimes ( 1 )
86
103
expect ( mockScripts . undeployUI ) . toHaveBeenCalledTimes ( 0 )
87
104
} )
88
105
89
- test ( 'undeploy only actions -- verbose' , async ( ) => {
106
+ test ( 'undeploy skip static verbose' , async ( ) => {
90
107
mockFS . existsSync . mockReturnValue ( true )
91
- command . argv = [ '-a ' ]
108
+ command . argv = [ '--skip-static' , '-v ']
92
109
await command . run ( )
93
110
expect ( command . error ) . toHaveBeenCalledTimes ( 0 )
94
111
expect ( mockScripts . undeployActions ) . toHaveBeenCalledTimes ( 1 )
95
112
expect ( mockScripts . undeployUI ) . toHaveBeenCalledTimes ( 0 )
96
113
} )
97
114
98
- test ( 'undeploy only static files ' , async ( ) => {
99
- command . argv = [ '-s' ]
115
+ test ( 'undeploy an app with no backend ' , async ( ) => {
116
+ mockFS . existsSync . mockImplementation ( f => ! f . includes ( 'manifest' ) )
100
117
await command . run ( )
101
118
expect ( command . error ) . toHaveBeenCalledTimes ( 0 )
102
119
expect ( mockScripts . undeployActions ) . toHaveBeenCalledTimes ( 0 )
103
120
expect ( mockScripts . undeployUI ) . toHaveBeenCalledTimes ( 1 )
121
+ expect ( command . log ) . toHaveBeenCalledWith ( 'no manifest file, skipping action undeploy' )
104
122
} )
105
123
106
- test ( 'undeploy only static files --verbose ' , async ( ) => {
107
- command . argv = [ '-s' , '--verbose' ]
124
+ test ( 'undeploy an app with no frontend ' , async ( ) => {
125
+ mockFS . existsSync . mockImplementation ( f => ! f . includes ( 'web-src' ) )
108
126
await command . run ( )
109
127
expect ( command . error ) . toHaveBeenCalledTimes ( 0 )
110
- expect ( mockScripts . undeployActions ) . toHaveBeenCalledTimes ( 0 )
111
- expect ( mockScripts . undeployUI ) . toHaveBeenCalledTimes ( 1 )
128
+ expect ( mockScripts . undeployActions ) . toHaveBeenCalledTimes ( 1 )
129
+ expect ( mockScripts . undeployUI ) . toHaveBeenCalledTimes ( 0 )
130
+ expect ( command . log ) . toHaveBeenCalledWith ( 'no web-src, skipping web-src undeploy' )
112
131
} )
113
132
114
133
test ( 'should fail if scripts.undeployActions fails' , async ( ) => {
115
134
mockFS . existsSync . mockReturnValue ( true )
116
- const error = new Error ( 'mock failure' )
135
+ const error = new Error ( 'mock failure Actions ' )
117
136
mockScripts . undeployActions . mockRejectedValue ( error )
118
137
await command . run ( )
119
138
expect ( command . error ) . toHaveBeenCalledWith ( error )
120
139
expect ( mockScripts . undeployActions ) . toHaveBeenCalledTimes ( 1 )
121
140
} )
122
141
123
- test ( 'undeploy an App with no backend' , async ( ) => {
124
- mockFS . existsSync . mockReturnValue ( false )
142
+ test ( 'should fail if scripts.undeployUI fails' , async ( ) => {
143
+ mockFS . existsSync . mockReturnValue ( true )
144
+ const error = new Error ( 'mock failure UI' )
145
+ mockScripts . undeployUI . mockRejectedValue ( error )
125
146
await command . run ( )
126
- expect ( command . error ) . toHaveBeenCalledTimes ( 0 )
127
- expect ( mockScripts . undeployActions ) . toHaveBeenCalledTimes ( 0 )
147
+ expect ( command . error ) . toHaveBeenCalledWith ( error )
128
148
expect ( mockScripts . undeployUI ) . toHaveBeenCalledTimes ( 1 )
129
149
} )
130
150
} )
0 commit comments