Skip to content

TypeError when GitHub URL is not defined #52#53

Merged
aalykiot merged 9 commits intonodeshift:mainfrom
zubinbhasin:patch-2
Aug 5, 2021
Merged

TypeError when GitHub URL is not defined #52#53
aalykiot merged 9 commits intonodeshift:mainfrom
zubinbhasin:patch-2

Conversation

@zubinbhasin
Copy link
Copy Markdown
Contributor

#52

@helio-frota
Copy link
Copy Markdown
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

Comment thread src/plugins/archive.js Outdated
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
Copy Markdown
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
Copy Markdown
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.

Comment thread src/plugins/archive.js Outdated
'Checking if github repository is archived'
).withPadding(65);

if (!pkg.repository.url) {
Copy link
Copy Markdown
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) {

Comment thread test/plugins/archive.test.js Outdated

it('should log warning message when module does not specify its GitHub repository', async () => {
// mocking http request to GitHub
network.fetchGithub.mockImplementation(() => {
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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