From 439772ad83bd061cfe14a7f4d6b5289345aab20f Mon Sep 17 00:00:00 2001 From: Campion Fellin Date: Fri, 25 May 2018 22:52:08 -0700 Subject: [PATCH] Fix order of checking if .clasp.json exists (#189) Will write tests for this either in this PR, or in another, whichever you think is best. Signed-off-by: campionfellin Fixes #188 - [x] `npm run test` succeeds. - [x] `npm run lint` succeeds. - [ ] Appropriate changes to README are included in PR. --- index.ts | 24 ++++++++++++------------ tests/test.ts | 9 ++++++++- 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/index.ts b/index.ts index 7355107f..649d357b 100755 --- a/index.ts +++ b/index.ts @@ -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 { diff --git a/tests/test.ts b/tests/test.ts index 2ecabb4e..8de3ceec 100644 --- a/tests/test.ts +++ b/tests/test.ts @@ -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 function', () => {