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

[extensions] Better document. Add unit tests. (#1248) #1442

Merged
merged 1 commit into from Jan 4, 2020
Merged

[extensions] Better document. Add unit tests. (#1248) #1442

merged 1 commit into from Jan 4, 2020

Conversation

ivo-stefchev
Copy link
Contributor

I was curious of how this rule worked, so I went the easiest way and wrote a bunch of unit tests for the buildProperties (a method that returns the options from the config for the extensions rule) method.

@coveralls
Copy link

coveralls commented Aug 5, 2019

Coverage Status

Coverage decreased (-0.02%) to 96.26% when pulling b511da2 on ivo-stefchev:#1248 into fb0cbeb on benmosher:master.

@coveralls
Copy link

Coverage Status

Coverage increased (+2.6%) to 97.897% when pulling bd733c3 on ivo-stefchev:#1248 into 35a12f9 on benmosher:master.


const ruleTester = new RuleTester()

describe('extensions buildProperties', function() {
Copy link
Member

Choose a reason for hiding this comment

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

i'm confused what the purpose of these tests are. can the tests be exercised with ruleTester test cases, rather than hardcoding to things like __test__?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry, I deleted my previous comment by accident. I did it like that, because buildProperties is private function and needs to be tested.
So I guess it's a no go for this PR?

Copy link
Member

Choose a reason for hiding this comment

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

in general, private things shouldn't be tested - in this plugin's case, everything should be tested via the RuleTester.

Copy link
Contributor

@soryy708 soryy708 Oct 23, 2019

Choose a reason for hiding this comment

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

I'm not sure why you're saying "private things shouldn't be tested". I see no reason not to, and plenty of reasons to do.

Copy link
Contributor

Choose a reason for hiding this comment

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

One benefit of not testing internal functions is that you can refactor internals as much as you want.

Copy link
Contributor

Choose a reason for hiding this comment

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

But when you refactor internals and break something, you wish you had tests to catch that early.

Copy link
Member

Choose a reason for hiding this comment

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

The tests should be on the public pieces, and should transparently exercise all the private pieces.

Any behavior of your private code that is not observable via your public code should not be tested because it doesn't matter if it works or not

Copy link
Member

@ljharb ljharb left a comment

Choose a reason for hiding this comment

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

I've gone ahead and reverted the semver-minor piece that exposes a utility function, and the associated tests, so I can merge the docs improvement.

@ljharb ljharb merged commit b511da2 into import-js:master Jan 4, 2020
@ljharb ljharb added the docs label Jan 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging this pull request may close these issues.

None yet

5 participants