Skip to content

Commit 6cd61db

Browse files
authored
align undeploy flags with deploy command (#172)
* align undeploy flags with deploy command * fix tests + ignore if no web src
1 parent 280e1db commit 6cd61db

File tree

2 files changed

+59
-37
lines changed

2 files changed

+59
-37
lines changed

src/commands/app/undeploy.js

+15-13
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,7 @@ class Undeploy extends BaseCommand {
2626
// cli input
2727
const { flags } = this.parse(Undeploy)
2828

29-
// const appDir = path.resolve(args.path)
30-
// const currDir = process.cwd()
31-
// process.chdir(appDir)
32-
3329
// setup scripts, events and spinner
34-
// todo modularize (same for all app-scripts wrappers)
3530
const spinner = ora()
3631
try {
3732
const listeners = {
@@ -59,22 +54,25 @@ class Undeploy extends BaseCommand {
5954
const scripts = AppScripts({ listeners })
6055

6156
// undeploy
62-
if (!flags.static) {
57+
if (!flags['skip-actions']) {
6358
if (fs.existsSync('manifest.yml')) {
6459
await scripts.undeployActions()
6560
} else {
66-
this.log('no action src, skipping action undeploy')
61+
this.log('no manifest file, skipping action undeploy')
6762
}
6863
}
69-
if (!flags.actions) {
70-
await scripts.undeployUI()
64+
if (!flags['skip-static']) {
65+
if (fs.existsSync('web-src/')) {
66+
await scripts.undeployUI()
67+
} else {
68+
this.log('no web-src, skipping web-src undeploy')
69+
}
7170
}
71+
7272
// final message
7373
this.log(chalk.green(chalk.bold('Undeploy done !')))
74-
// process.chdir(currDir)
7574
} catch (error) {
7675
spinner.fail()
77-
// process.chdir(currDir)
7876
this.error(wrapError(error))
7977
}
8078
}
@@ -85,8 +83,12 @@ Undeploy.description = `Undeploys an Adobe I/O App
8583

8684
Undeploy.flags = {
8785
...BaseCommand.flags,
88-
static: flags.boolean({ char: 's', description: 'Only deploy static files.', exclusive: ['actions'] }),
89-
actions: flags.boolean({ char: 'a', description: 'Only deploy actions.', exclusive: ['static'] })
86+
'skip-static': flags.boolean({
87+
description: 'Skip build & deployment of static files'
88+
}),
89+
'skip-actions': flags.boolean({
90+
description: 'Skip action build & deploy'
91+
})
9092
}
9193

9294
Undeploy.args = []

test/commands/app/undeploy.test.js

+44-24
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ const mockFS = require('fs-extra')
1919
const mockScripts = require('@adobe/aio-app-scripts')()
2020

2121
beforeEach(() => {
22+
mockScripts.undeployActions.mockReset()
23+
mockScripts.undeployUI.mockReset()
2224
mockFS.existsSync.mockReset()
2325
jest.restoreAllMocks()
2426
})
@@ -37,15 +39,11 @@ test('aliases', async () => {
3739
})
3840

3941
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')
4947
})
5048

5149
describe('run', () => {
@@ -54,6 +52,7 @@ describe('run', () => {
5452
mockFS.existsSync.mockReset()
5553
command = new TheCommand([])
5654
command.error = jest.fn()
55+
command.log = jest.fn()
5756
})
5857

5958
afterEach(() => {
@@ -77,54 +76,75 @@ describe('run', () => {
7776
expect(mockScripts.undeployUI).toHaveBeenCalledTimes(1)
7877
})
7978

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 () => {
8189
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']
83100
await command.run()
84101
expect(command.error).toHaveBeenCalledTimes(0)
85102
expect(mockScripts.undeployActions).toHaveBeenCalledTimes(1)
86103
expect(mockScripts.undeployUI).toHaveBeenCalledTimes(0)
87104
})
88105

89-
test('undeploy only actions --verbose', async () => {
106+
test('undeploy skip static verbose', async () => {
90107
mockFS.existsSync.mockReturnValue(true)
91-
command.argv = ['-a']
108+
command.argv = ['--skip-static', '-v']
92109
await command.run()
93110
expect(command.error).toHaveBeenCalledTimes(0)
94111
expect(mockScripts.undeployActions).toHaveBeenCalledTimes(1)
95112
expect(mockScripts.undeployUI).toHaveBeenCalledTimes(0)
96113
})
97114

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'))
100117
await command.run()
101118
expect(command.error).toHaveBeenCalledTimes(0)
102119
expect(mockScripts.undeployActions).toHaveBeenCalledTimes(0)
103120
expect(mockScripts.undeployUI).toHaveBeenCalledTimes(1)
121+
expect(command.log).toHaveBeenCalledWith('no manifest file, skipping action undeploy')
104122
})
105123

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'))
108126
await command.run()
109127
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')
112131
})
113132

114133
test('should fail if scripts.undeployActions fails', async () => {
115134
mockFS.existsSync.mockReturnValue(true)
116-
const error = new Error('mock failure')
135+
const error = new Error('mock failure Actions')
117136
mockScripts.undeployActions.mockRejectedValue(error)
118137
await command.run()
119138
expect(command.error).toHaveBeenCalledWith(error)
120139
expect(mockScripts.undeployActions).toHaveBeenCalledTimes(1)
121140
})
122141

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)
125146
await command.run()
126-
expect(command.error).toHaveBeenCalledTimes(0)
127-
expect(mockScripts.undeployActions).toHaveBeenCalledTimes(0)
147+
expect(command.error).toHaveBeenCalledWith(error)
128148
expect(mockScripts.undeployUI).toHaveBeenCalledTimes(1)
129149
})
130150
})

0 commit comments

Comments
 (0)