Skip to content
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

Merged
merged 3 commits into from
May 5, 2018
Merged

Add more tests #158

merged 3 commits into from
May 5, 2018

Conversation

campionfellin
Copy link
Collaborator

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.
  • Appropriate changes to README are included in PR.

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(() => {
Copy link
Collaborator Author

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.

Copy link
Contributor

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.

Copy link
Collaborator Author

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');
Copy link
Collaborator Author

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?

Copy link
Contributor

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.

Copy link
Collaborator Author

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.

@coveralls
Copy link

coveralls commented May 2, 2018

Pull Request Test Coverage Report for Build 146

  • 0 of 0 (NaN%) changed or added relevant lines in 0 files are covered.
  • 73 unchanged lines in 2 files lost coverage.
  • Overall coverage increased (+1.7%) to 13.968%

Files with Coverage Reduction New Missed Lines %
src/utils.js 3 18.64%
tests/test.js 70 32.88%
Totals Coverage Status
Change from base Build 141: 1.7%
Covered Lines: 157
Relevant Lines: 855

💛 - Coveralls

@coveralls
Copy link

Pull Request Test Coverage Report for Build 144

  • 0 of 0 (NaN%) changed or added relevant lines in 0 files are covered.
  • 22 unchanged lines in 1 file lost coverage.
  • Overall coverage increased (+2.5%) to 14.821%

Files with Coverage Reduction New Missed Lines %
tests/test.js 22 52.46%
Totals Coverage Status
Change from base Build 141: 2.5%
Covered Lines: 157
Relevant Lines: 817

💛 - Coveralls

1 similar comment
@coveralls
Copy link

Pull Request Test Coverage Report for Build 144

  • 0 of 0 (NaN%) changed or added relevant lines in 0 files are covered.
  • 22 unchanged lines in 1 file lost coverage.
  • Overall coverage increased (+2.5%) to 14.821%

Files with Coverage Reduction New Missed Lines %
tests/test.js 22 52.46%
Totals Coverage Status
Change from base Build 141: 2.5%
Covered Lines: 157
Relevant Lines: 817

💛 - Coveralls

Copy link
Contributor

@grant grant left a 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');
Copy link
Contributor

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');
Copy link
Contributor

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.

Copy link
Collaborator Author

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(() => {
Copy link
Contributor

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this note.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@campionfellin campionfellin self-assigned this May 5, 2018
Make saveProjectId async function
Test it (without using timeout)

Signed-off-by: campionfellin <campionfellin@gmail.com>
@campionfellin
Copy link
Collaborator Author

All comments are covered except converting saveProjectId to saveScriptId because that needs to be changed in many places. Should be a separate PR.

Copy link
Contributor

@grant grant left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stellar job!

@grant grant merged commit 39e0690 into google:master May 5, 2018
@campionfellin campionfellin deleted the more-tests branch May 25, 2018 22:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants