Skip to content

Commit

Permalink
Add clasp status tests and --json option
Browse files Browse the repository at this point in the history
  • Loading branch information
Anthony Lai committed May 15, 2018
1 parent 0080f67 commit 60c304d
Show file tree
Hide file tree
Showing 5 changed files with 119 additions and 14 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ node_modules/
.npm
.env
.nyc_output
*.lock
*.lock
/tmp
22 changes: 12 additions & 10 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -442,23 +442,25 @@ commander
commander
.command('status')
.description('Lists files that will be pushed by clasp')
.action(async () => {
.option('--json', "Show status in JSON form")
.action(async (cmd: { json: boolean }) => {
await checkIfOnline();
getProjectSettings().then(({ scriptId, rootDir }: ProjectSettings) => {
if (!scriptId) return;
getProjectFiles(rootDir, (err, projectFiles) => {
if(err) return console.log(err);
else if (projectFiles) {
const [nonIgnoredFilePaths, ignoredFilePaths] = projectFiles;
console.log(LOG.STATUS_PUSH);
nonIgnoredFilePaths.map((filePath: string) => {
console.log(`└─ ${filePath}`);
});
if (ignoredFilePaths.length) {
const status = {
filesToPush: projectFiles[0],
untrackedFiles: projectFiles[1]
}
if (cmd.json) {
console.log(JSON.stringify(status));
} else {
console.log(LOG.STATUS_PUSH);
status.filesToPush.forEach((file) => console.log(`└─ ${file}`));
console.log(LOG.STATUS_IGNORE);
ignoredFilePaths.map((filePath: string) => {
console.log(`└─ ${filePath}`);
});
status.untrackedFiles.forEach((file) => console.log(`└─ ${file}`));
}
}
});
Expand Down
55 changes: 55 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,21 +57,27 @@
},
"devDependencies": {
"@types/anymatch": "^1.3.0",
"@types/chai": "^4.1.3",
"@types/cli-spinner": "^0.2.0",
"@types/commander": "^2.12.2",
"@types/connect": "^3.4.31",
"@types/del": "^3.0.0",
"@types/events": "^1.1.0",
"@types/fs-extra": "^5.0.2",
"@types/glob": "^5.0.35",
"@types/mkdirp": "^0.5.2",
"@types/mocha": "^5.2.0",
"@types/node": "^9.4.0",
"@types/open": "^0.0.29",
"@types/pluralize": "^0.0.28",
"@types/recursive-readdir": "^2.2.0",
"@types/tmp": "0.0.33",
"chai": "^4.1.2",
"coveralls": "^3.0.0",
"fs-extra": "^6.0.1",
"mocha": "^5.1.0",
"nyc": "^11.6.0",
"tmp": "0.0.33",
"tslint": "^5.9.1",
"typescript": "^2.8.1"
}
Expand Down
47 changes: 44 additions & 3 deletions tests/test.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { describe, it } from 'mocha';
import { expect } from 'chai';
import * as fs from 'fs';
import * as fs from 'fs-extra';
import * as os from 'os';

const { spawnSync } = require('child_process');
import { getScriptURL, getFileType, getAPIFileType,
saveProjectId } from './../src/utils.js';
const path = require('path');
import * as path from 'path';
import * as tmp from 'tmp';

describe('Test help for each function', () => {
it('should output help for run command', () => {
Expand All @@ -18,7 +19,7 @@ describe('Test help for each function', () => {
});
it('should output help for logs command', () => {
const result = spawnSync(
'clasp', ['logs', '--help'], { encoding : 'utf8', detached: true },
'clasp', ['logs', '--help'], { encoding : 'utf8' },
);
expect(result.status).to.equal(0);
expect(result.stdout).to.include('Shows the StackDriver logs');
Expand Down Expand Up @@ -106,6 +107,46 @@ describe.skip('Test clasp push function', () => {
});
});

describe.skip('Test clasp status function', () => {
function setupTmpDirectory(filepathsAndContents: Array<{ file: string, data: string }>) {
fs.ensureDirSync('tmp');
const tmpdir = tmp.dirSync({ unsafeCleanup: true, dir: 'tmp/', keep: true }).name;
filepathsAndContents.forEach(({ file, data }) => {
fs.outputFileSync(path.join(tmpdir, file), data);
});
return tmpdir;
}
it("should respect globs and negation rules", () => {
const tmpdir = setupTmpDirectory([
{ file: '.claspignore', data: '**/**\n!build/main.js\n!appsscript.json' },
{ file: 'build/main.js', data: ' ' },
{ file: 'appsscript.json', data: ' ' },
{ file: 'shouldBeIgnored', data: ' ' },
{ file: 'should/alsoBeIgnored', data: ' ' }
]);
spawnSync('clasp', ['create', '[TEST] clasp status'], { encoding: 'utf8', cwd: tmpdir });
const result = spawnSync('clasp', ['status', '--json'], { encoding: 'utf8', cwd: tmpdir });
expect(result.status).to.equal(0);
const resultJson = JSON.parse(result.stdout);
expect(resultJson.untrackedFiles).to.have.members(['shouldBeIgnored', 'should/alsoBeIgnored']);
expect(resultJson.filesToPush).to.have.members(['build/main.js', 'appsscript.json']);
});
// https://github.com/google/clasp/issues/67 - This test currently fails
it.skip('should ignore dotfiles if the parent folder is ignored', () => {
const tmpdir = setupTmpDirectory([
{ file: '.claspignore', data: '**/node_modules/**\n**/**\n!appsscript.json' },
{ file: 'appsscript.json', data: ' ' },
{ file: 'node_modules/fsevents/build/Release/.deps/Release/.node.d', data: ' ' },
]);
spawnSync('clasp', ['create', '[TEST] clasp status'], { encoding: 'utf8', cwd: tmpdir });
const result = spawnSync('clasp', ['status', '--json'], { encoding: 'utf8', cwd: tmpdir });
expect(result.status).to.equal(0);
const resultJson = JSON.parse(result.stdout);
expect(resultJson.untrackedFiles).to.have.members(['node_modules/fsevents/build/Release/.deps/Release/.node.d']);
expect(resultJson.filesToPush).to.have.members(['appsscript.json']);
});
});

describe.skip('Test clasp open function', () => {
it('should open a project correctly', () => {
const result = spawnSync(
Expand Down

0 comments on commit 60c304d

Please sign in to comment.