Skip to content

Commit

Permalink
Merge pull request google#195 from campionfellin/clone-test
Browse files Browse the repository at this point in the history
Clasp clone now exits with error if .clasp.json already exists
  • Loading branch information
campionfellin authored May 30, 2018
2 parents 4bc1e32 + d8efffb commit 2cd1225
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
6 changes: 5 additions & 1 deletion index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,10 @@ commander
.command('clone [scriptId] [versionNumber]')
.description('Clone a project')
.action(async (scriptId: string, versionNumber?: number) => {
await checkIfOnline();
if (fs.existsSync(DOT.PROJECT.PATH)) {
logError(null, ERROR.FOLDER_EXISTS);
} else {
if (!scriptId) {
getAPICredentials(async () => {
const drive = google.drive({version: 'v3', auth: oauth2Client}) as Drive;
Expand Down Expand Up @@ -325,11 +329,11 @@ commander
}
});
} else {
await checkIfOnline();
spinner.setSpinnerTitle(LOG.CLONING);
saveProjectId(scriptId);
fetchProject(scriptId, '', versionNumber);
}
}
});

/**
Expand Down
1 change: 1 addition & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ export const logError = (err: any, description = '') => {
}
if (description) console.error(description);
}
process.exit(1);
};

/**
Expand Down
9 changes: 9 additions & 0 deletions tests/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ describe.skip('Test clasp create <title> function', () => {
describe.skip('Test clasp clone <scriptId> function', () => {
it('should clone an existing project correctly', () => {
const settings = JSON.parse(fs.readFileSync('.clasp.json', 'utf8'));
fs.removeSync('.clasp.json');
const result = spawnSync(
'clasp', ['clone', settings.scriptId], { encoding: 'utf8' },
);
Expand Down Expand Up @@ -173,6 +174,14 @@ describe.skip('Test clasp clone function', () => {
expect(result.stdout).to.contain('Clone which script?');
expect(result.status).to.equal(0);
});
it('should give an error if .clasp.json already exists', () => {
fs.writeFileSync('.clasp.json', '');
const result = spawnSync(
'clasp', ['clone'], { encoding: 'utf8' },
);
expect(result.stderr).to.contain('Project file (.clasp.json) already exists.');
expect(result.status).to.equal(1);
});
});

describe.skip('Test clasp deployments function', () => {
Expand Down

0 comments on commit 2cd1225

Please sign in to comment.