Skip to content

Commit

Permalink
Fix order of checking if .clasp.json exists (google#189)
Browse files Browse the repository at this point in the history
Will write tests for this either in this PR, or in another, whichever you think is best.

Signed-off-by: campionfellin <[email protected]>

Fixes google#188 

- [x] `npm run test` succeeds.
- [x] `npm run lint` succeeds.
- [ ] Appropriate changes to README are included in PR.
  • Loading branch information
campionfellin authored and grant committed May 26, 2018
1 parent f74b710 commit 439772a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 13 deletions.
24 changes: 12 additions & 12 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,22 +192,22 @@ commander
.command('create [scriptTitle] [scriptParentId]')
.description('Create a script')
.action(async (title: string, parentId: string) => {
if (!title) {
await prompt([{
type : 'input',
name : 'title',
message : 'Give a script title:',
default: LOG.UNTITLED_SCRIPT_TITLE,
}]).then((answers: any) => {
title = answers.title;
}).catch((err: any) => {
console.log(err);
});
}
await checkIfOnline();
if (fs.existsSync(DOT.PROJECT.PATH)) {
logError(null, ERROR.FOLDER_EXISTS);
} else {
if (!title) {
await prompt([{
type : 'input',
name : 'title',
message : 'Give a script title:',
default: LOG.UNTITLED_SCRIPT_TITLE,
}]).then((answers: any) => {
title = answers.title;
}).catch((err: any) => {
console.log(err);
});
}
getAPICredentials(async () => {
spinner.setSpinnerTitle(LOG.CREATE_PROJECT_START(title)).start();
try {
Expand Down
9 changes: 8 additions & 1 deletion tests/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,16 @@ describe.skip('Test clasp create function', () => {
const result = spawnSync(
'clasp', ['create'], { encoding: 'utf8' },
);
expect(result.stdout).to.contain('give a script title:');
expect(result.stdout).to.contain('Give a script title:');
expect(result.status).to.equal(0);
});
it('should not prompt for project name', () => {
fs.writeFileSync('.clasp.json', '');
const result = spawnSync(
'clasp', ['create'], { encoding: 'utf8' },
);
expect(result.stderr).to.contain('Project file (.clasp.json) already exists.');
});
});

describe.skip('Test clasp create <title> function', () => {
Expand Down

0 comments on commit 439772a

Please sign in to comment.