Skip to content

Commit 3572f02

Browse files
committed
Merge branch 'develop', prepare 0.19.1
2 parents 39261e4 + 748502c commit 3572f02

File tree

2 files changed

+97
-40
lines changed

2 files changed

+97
-40
lines changed

src/commands/deploy.js

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,23 @@ const streamToResponse = ({tarStream, remoteUrl, options}) =>
2727
stream.on('data', str => (result += str.toString()));
2828
// listen for read stream end
2929
stream.on('end', () => {
30-
const res = JSON.parse(result);
31-
// if stream had error - reject
32-
if (error) {
30+
try {
31+
const res = JSON.parse(result);
32+
// if stream had error - reject
33+
if (error) {
34+
// add response to allow access to body
35+
error.response = res;
36+
reject(error);
37+
return;
38+
}
39+
// otherwise resolve
40+
resolve(res);
41+
} catch (parseErr) {
42+
// catch parsing error
3343
// add response to allow access to body
34-
error.response = res;
35-
reject(error);
36-
return;
44+
parseErr.response = {result: {error: result, log: ['No log available']}};
45+
reject(parseErr);
3746
}
38-
// otherwise resolve
39-
resolve(res);
4047
});
4148
// listen for stream errors
4249
stream.on('error', e => (error = e));

test/deploy.js

Lines changed: 82 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,16 @@ module.exports = () => {
4545
const consoleSpy = sinon.spy(console, 'log');
4646

4747
// handle correct request
48-
const deployServer = nock('http://localhost:8080').post('/deploy').reply((uri, requestBody, cb) => {
49-
const excgf = fs.readFileSync(path.join(testFolder, 'exoframe.json'));
50-
const index = fs.readFileSync(path.join(testFolder, 'index.html'));
51-
t.ok(requestBody.includes(excgf), 'Should send correct config');
52-
t.ok(requestBody.includes(index), 'Should send correct index file');
48+
const deployServer = nock('http://localhost:8080')
49+
.post('/deploy')
50+
.reply((uri, requestBody, cb) => {
51+
const excgf = fs.readFileSync(path.join(testFolder, 'exoframe.json'));
52+
const index = fs.readFileSync(path.join(testFolder, 'index.html'));
53+
t.ok(requestBody.includes(excgf), 'Should send correct config');
54+
t.ok(requestBody.includes(index), 'Should send correct index file');
5355

54-
cb(null, [200, {status: 'success', deployments}]);
55-
});
56+
cb(null, [200, {status: 'success', deployments}]);
57+
});
5658

5759
// execute login
5860
deploy({_: [folderPath]}).then(() => {
@@ -83,9 +85,11 @@ module.exports = () => {
8385
const consoleSpy = sinon.spy(console, 'log');
8486

8587
// handle correct request
86-
const deployServer = nock('http://localhost:8080').post('/deploy').reply((uri, requestBody, cb) => {
87-
cb(null, [200, {status: 'success', deployments}]);
88-
});
88+
const deployServer = nock('http://localhost:8080')
89+
.post('/deploy')
90+
.reply((uri, requestBody, cb) => {
91+
cb(null, [200, {status: 'success', deployments}]);
92+
});
8993

9094
// execute login
9195
deploy().then(() => {
@@ -118,9 +122,11 @@ module.exports = () => {
118122
const originalConfig = Object.assign({}, userConfig);
119123

120124
// handle correct request
121-
const deployServer = nock('http://localhost:8080').post('/deploy').reply((uri, requestBody, cb) => {
122-
cb(null, [200, {status: 'success', deployments}]);
123-
});
125+
const deployServer = nock('http://localhost:8080')
126+
.post('/deploy')
127+
.reply((uri, requestBody, cb) => {
128+
cb(null, [200, {status: 'success', deployments}]);
129+
});
124130

125131
// remove auth from config
126132
updateConfig({endpoint: 'http://localhost:8080'});
@@ -157,9 +163,11 @@ module.exports = () => {
157163
const consoleSpy = sinon.spy(console, 'log');
158164

159165
// handle correct request
160-
const updateServer = nock('http://localhost:8080').post('/update').reply((uri, requestBody, cb) => {
161-
cb(null, [200, {status: 'success', deployments}]);
162-
});
166+
const updateServer = nock('http://localhost:8080')
167+
.post('/update')
168+
.reply((uri, requestBody, cb) => {
169+
cb(null, [200, {status: 'success', deployments}]);
170+
});
163171

164172
// execute login
165173
deploy({update: true}).then(() => {
@@ -190,9 +198,11 @@ module.exports = () => {
190198
const consoleSpy = sinon.spy(console, 'log');
191199

192200
// handle correct request
193-
const deployServer = nock('http://localhost:8080').post('/deploy').reply((uri, requestBody, cb) => {
194-
cb(null, [200, {status: 'success', deployments}]);
195-
});
201+
const deployServer = nock('http://localhost:8080')
202+
.post('/deploy')
203+
.reply((uri, requestBody, cb) => {
204+
cb(null, [200, {status: 'success', deployments}]);
205+
});
196206

197207
// execute
198208
deploy({open: true}).then(() => {
@@ -225,19 +235,21 @@ module.exports = () => {
225235
const consoleSpy = sinon.spy(console, 'log');
226236

227237
// handle correct request
228-
const deployServer = nock('http://localhost:8080').post('/deploy').reply((uri, requestBody, cb) => {
229-
cb(null, [
230-
400,
231-
{
232-
status: 'error',
233-
result: {
234-
error: 'Build failed! See build log for details.',
235-
log: ['Error log', 'here'],
236-
image: 'test:latest',
238+
const deployServer = nock('http://localhost:8080')
239+
.post('/deploy')
240+
.reply((uri, requestBody, cb) => {
241+
cb(null, [
242+
400,
243+
{
244+
status: 'error',
245+
result: {
246+
error: 'Build failed! See build log for details.',
247+
log: ['Error log', 'here'],
248+
image: 'test:latest',
249+
},
237250
},
238-
},
239-
]);
240-
});
251+
]);
252+
});
241253

242254
// execute
243255
deploy().then(() => {
@@ -264,6 +276,42 @@ module.exports = () => {
264276
});
265277
});
266278

279+
// test
280+
tap.test('Should display error on malformed JSON', t => {
281+
// spy on console
282+
const consoleSpy = sinon.spy(console, 'log');
283+
284+
// handle correct request
285+
const deployServer = nock('http://localhost:8080')
286+
.post('/deploy')
287+
.reply((uri, requestBody, cb) => {
288+
cb(null, [200, 'Bad Gateway']);
289+
});
290+
291+
// execute
292+
deploy().then(() => {
293+
// make sure log in was successful
294+
// check that server was called
295+
t.ok(deployServer.isDone());
296+
// first check console output
297+
t.deepEqual(
298+
consoleSpy.args,
299+
[
300+
['Deploying current project to endpoint:', 'http://localhost:8080'],
301+
['Error deploying project:', 'Bad Gateway'],
302+
['Build log:\n'],
303+
['No log available'],
304+
],
305+
'Correct log output'
306+
);
307+
// restore console
308+
console.log.restore();
309+
// tear down nock
310+
deployServer.done();
311+
t.end();
312+
});
313+
});
314+
267315
// test
268316
tap.test('Should not deploy with broken config', t => {
269317
// spy on console
@@ -317,7 +365,9 @@ module.exports = () => {
317365
// copy original config for restoration
318366
const originalConfig = Object.assign({}, userConfig);
319367
// handle correct request
320-
const deployServer = nock('http://localhost:8080').post('/deploy').reply(401, {error: 'Deauth test'});
368+
const deployServer = nock('http://localhost:8080')
369+
.post('/deploy')
370+
.reply(401, {error: 'Deauth test'});
321371
// spy on console
322372
const consoleSpy = sinon.spy(console, 'log');
323373
// execute login

0 commit comments

Comments
 (0)