-
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 more tests #158
Add more tests #158
Conversation
Also, noted that saveProjectId should be async or return a promise Signed-off-by: campionfellin <campionfellin@gmail.com>
Signed-off-by: campionfellin <campionfellin@gmail.com>
tests/test.ts
Outdated
it('should save the scriptId correctly', () => { | ||
spawnSync('rm', ['.clasp.json']); | ||
saveProjectId('12345'); | ||
setTimeout(() => { |
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.
This is here because otherwise, it won't have saved the projectId before running the test.
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.
Don't set a timeout.
Change the definition of saveProjectId
.
var isSaved = async saveProjectId('12345'); // async is only used for tests. In src, we don't to read back the value
Source (with async
):
/**
* Saves the script ID in the project dotfile.
* @param {string} scriptId The script ID
*/
export async function saveProjectId(scriptId: string): void {
return DOTFILE.PROJECT().write({ scriptId }); // Save the script id
}
saveProjectId
uses dotf
.write()
, which returns a Promise
.
Not sure if that's the exact syntax, but something like that would be better than a 3000ms read file timeout.
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.
Yeah I was just putting that there so the tests didn't fail. I'll go ahead and make another commit to this branch with an update of saveProjectId
tests/test.ts
Outdated
describe('Test saveProjectId function from utils', () => { | ||
it('should save the scriptId correctly', () => { | ||
spawnSync('rm', ['.clasp.json']); | ||
saveProjectId('12345'); |
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.
Should this be renamed to saveScriptId
?
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 so according to the API reference.
The API is not very clear what the difference between a scriptId and a projectId. We could probably just say scriptId.
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'll change it from saveProjectId
to saveScriptId
. In my opinion, we should make a function at sometime that would support clasp logs
by allowing users to add their GCP project ID to the .clasp.json
file without having to manually edit it.
Pull Request Test Coverage Report for Build 146
💛 - Coveralls |
Pull Request Test Coverage Report for Build 144
💛 - Coveralls |
1 similar comment
Pull Request Test Coverage Report for Build 144
💛 - Coveralls |
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.
LGTM once setTimeout is removed. Thanks!
tests/test.ts
Outdated
describe('Test saveProjectId function from utils', () => { | ||
it('should save the scriptId correctly', () => { | ||
spawnSync('rm', ['.clasp.json']); | ||
saveProjectId('12345'); |
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 so according to the API reference.
The API is not very clear what the difference between a scriptId and a projectId. We could probably just say scriptId.
it('should return the lowercase file type correctly', () => { | ||
expect(getFileType('SERVER_JS')).to.equal('js'); | ||
expect(getFileType('GS')).to.equal('gs'); | ||
expect(getFileType('JS')).to.equal('js'); | ||
}); | ||
}); | ||
|
||
describe('Test getAPIFileType function from utils', () => { | ||
it('should return the uppercase file type correctly', () => { | ||
expect(getAPIFileType('file.GS')).to.equal('SERVER_JS'); |
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.
Add a few more cases: file.js
, file.jsx
, file.js.html
.
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.
👍
tests/test.ts
Outdated
it('should save the scriptId correctly', () => { | ||
spawnSync('rm', ['.clasp.json']); | ||
saveProjectId('12345'); | ||
setTimeout(() => { |
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.
Don't set a timeout.
Change the definition of saveProjectId
.
var isSaved = async saveProjectId('12345'); // async is only used for tests. In src, we don't to read back the value
Source (with async
):
/**
* Saves the script ID in the project dotfile.
* @param {string} scriptId The script ID
*/
export async function saveProjectId(scriptId: string): void {
return DOTFILE.PROJECT().write({ scriptId }); // Save the script id
}
saveProjectId
uses dotf
.write()
, which returns a Promise
.
Not sure if that's the exact syntax, but something like that would be better than a 3000ms read file timeout.
tests/test.ts
Outdated
}); | ||
}); | ||
|
||
// NOTE: we should make saveProjectId async because dotf.write is async |
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.
Remove this note.
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.
👍
Make saveProjectId async function Test it (without using timeout) Signed-off-by: campionfellin <campionfellin@gmail.com>
All comments are covered except converting |
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.
Stellar job!
A few notes:
Looks like we should make saveProjectId return a promise so we can use
await
syntax.npm run test
succeeds.npm run lint
succeeds.