Skip to content

Commit 1c001c6

Browse files
committed
Validate project name in config before deployment, closes #90
1 parent f878f45 commit 1c001c6

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-2
lines changed

src/commands/deploy.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,9 +136,13 @@ exports.handler = async (args = {}) => {
136136
spinner = ora('Deploying project to server...').start();
137137
}
138138

139-
// syntax-check config
139+
// syntax-check & validate config
140140
try {
141-
JSON.parse(fs.readFileSync(configPath));
141+
const config = JSON.parse(fs.readFileSync(configPath));
142+
// validate project name
143+
if (!config.name || !config.name.length) {
144+
throw new Error('Project should have a valid name in config!');
145+
}
142146
} catch (e) {
143147
spinner && spinner.fail('Your exoframe.json is not valid');
144148
console.log(chalk.red('Please, check your config and try again:'), e.toString());

test/deploy.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,33 @@ module.exports = () => {
392392
});
393393
});
394394

395+
// test
396+
tap.test('Should not deploy with config without project name', t => {
397+
// spy on console
398+
const consoleSpy = sinon.spy(console, 'log');
399+
400+
// corrupt config with string
401+
const cfg = JSON.parse(fs.readFileSync(path.join(__dirname, '..', 'exoframe.json')));
402+
cfg.name = '';
403+
fs.writeFileSync(path.join(__dirname, '..', 'exoframe.json'), JSON.stringify(cfg));
404+
405+
// execute deploy
406+
deploy().then(() => {
407+
// check console output
408+
t.deepEqual(
409+
consoleSpy.args,
410+
[
411+
['Deploying current project to endpoint:', 'http://localhost:8080'],
412+
['Please, check your config and try again:', 'Error: Project should have a valid name in config!'],
413+
],
414+
'Correct log output'
415+
);
416+
// restore console
417+
console.log.restore();
418+
t.end();
419+
});
420+
});
421+
395422
// test
396423
tap.test('Should not deploy with broken config', t => {
397424
// spy on console

0 commit comments

Comments
 (0)