@adobe/aio-lib-web 7.2.0 → 8.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/e2e/e2e.js +12 -4
- package/lib/remote-storage.js +219 -75
- package/package.json +5 -3
- package/src/build-web.js +11 -1
- package/src/bundle.js +28 -6
- package/src/constants.js +19 -0
- package/src/deploy-web.js +28 -9
- package/src/undeploy-web.js +18 -6
- package/test/jest.setup.js +28 -0
- package/test/lib/remote-storage.test.js +952 -554
- package/test/src/build-web.test.js +40 -1
- package/test/src/bundle.test.js +52 -0
- package/test/src/deploy-web.test.js +197 -79
- package/test/src/undeploy-web.test.js +88 -19
- package/lib/getS3Creds.js +0 -42
- package/test/lib/getS3Creds.test.js +0 -73
|
@@ -15,6 +15,7 @@ const { vol } = global.mockFs()
|
|
|
15
15
|
const buildWeb = require('../../src/build-web')
|
|
16
16
|
const fs = require('fs-extra')
|
|
17
17
|
jest.mock('fs-extra')
|
|
18
|
+
const originalNodeEnv = process.env.NODE_ENV
|
|
18
19
|
|
|
19
20
|
describe('build-web', () => {
|
|
20
21
|
beforeEach(() => {
|
|
@@ -24,6 +25,14 @@ describe('build-web', () => {
|
|
|
24
25
|
global.cleanFs(vol)
|
|
25
26
|
})
|
|
26
27
|
|
|
28
|
+
afterEach(() => {
|
|
29
|
+
if (originalNodeEnv === undefined) {
|
|
30
|
+
delete process.env.NODE_ENV
|
|
31
|
+
} else {
|
|
32
|
+
process.env.NODE_ENV = originalNodeEnv
|
|
33
|
+
}
|
|
34
|
+
})
|
|
35
|
+
|
|
27
36
|
test('throws if config does not have an app, or frontEnd', async () => {
|
|
28
37
|
await expect(buildWeb()).rejects.toThrow('cannot build web')
|
|
29
38
|
await expect(buildWeb({ app: 'nothing-here' })).rejects.toThrow('cannot build web')
|
|
@@ -51,6 +60,7 @@ describe('build-web', () => {
|
|
|
51
60
|
})
|
|
52
61
|
|
|
53
62
|
test('check build options', async () => {
|
|
63
|
+
delete process.env.NODE_ENV
|
|
54
64
|
const config = {
|
|
55
65
|
app: {
|
|
56
66
|
hasFrontend: true
|
|
@@ -68,13 +78,42 @@ describe('build-web', () => {
|
|
|
68
78
|
defaultConfig: expect.stringContaining(path.join('parcel', 'config-default', 'index.json')),
|
|
69
79
|
defaultTargetOptions: expect.objectContaining({
|
|
70
80
|
distDir: 'dist',
|
|
71
|
-
publicUrl: './'
|
|
81
|
+
publicUrl: './',
|
|
82
|
+
shouldOptimize: false
|
|
72
83
|
}),
|
|
84
|
+
env: expect.objectContaining({ NODE_ENV: 'development' }),
|
|
73
85
|
entries: path.join('fakeDir', 'index.html'),
|
|
74
86
|
logLevel: 'none',
|
|
87
|
+
mode: 'development',
|
|
75
88
|
shouldContentHash: true,
|
|
76
89
|
shouldDisableCache: true
|
|
77
90
|
})
|
|
78
91
|
])
|
|
79
92
|
})
|
|
93
|
+
|
|
94
|
+
test('uses production build options from NODE_ENV', async () => {
|
|
95
|
+
process.env.NODE_ENV = 'production'
|
|
96
|
+
const config = {
|
|
97
|
+
app: {
|
|
98
|
+
hasFrontend: true
|
|
99
|
+
},
|
|
100
|
+
web: {
|
|
101
|
+
distProd: 'dist',
|
|
102
|
+
src: 'fakeDir'
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
global.addFakeFiles(vol, 'fakeDir', { 'index.html': '' })
|
|
106
|
+
fs.readdir.mockReturnValue(['output.html'])
|
|
107
|
+
|
|
108
|
+
await expect(buildWeb(config)).resolves.toEqual(['output.html'])
|
|
109
|
+
expect(global._bundler__arguments).toEqual([
|
|
110
|
+
expect.objectContaining({
|
|
111
|
+
defaultTargetOptions: expect.objectContaining({
|
|
112
|
+
shouldOptimize: true
|
|
113
|
+
}),
|
|
114
|
+
env: expect.objectContaining({ NODE_ENV: 'production' }),
|
|
115
|
+
mode: 'production'
|
|
116
|
+
})
|
|
117
|
+
])
|
|
118
|
+
})
|
|
80
119
|
})
|
package/test/src/bundle.test.js
CHANGED
|
@@ -15,6 +15,7 @@ const bundle = require('../../src/bundle')
|
|
|
15
15
|
const fs = require('fs-extra')
|
|
16
16
|
jest.mock('fs-extra')
|
|
17
17
|
const path = require('path')
|
|
18
|
+
const originalNodeEnv = process.env.NODE_ENV
|
|
18
19
|
|
|
19
20
|
describe('bundle', () => {
|
|
20
21
|
beforeEach(() => {
|
|
@@ -24,6 +25,14 @@ describe('bundle', () => {
|
|
|
24
25
|
global.cleanFs(vol)
|
|
25
26
|
})
|
|
26
27
|
|
|
28
|
+
afterEach(() => {
|
|
29
|
+
if (originalNodeEnv === undefined) {
|
|
30
|
+
delete process.env.NODE_ENV
|
|
31
|
+
} else {
|
|
32
|
+
process.env.NODE_ENV = originalNodeEnv
|
|
33
|
+
}
|
|
34
|
+
})
|
|
35
|
+
|
|
27
36
|
test('throws if config does not have an app, or frontEnd', async () => {
|
|
28
37
|
// much of this is actually now the callers responsibility
|
|
29
38
|
await expect(bundle()).rejects.toThrow('cannot build web')
|
|
@@ -49,6 +58,7 @@ describe('bundle', () => {
|
|
|
49
58
|
})
|
|
50
59
|
|
|
51
60
|
test('check build options', async () => {
|
|
61
|
+
delete process.env.NODE_ENV
|
|
52
62
|
global.addFakeFiles(vol, 'fakeDir', { 'index.html': '' })
|
|
53
63
|
await expect(bundle('fakeDir/index.html', 'distProd')).resolves.toEqual(expect.any(Object))
|
|
54
64
|
expect(global._bundler__arguments).toEqual([
|
|
@@ -58,8 +68,10 @@ describe('bundle', () => {
|
|
|
58
68
|
distDir: 'distProd',
|
|
59
69
|
shouldOptimize: false
|
|
60
70
|
}),
|
|
71
|
+
env: expect.objectContaining({ NODE_ENV: 'development' }),
|
|
61
72
|
entries: 'fakeDir/index.html',
|
|
62
73
|
logLevel: 'error',
|
|
74
|
+
mode: 'development',
|
|
63
75
|
shouldContentHash: true,
|
|
64
76
|
shouldDisableCache: false
|
|
65
77
|
})])
|
|
@@ -99,6 +111,46 @@ describe('bundle', () => {
|
|
|
99
111
|
})])
|
|
100
112
|
})
|
|
101
113
|
|
|
114
|
+
test('uses production build options from NODE_ENV', async () => {
|
|
115
|
+
process.env.NODE_ENV = 'production'
|
|
116
|
+
global.addFakeFiles(vol, 'fakeDir', { 'index.html': '' })
|
|
117
|
+
|
|
118
|
+
await expect(bundle('fakeDir/index.html', 'distProd')).resolves.toEqual(expect.any(Object))
|
|
119
|
+
expect(global._bundler__arguments).toEqual([
|
|
120
|
+
expect.objectContaining({
|
|
121
|
+
defaultTargetOptions: expect.objectContaining({
|
|
122
|
+
distDir: 'distProd',
|
|
123
|
+
shouldOptimize: true
|
|
124
|
+
}),
|
|
125
|
+
env: expect.objectContaining({ NODE_ENV: 'production' }),
|
|
126
|
+
mode: 'production'
|
|
127
|
+
})])
|
|
128
|
+
})
|
|
129
|
+
|
|
130
|
+
test('allows explicit Parcel mode, environment and target option overrides', async () => {
|
|
131
|
+
process.env.NODE_ENV = 'development'
|
|
132
|
+
global.addFakeFiles(vol, 'fakeDir', { 'index.html': '' })
|
|
133
|
+
|
|
134
|
+
await expect(bundle('fakeDir/index.html', 'distProd', {
|
|
135
|
+
mode: 'production',
|
|
136
|
+
env: { NODE_ENV: 'production', CUSTOM_ENV: 'custom' },
|
|
137
|
+
defaultTargetOptions: { publicUrl: './', shouldOptimize: false }
|
|
138
|
+
})).resolves.toEqual(expect.any(Object))
|
|
139
|
+
expect(global._bundler__arguments).toEqual([
|
|
140
|
+
expect.objectContaining({
|
|
141
|
+
defaultTargetOptions: expect.objectContaining({
|
|
142
|
+
distDir: 'distProd',
|
|
143
|
+
publicUrl: './',
|
|
144
|
+
shouldOptimize: false
|
|
145
|
+
}),
|
|
146
|
+
env: {
|
|
147
|
+
NODE_ENV: 'production',
|
|
148
|
+
CUSTOM_ENV: 'custom'
|
|
149
|
+
},
|
|
150
|
+
mode: 'production'
|
|
151
|
+
})])
|
|
152
|
+
})
|
|
153
|
+
|
|
102
154
|
test('returns {bundle, cleanup}', async () => {
|
|
103
155
|
global.addFakeFiles(vol, 'fakeDir', { 'index.html': '' })
|
|
104
156
|
|
|
@@ -15,10 +15,6 @@ const deployWeb = require('../../src/deploy-web')
|
|
|
15
15
|
const fs = require('fs-extra')
|
|
16
16
|
jest.mock('fs-extra')
|
|
17
17
|
|
|
18
|
-
jest.mock('../../lib/getS3Creds')
|
|
19
|
-
const getS3Credentials = require('../../lib/getS3Creds')
|
|
20
|
-
getS3Credentials.mockResolvedValue('fakecreds')
|
|
21
|
-
|
|
22
18
|
const mockRemoteStorageInstance = {
|
|
23
19
|
emptyFolder: jest.fn(),
|
|
24
20
|
folderExists: jest.fn(),
|
|
@@ -37,7 +33,6 @@ describe('deploy-web', () => {
|
|
|
37
33
|
mockRemoteStorageInstance.emptyFolder.mockReset()
|
|
38
34
|
mockRemoteStorageInstance.folderExists.mockReset()
|
|
39
35
|
mockRemoteStorageInstance.uploadDir.mockReset()
|
|
40
|
-
getS3Credentials.mockClear()
|
|
41
36
|
|
|
42
37
|
global.cleanFs(vol)
|
|
43
38
|
})
|
|
@@ -48,10 +43,34 @@ describe('deploy-web', () => {
|
|
|
48
43
|
await expect(deployWeb({ app: { hasFrontEnd: false } })).rejects.toThrow('cannot deploy web')
|
|
49
44
|
})
|
|
50
45
|
|
|
46
|
+
test('throws if no auth token', async () => {
|
|
47
|
+
const config = {
|
|
48
|
+
app: {
|
|
49
|
+
hasFrontend: true
|
|
50
|
+
},
|
|
51
|
+
ow: {
|
|
52
|
+
namespace: 'ns',
|
|
53
|
+
auth_handler: {
|
|
54
|
+
getAuthHeader: jest.fn().mockResolvedValue(null)
|
|
55
|
+
}
|
|
56
|
+
},
|
|
57
|
+
web: {
|
|
58
|
+
distProd: 'dist'
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
await expect(deployWeb(config)).rejects.toThrow('cannot deploy web, Authorization is required')
|
|
62
|
+
})
|
|
63
|
+
|
|
51
64
|
test('throws if src dir does not exist', async () => {
|
|
52
65
|
const config = {
|
|
53
66
|
s3: {
|
|
54
|
-
|
|
67
|
+
folder: 'somefolder'
|
|
68
|
+
},
|
|
69
|
+
ow: {
|
|
70
|
+
namespace: 'ns',
|
|
71
|
+
auth_handler: {
|
|
72
|
+
getAuthHeader: jest.fn().mockResolvedValue('Bearer token')
|
|
73
|
+
}
|
|
55
74
|
},
|
|
56
75
|
app: {
|
|
57
76
|
hasFrontend: true
|
|
@@ -66,7 +85,13 @@ describe('deploy-web', () => {
|
|
|
66
85
|
test('throws if src dir is not a directory', async () => {
|
|
67
86
|
const config = {
|
|
68
87
|
s3: {
|
|
69
|
-
|
|
88
|
+
folder: 'somefolder'
|
|
89
|
+
},
|
|
90
|
+
ow: {
|
|
91
|
+
namespace: 'ns',
|
|
92
|
+
auth_handler: {
|
|
93
|
+
getAuthHeader: jest.fn().mockResolvedValue('Bearer token')
|
|
94
|
+
}
|
|
70
95
|
},
|
|
71
96
|
app: {
|
|
72
97
|
hasFrontend: true
|
|
@@ -80,13 +105,20 @@ describe('deploy-web', () => {
|
|
|
80
105
|
await expect(deployWeb(config)).rejects.toThrow('missing files in dist')
|
|
81
106
|
})
|
|
82
107
|
|
|
83
|
-
test('throws if
|
|
84
|
-
const
|
|
108
|
+
test('throws if hostname or namespace is missing', async () => {
|
|
109
|
+
const baseConfig = {
|
|
85
110
|
s3: {
|
|
86
|
-
|
|
111
|
+
folder: 'somefolder'
|
|
112
|
+
},
|
|
113
|
+
ow: {
|
|
114
|
+
namespace: 'ns',
|
|
115
|
+
auth_handler: {
|
|
116
|
+
getAuthHeader: jest.fn().mockResolvedValue('Bearer token')
|
|
117
|
+
}
|
|
87
118
|
},
|
|
88
119
|
app: {
|
|
89
|
-
hasFrontend: true
|
|
120
|
+
hasFrontend: true,
|
|
121
|
+
hostname: 'host'
|
|
90
122
|
},
|
|
91
123
|
web: {
|
|
92
124
|
distProd: 'dist'
|
|
@@ -94,21 +126,56 @@ describe('deploy-web', () => {
|
|
|
94
126
|
}
|
|
95
127
|
fs.existsSync.mockReturnValue(true)
|
|
96
128
|
fs.lstatSync.mockReturnValue({ isDirectory: () => true })
|
|
97
|
-
fs.readdirSync.mockReturnValue({ length:
|
|
98
|
-
|
|
129
|
+
fs.readdirSync.mockReturnValue({ length: 1 })
|
|
130
|
+
|
|
131
|
+
await expect(deployWeb({
|
|
132
|
+
...baseConfig,
|
|
133
|
+
app: { hasFrontend: true }
|
|
134
|
+
})).rejects.toThrow('config.app.hostname and config.ow.namespace are required')
|
|
135
|
+
|
|
136
|
+
await expect(deployWeb({
|
|
137
|
+
...baseConfig,
|
|
138
|
+
ow: { auth_handler: baseConfig.ow.auth_handler }
|
|
139
|
+
})).rejects.toThrow('config.app.hostname and config.ow.namespace are required')
|
|
99
140
|
})
|
|
100
141
|
|
|
101
|
-
test('
|
|
142
|
+
test('throws if hostname is invalid', async () => {
|
|
102
143
|
const config = {
|
|
144
|
+
s3: {
|
|
145
|
+
folder: 'somefolder'
|
|
146
|
+
},
|
|
103
147
|
ow: {
|
|
104
148
|
namespace: 'ns',
|
|
105
|
-
|
|
149
|
+
auth_handler: {
|
|
150
|
+
getAuthHeader: jest.fn().mockResolvedValue('Bearer token')
|
|
151
|
+
}
|
|
106
152
|
},
|
|
153
|
+
app: {
|
|
154
|
+
hasFrontend: true,
|
|
155
|
+
hostname: 'bad host!'
|
|
156
|
+
},
|
|
157
|
+
web: {
|
|
158
|
+
distProd: 'dist'
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
fs.existsSync.mockReturnValue(true)
|
|
162
|
+
fs.lstatSync.mockReturnValue({ isDirectory: () => true })
|
|
163
|
+
fs.readdirSync.mockReturnValue({ length: 1 })
|
|
164
|
+
|
|
165
|
+
await expect(deployWeb(config)).rejects.toThrow('config.app.hostname is invalid')
|
|
166
|
+
})
|
|
167
|
+
|
|
168
|
+
test('throws if namespace is invalid', async () => {
|
|
169
|
+
const config = {
|
|
107
170
|
s3: {
|
|
108
|
-
credsCacheFile: 'file',
|
|
109
|
-
tvmUrl: 'url',
|
|
110
171
|
folder: 'somefolder'
|
|
111
172
|
},
|
|
173
|
+
ow: {
|
|
174
|
+
namespace: 'bad/ns',
|
|
175
|
+
auth_handler: {
|
|
176
|
+
getAuthHeader: jest.fn().mockResolvedValue('Bearer token')
|
|
177
|
+
}
|
|
178
|
+
},
|
|
112
179
|
app: {
|
|
113
180
|
hasFrontend: true,
|
|
114
181
|
hostname: 'host'
|
|
@@ -120,23 +187,43 @@ describe('deploy-web', () => {
|
|
|
120
187
|
fs.existsSync.mockReturnValue(true)
|
|
121
188
|
fs.lstatSync.mockReturnValue({ isDirectory: () => true })
|
|
122
189
|
fs.readdirSync.mockReturnValue({ length: 1 })
|
|
123
|
-
|
|
124
|
-
expect(
|
|
125
|
-
expect(RemoteStorage).toHaveBeenCalledWith('fakecreds')
|
|
126
|
-
expect(mockRemoteStorageInstance.uploadDir).toHaveBeenCalledWith('dist', 'somefolder', config, null)
|
|
127
|
-
expect(mockRemoteStorageInstance.emptyFolder).not.toHaveBeenCalled()
|
|
128
|
-
expect(mockRemoteStorageInstance.folderExists).toHaveBeenCalledWith('somefolder/')
|
|
190
|
+
|
|
191
|
+
await expect(deployWeb(config)).rejects.toThrow('config.ow.namespace is invalid')
|
|
129
192
|
})
|
|
130
193
|
|
|
131
|
-
test('
|
|
194
|
+
test('throws if src dir is empty', async () => {
|
|
132
195
|
const config = {
|
|
196
|
+
s3: {
|
|
197
|
+
folder: 'somefolder'
|
|
198
|
+
},
|
|
133
199
|
ow: {
|
|
134
200
|
namespace: 'ns',
|
|
135
|
-
|
|
201
|
+
auth_handler: {
|
|
202
|
+
getAuthHeader: jest.fn().mockResolvedValue('Bearer token')
|
|
203
|
+
}
|
|
204
|
+
},
|
|
205
|
+
app: {
|
|
206
|
+
hasFrontend: true
|
|
207
|
+
},
|
|
208
|
+
web: {
|
|
209
|
+
distProd: 'dist'
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
fs.existsSync.mockReturnValue(true)
|
|
213
|
+
fs.lstatSync.mockReturnValue({ isDirectory: () => true })
|
|
214
|
+
fs.readdirSync.mockReturnValue({ length: 0 })
|
|
215
|
+
await expect(deployWeb(config)).rejects.toThrow('missing files in dist')
|
|
216
|
+
})
|
|
217
|
+
|
|
218
|
+
test('uploads files', async () => {
|
|
219
|
+
const config = {
|
|
220
|
+
ow: {
|
|
221
|
+
namespace: 'ns',
|
|
222
|
+
auth_handler: {
|
|
223
|
+
getAuthHeader: jest.fn().mockResolvedValue('Bearer token')
|
|
224
|
+
}
|
|
136
225
|
},
|
|
137
226
|
s3: {
|
|
138
|
-
credsCacheFile: 'file',
|
|
139
|
-
tvmUrl: 'url',
|
|
140
227
|
folder: 'somefolder'
|
|
141
228
|
},
|
|
142
229
|
app: {
|
|
@@ -150,25 +237,20 @@ describe('deploy-web', () => {
|
|
|
150
237
|
fs.existsSync.mockReturnValue(true)
|
|
151
238
|
fs.lstatSync.mockReturnValue({ isDirectory: () => true })
|
|
152
239
|
fs.readdirSync.mockReturnValue({ length: 1 })
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
mockRemoteStorageInstance.uploadDir.
|
|
156
|
-
await expect(deployWeb(config, mockLogger)).resolves.toEqual('https://ns.host/index.html')
|
|
157
|
-
expect(getS3Credentials).toHaveBeenCalledWith(config)
|
|
158
|
-
expect(RemoteStorage).toHaveBeenCalledWith('fakecreds')
|
|
159
|
-
expect(mockRemoteStorageInstance.uploadDir).toHaveBeenCalledWith('dist', 'somefolder', config, expect.any(Function))
|
|
160
|
-
expect(mockRemoteStorageInstance.emptyFolder).not.toHaveBeenCalled()
|
|
161
|
-
expect(mockRemoteStorageInstance.folderExists).toHaveBeenCalledWith('somefolder/')
|
|
240
|
+
await expect(deployWeb(config)).resolves.toEqual('https://ns.host/index.html')
|
|
241
|
+
expect(RemoteStorage).toHaveBeenCalledWith()
|
|
242
|
+
expect(mockRemoteStorageInstance.uploadDir).toHaveBeenCalledWith('Bearer token', 'dist', '', config, null)
|
|
162
243
|
})
|
|
163
244
|
|
|
164
|
-
test('
|
|
245
|
+
test('uploads files with log func', async () => {
|
|
165
246
|
const config = {
|
|
166
247
|
ow: {
|
|
167
248
|
namespace: 'ns',
|
|
168
|
-
|
|
249
|
+
auth_handler: {
|
|
250
|
+
getAuthHeader: jest.fn().mockResolvedValue('Bearer token')
|
|
251
|
+
}
|
|
169
252
|
},
|
|
170
253
|
s3: {
|
|
171
|
-
creds: 'somecreds',
|
|
172
254
|
folder: 'somefolder'
|
|
173
255
|
},
|
|
174
256
|
app: {
|
|
@@ -181,26 +263,23 @@ describe('deploy-web', () => {
|
|
|
181
263
|
}
|
|
182
264
|
fs.existsSync.mockReturnValue(true)
|
|
183
265
|
fs.lstatSync.mockReturnValue({ isDirectory: () => true })
|
|
184
|
-
const mockLogger = jest.fn()
|
|
185
266
|
fs.readdirSync.mockReturnValue({ length: 1 })
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
267
|
+
const mockLogger = jest.fn()
|
|
268
|
+
// for func coverage
|
|
269
|
+
mockRemoteStorageInstance.uploadDir.mockImplementation((a, b, c, d, func) => func('dist/somefile'))
|
|
189
270
|
await expect(deployWeb(config, mockLogger)).resolves.toEqual('https://ns.host/index.html')
|
|
190
|
-
expect(
|
|
191
|
-
expect(
|
|
192
|
-
expect(
|
|
193
|
-
expect(mockRemoteStorageInstance.folderExists).toHaveBeenCalledWith('somefolder/')
|
|
194
|
-
expect(mockRemoteStorageInstance.uploadDir).toHaveBeenCalledWith('dist', 'somefolder', config, expect.any(Function))
|
|
195
|
-
// empty dir!
|
|
196
|
-
expect(mockRemoteStorageInstance.emptyFolder).toHaveBeenCalledWith('somefolder/')
|
|
271
|
+
expect(RemoteStorage).toHaveBeenCalledWith()
|
|
272
|
+
expect(mockRemoteStorageInstance.uploadDir).toHaveBeenCalledWith('Bearer token', 'dist', '', config, expect.any(Function))
|
|
273
|
+
expect(mockLogger).toHaveBeenCalledWith('deploying somefile')
|
|
197
274
|
})
|
|
198
275
|
|
|
199
|
-
test('
|
|
276
|
+
test('clears existing deployment before uploading to avoid stale files', async () => {
|
|
200
277
|
const config = {
|
|
201
278
|
ow: {
|
|
202
279
|
namespace: 'ns',
|
|
203
|
-
|
|
280
|
+
auth_handler: {
|
|
281
|
+
getAuthHeader: jest.fn().mockResolvedValue('Bearer token')
|
|
282
|
+
}
|
|
204
283
|
},
|
|
205
284
|
s3: {
|
|
206
285
|
folder: 'somefolder'
|
|
@@ -216,27 +295,75 @@ describe('deploy-web', () => {
|
|
|
216
295
|
fs.existsSync.mockReturnValue(true)
|
|
217
296
|
fs.lstatSync.mockReturnValue({ isDirectory: () => true })
|
|
218
297
|
fs.readdirSync.mockReturnValue({ length: 1 })
|
|
219
|
-
|
|
220
298
|
mockRemoteStorageInstance.folderExists.mockResolvedValue(true)
|
|
221
299
|
|
|
222
|
-
await
|
|
223
|
-
|
|
224
|
-
expect(mockRemoteStorageInstance.folderExists).toHaveBeenCalledWith('
|
|
225
|
-
expect(mockRemoteStorageInstance.
|
|
226
|
-
|
|
227
|
-
expect(mockRemoteStorageInstance.emptyFolder).
|
|
300
|
+
await deployWeb(config)
|
|
301
|
+
|
|
302
|
+
expect(mockRemoteStorageInstance.folderExists).toHaveBeenCalledWith('Bearer token', '/', config)
|
|
303
|
+
expect(mockRemoteStorageInstance.emptyFolder).toHaveBeenCalledWith('Bearer token', '/', config)
|
|
304
|
+
expect(mockRemoteStorageInstance.uploadDir).toHaveBeenCalledWith('Bearer token', 'dist', '', config, null)
|
|
305
|
+
expect(mockRemoteStorageInstance.emptyFolder.mock.invocationCallOrder[0]).toBeLessThan(
|
|
306
|
+
mockRemoteStorageInstance.uploadDir.mock.invocationCallOrder[0]
|
|
307
|
+
)
|
|
228
308
|
})
|
|
229
309
|
|
|
230
|
-
test('
|
|
310
|
+
test('throws if config has no ow auth_handler', async () => {
|
|
311
|
+
const config = {
|
|
312
|
+
app: { hasFrontend: true },
|
|
313
|
+
web: { distProd: 'dist' }
|
|
314
|
+
}
|
|
315
|
+
await expect(deployWeb(config)).rejects.toThrow('cannot deploy web, Authorization is required')
|
|
316
|
+
})
|
|
317
|
+
|
|
318
|
+
describe('byo s3 credentials', () => {
|
|
319
|
+
const byoConfig = () => ({
|
|
320
|
+
ow: { namespace: 'ns' },
|
|
321
|
+
s3: {
|
|
322
|
+
folder: 'somefolder',
|
|
323
|
+
creds: { accessKeyId: 'fake', secretAccessKey: 'fake', params: { Bucket: 'bucket' } }
|
|
324
|
+
},
|
|
325
|
+
app: { hasFrontend: true, hostname: 'host' },
|
|
326
|
+
web: { distProd: 'dist' }
|
|
327
|
+
})
|
|
328
|
+
|
|
329
|
+
beforeEach(() => {
|
|
330
|
+
fs.existsSync.mockReturnValue(true)
|
|
331
|
+
fs.lstatSync.mockReturnValue({ isDirectory: () => true })
|
|
332
|
+
fs.readdirSync.mockReturnValue({ length: 1 })
|
|
333
|
+
})
|
|
334
|
+
|
|
335
|
+
test('uploads to the s3 folder without requiring an auth token', async () => {
|
|
336
|
+
const config = byoConfig()
|
|
337
|
+
mockRemoteStorageInstance.folderExists.mockResolvedValue(false)
|
|
338
|
+
|
|
339
|
+
await expect(deployWeb(config)).resolves.toEqual('https://ns.host/index.html')
|
|
340
|
+
|
|
341
|
+
expect(RemoteStorage).toHaveBeenCalledWith(config.s3.creds)
|
|
342
|
+
expect(mockRemoteStorageInstance.folderExists).toHaveBeenCalledWith(undefined, 'somefolder/', config)
|
|
343
|
+
expect(mockRemoteStorageInstance.emptyFolder).not.toHaveBeenCalled()
|
|
344
|
+
expect(mockRemoteStorageInstance.uploadDir).toHaveBeenCalledWith(undefined, 'dist', 'somefolder', config, null)
|
|
345
|
+
})
|
|
346
|
+
|
|
347
|
+
test('empties the existing s3 folder before uploading', async () => {
|
|
348
|
+
const config = byoConfig()
|
|
349
|
+
mockRemoteStorageInstance.folderExists.mockResolvedValue(true)
|
|
350
|
+
|
|
351
|
+
await deployWeb(config)
|
|
352
|
+
|
|
353
|
+
expect(mockRemoteStorageInstance.emptyFolder).toHaveBeenCalledWith(undefined, 'somefolder/', config)
|
|
354
|
+
})
|
|
355
|
+
})
|
|
356
|
+
|
|
357
|
+
test('logs overwrite warning when an existing deployment will be replaced', async () => {
|
|
231
358
|
const config = {
|
|
232
359
|
ow: {
|
|
233
360
|
namespace: 'ns',
|
|
234
|
-
|
|
361
|
+
auth_handler: {
|
|
362
|
+
getAuthHeader: jest.fn().mockResolvedValue('Bearer token')
|
|
363
|
+
}
|
|
235
364
|
},
|
|
236
365
|
s3: {
|
|
237
|
-
|
|
238
|
-
tvmUrl: 'url',
|
|
239
|
-
folder: 'nsfolder'
|
|
366
|
+
folder: 'somefolder'
|
|
240
367
|
},
|
|
241
368
|
app: {
|
|
242
369
|
hasFrontend: true,
|
|
@@ -246,23 +373,14 @@ describe('deploy-web', () => {
|
|
|
246
373
|
distProd: 'dist'
|
|
247
374
|
}
|
|
248
375
|
}
|
|
249
|
-
const emptyFolder = jest.fn()
|
|
250
|
-
const folderExists = jest.fn(() => true)
|
|
251
|
-
RemoteStorage.mockImplementation(() => {
|
|
252
|
-
return {
|
|
253
|
-
emptyFolder,
|
|
254
|
-
folderExists,
|
|
255
|
-
uploadDir: jest.fn()
|
|
256
|
-
}
|
|
257
|
-
})
|
|
258
376
|
fs.existsSync.mockReturnValue(true)
|
|
259
377
|
fs.lstatSync.mockReturnValue({ isDirectory: () => true })
|
|
260
|
-
const mockLogger = jest.fn()
|
|
261
378
|
fs.readdirSync.mockReturnValue({ length: 1 })
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
379
|
+
mockRemoteStorageInstance.folderExists.mockResolvedValue(true)
|
|
380
|
+
const mockLogger = jest.fn()
|
|
381
|
+
|
|
382
|
+
await deployWeb(config, mockLogger)
|
|
383
|
+
|
|
384
|
+
expect(mockLogger).toHaveBeenCalledWith('warning: an existing deployment will be overwritten')
|
|
267
385
|
})
|
|
268
386
|
})
|