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

TypeError when GitHub URL is not defined #52 #53

Merged
merged 9 commits into from
Aug 5, 2021

Conversation

zubinbhasin
Copy link
Contributor

#52

@helio-frota
Copy link
Member

@zubinbhasin thanks for the PR.
Can you please write a unit test for when Github URL is not found?
You can take a look here for similar examples https://github.com/nodeshift/npcheck/blob/main/test/plugins/archive.test.js#L80

const { fetchGithub } = require('../lib/fetch');

const archivePlugin = async (pkg, _, options) => {
if (!pkg.repository.url) {
warning(output.get());
return createWarning(`No Github url found for the ${pkg.name} module`);
Copy link
Member

@aalykiot aalykiot Aug 4, 2021

Choose a reason for hiding this comment

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

Suggested change
return createWarning(`No Github url found for the ${pkg.name} module`);
return createWarning(`The module "${pkg.name}" does not specify its GitHub repository.`);

@zubinbhasin
Copy link
Contributor Author

zubinbhasin commented Aug 4, 2021

@zubinbhasin thanks for the PR.
Can you please write a unit test for when Github URL is not found?
You can take a look here for similar examples https://github.com/nodeshift/npcheck/blob/main/test/plugins/archive.test.js#L80

I have added the unit test and made the changes according to the suggestions by @aalykiot . Please have a look now.

'Checking if github repository is archived'
).withPadding(65);

if (!pkg.repository.url) {
Copy link
Member

Choose a reason for hiding this comment

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

If the repository field is also undefined then the if statement will throw a TypeError.

Suggested change
if (!pkg.repository.url) {
if (!pkg?.repository?.url) {


it('should log warning message when module does not specify its GitHub repository', async () => {
// mocking http request to GitHub
network.fetchGithub.mockImplementation(() => {
Copy link
Member

@aalykiot aalykiot Aug 4, 2021

Choose a reason for hiding this comment

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

You don't have to mock the network request here since you'll never reach the network call anyway.

@aalykiot
Copy link
Member

aalykiot commented Aug 4, 2021

@zubinbhasin I would suggest writing one test with const pkg = {}; and another with const pkg = { repository: {} }; so we can cover all the edge cases 🙂

aalykiot and others added 3 commits August 4, 2021 19:25
Use the Coveralls GitHub action instead of the module to allow
coverage runs on pull requests from forks.

Fixes: nodeshift#54
@zubinbhasin
Copy link
Contributor Author

@zubinbhasin I would suggest writing one test with const pkg = {}; and another with const pkg = { repository: {} }; so we can cover all the edge cases 🙂

@aalykiot I've covered both of these cases, also removed the mock calls and added optional chaining snippet as mentioned above.

@aalykiot aalykiot self-requested a review August 5, 2021 09:11
Copy link
Member

@aalykiot aalykiot left a comment

Choose a reason for hiding this comment

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

@zubinbhasin LGTM, can you please rebase from main so we can merge your PR ??

@zubinbhasin
Copy link
Contributor Author

@zubinbhasin LGTM, can you please rebase from main so we can merge your PR ??

@aalykiot I've done the rebase but coveralls seems to be failing now.

@helio-frota
Copy link
Member

@zubinbhasin LGTM, can you please rebase from main so we can merge your PR ??

@aalykiot I've done the rebase but coveralls seems to be failing now.

Don't need to worry about that coveralls issue 👍

@aalykiot aalykiot merged commit 0bfd8c4 into nodeshift:main Aug 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants