Skip to content

Commit b37e93b

Browse files
committed
Merge branch 'develop', prepare 0.19.2
2 parents 6713ca6 + 8140441 commit b37e93b

File tree

2 files changed

+122
-8
lines changed

2 files changed

+122
-8
lines changed

src/commands/deploy.js

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,14 @@ exports.builder = {
6464
alias: 'o',
6565
description: 'Open deployed project in browser after upload',
6666
},
67+
verbose: {
68+
alias: 'v',
69+
description: 'Verbose mode; will output more information',
70+
},
6771
};
6872
exports.handler = async (args = {}) => {
6973
const deployToken = args.token;
74+
const {verbose} = args;
7075

7176
// exit if not logged in and no token provided
7277
if (!deployToken && !isLoggedIn()) {
@@ -100,6 +105,8 @@ exports.handler = async (args = {}) => {
100105
} catch (e) {
101106
const defaultConfig = JSON.stringify({name: folderName});
102107
fs.writeFileSync(configPath, defaultConfig, 'utf-8');
108+
// if in verbose mode - log config creation
109+
verbose && console.log('Create new default config:', defaultConfig);
103110
}
104111

105112
// show loader
@@ -119,6 +126,8 @@ exports.handler = async (args = {}) => {
119126
const tarStream = tar.pack(workdir, {
120127
ignore: name => ig.ignores(name),
121128
});
129+
// if in verbose mode - log ignores
130+
verbose && console.log('\nIgnoring following paths:', ignores);
122131

123132
let token = userConfig.token;
124133
if (deployToken) {
@@ -133,7 +142,10 @@ exports.handler = async (args = {}) => {
133142

134143
// pipe stream to remote
135144
try {
136-
const res = await streamToResponse({tarStream, remoteUrl, options});
145+
const res = await streamToResponse({tarStream, remoteUrl, options, verbose});
146+
// if in verbose mode - log response
147+
verbose && console.log('\nGot response from server:', res);
148+
// check deployments
137149
if (!res.deployments || !res.deployments.length) {
138150
throw new Error('Something went wrong!');
139151
}
@@ -168,13 +180,21 @@ exports.handler = async (args = {}) => {
168180
return;
169181
}
170182

171-
const reason = e.response.result ? e.response.result.error : e.toString();
172-
console.log(chalk.red('Error deploying project:'), reason);
183+
const response = e.response || {};
184+
const reason = response.result ? response.result.error : e.toString();
185+
console.log(chalk.red('Error deploying project:'), reason || 'Unknown reason');
173186
console.log('Build log:\n');
174-
e.response.result.log
175-
.filter(l => l !== undefined)
176-
.map(l => l.trim())
177-
.filter(l => l && l.length > 0)
178-
.forEach(line => console.log(line));
187+
response.result
188+
? (response.result.log || ['No log available'])
189+
.filter(l => l !== undefined)
190+
.map(l => l.trim())
191+
.filter(l => l && l.length > 0)
192+
.forEach(line => console.log(line))
193+
: console.log('No log available');
194+
195+
// if in verbose mode - log original error and response
196+
verbose && console.log('');
197+
verbose && console.log('Original error:', e);
198+
verbose && console.log('Original response:', e.response);
179199
}
180200
};

test/deploy.js

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,100 @@ module.exports = () => {
312312
});
313313
});
314314

315+
// test
316+
tap.test('Should display verbose output', t => {
317+
// spy on console
318+
const consoleSpy = sinon.spy(console, 'log');
319+
320+
// handle correct request
321+
const deployServer = nock('http://localhost:8080')
322+
.post('/deploy')
323+
.reply((uri, requestBody, cb) => {
324+
cb(null, [200, 'Bad Gateway']);
325+
});
326+
327+
// execute
328+
deploy({verbose: true}).then(() => {
329+
// make sure log in was successful
330+
// check that server was called
331+
t.ok(deployServer.isDone());
332+
// first check console output
333+
t.deepEqual(
334+
consoleSpy.args,
335+
[
336+
['Deploying current project to endpoint:', 'http://localhost:8080'],
337+
['\nIgnoring following paths:', ['.git', 'node_modules']],
338+
['Error deploying project:', 'Bad Gateway'],
339+
['Build log:\n'],
340+
['No log available'],
341+
[''],
342+
[
343+
'Original error:',
344+
{
345+
response: {
346+
result: {
347+
error: 'Bad Gateway',
348+
log: ['No log available'],
349+
},
350+
},
351+
},
352+
],
353+
[
354+
'Original response:',
355+
{
356+
result: {
357+
error: 'Bad Gateway',
358+
log: ['No log available'],
359+
},
360+
},
361+
],
362+
],
363+
'Correct log output'
364+
);
365+
// restore console
366+
console.log.restore();
367+
// tear down nock
368+
deployServer.done();
369+
t.end();
370+
});
371+
});
372+
373+
// test
374+
tap.test('Should display error on zero deployments', t => {
375+
// spy on console
376+
const consoleSpy = sinon.spy(console, 'log');
377+
378+
// handle correct request
379+
const deployServer = nock('http://localhost:8080')
380+
.post('/deploy')
381+
.reply((uri, requestBody, cb) => {
382+
cb(null, [200, {}]);
383+
});
384+
385+
// execute
386+
deploy().then(() => {
387+
// make sure log in was successful
388+
// check that server was called
389+
t.ok(deployServer.isDone());
390+
// first check console output
391+
t.deepEqual(
392+
consoleSpy.args,
393+
[
394+
['Deploying current project to endpoint:', 'http://localhost:8080'],
395+
['Error deploying project:', 'Error: Something went wrong!'],
396+
['Build log:\n'],
397+
['No log available'],
398+
],
399+
'Correct log output'
400+
);
401+
// restore console
402+
console.log.restore();
403+
// tear down nock
404+
deployServer.done();
405+
t.end();
406+
});
407+
});
408+
315409
// test
316410
tap.test('Should not deploy with broken config', t => {
317411
// spy on console

0 commit comments

Comments
 (0)