-
Notifications
You must be signed in to change notification settings - Fork 437
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add clasp status tests and --json option #167
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,4 +8,5 @@ node_modules/ | |
.npm | ||
.env | ||
.nyc_output | ||
*.lock | ||
*.lock | ||
/tmp |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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', () => { | ||
|
@@ -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'); | ||
|
@@ -106,6 +107,47 @@ 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: false }).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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. After each test, maybe add There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Perfect, thanks for changing that. |
||
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( | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm curious why we need a
/tmp
directory for testing. We've been usingfs.writeFileSync('.clasprc.json', ' ');
if we need files for testing. Should we be changing that in the other tests as well?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe the other tests using
fs.writeFileSync
directly actually just end up dumping files into the /clasp directory. It'd probably be better to have all the test related file writing in tmp/ so we can clean up nicely afterwards.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍