Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Some unit tests for the cli #45

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

Merged
rtfpessoa merged 15 commits into rtfpessoa:master from whyboris:unit-testing
Feb 10, 2019
Merged

Conversation

@whyboris
Copy link
Contributor

@whyboris whyboris commented Feb 4, 2019

I'm happy to add more unit tests if they are welcome 👍

@whyboris whyboris changed the title (削除) Unit test cli getInput method (削除ここまで) (追記) Some unit tests for the cli (追記ここまで) Feb 4, 2019
Copy link
Owner

Overall I would love to have more unit and integration tests, maybe even some screnshot comparison to understand if the CSS is breaking something.

Regarding this examples specifically:

  • I would like to keep the testing libraries to only one, since we already have mocha we should keep it or update the remaining tests if other library seems more suitable.
  • The testing library should only be available as a DevDependency (should not be needed for runtime)
  • This project was how I learned JS so the code is not very good (maybe even quite bad 😞) for testing. In my daily work I really try to avoid mocks and rewrite the code to be more injectable so we can test most of it just by passing the needed parts.

In sum I have two questions:

  • What is your experience with sinon? (I don't do JS daily to I am not following the trends/innovations) Do you think switching would be interesting?
  • About the tests what do you think about using Dependency Injection / Method Passing instead of mocks for the majority of the tests?
whyboris reacted with thumbs up emoji

Copy link
Contributor Author

whyboris commented Feb 5, 2019

Mocha does not come equipped with spies and the library recommends Sinon.

Spies are particularly useful for unit testing. If the code is modular (and especially if it's functional) it's enough to test that function calls other functions / methods with appropriate arguments. For that we need to create a spy / stub.

Sorry I was tired and accidentally stuck sinon in Dependencies not DevDependencies 😓

At work we use Jasmine which includes spies and better logging when expected value is different from actual. It's easy to work with and given how few written tests there are, it would likely be simple to switch over.

I am more eager to get #42 to a state that's worth merging; we could revisit this PR after then 👍

Copy link
Contributor Author

whyboris commented Feb 5, 2019

I've barely ever used Sinon - just a bit here: https://github.com/whyboris/karma-helpful-reporter
I've not done much research so I'm unsure about the quality of anything other than Jasmine

I'm sorry I'm unsure what you mean with "Dependency Injection / Method passing" with respect to tests. Do you mean just to use the actual Diff2HtmlInterface and see if all the pieces work together by "expecting" correct output given standardized input?

Copy link
Owner

@whyboris my idea was going more in this direction:

but maybe this is not that important in this small application. If you feel like contributing some tests I will be ok accepting the mocks. Also if you think jasmine would be better feel free to change. I have nothing special regarding mockito.

whyboris reacted with thumbs up emoji

Copy link
Owner

@whyboris if you change the dependency to devDependencies I can merge this one.

whyboris reacted with thumbs up emoji

Copy link
Contributor Author

whyboris commented Feb 8, 2019
edited
Loading

I'll look into failing tests tomorrow 👌 unsure what happened yet.

Thank you for the links -- good reading material!

I might try hooking up Jasmine just to see how it goes 👍

edit: the failing tests were because we now have the ignore argument in the getInput method. Fixed with cdabb61

Copy link
Contributor Author

whyboris commented Feb 8, 2019
edited
Loading

Sorry for so many commits, please consider Squash and merge rather than merge commit whenever this PR is ready 😅

Copy link
Contributor Author

whyboris commented Feb 8, 2019
edited
Loading

Currently we're using Istanbul which is no longer maintained and NYC is recommended instead.

Simply replacing istanbul with nyc in package.json and switching the coverage script to nyc mocha we get this:

image

Would you like me to make the switch in this PR ? :)

rtfpessoa reacted with thumbs up emoji

Copy link
Contributor Author

whyboris commented Feb 8, 2019

This is what the change for NYC would look like: whyboris@bfbee97

It should keep all the functionality the same. As a bonus it will include a separate command for generating an HTML output npm run coverage-html 👍

Copy link
Owner

rtfpessoa commented Feb 9, 2019
edited
Loading

Would you like me to make the switch in this PR ? :)

Go ahead 👍

whyboris reacted with thumbs up emoji

Copy link
Contributor Author

whyboris commented Feb 9, 2019
edited
Loading

node 5 fails with:

> nyc mocha
/root/diff2html-cli/node_modules/nyc/node_modules/find-up/index.js:5
module.exports = (filename, opts = {}) => {
 ^
SyntaxError: Unexpected token =

Will not work with nyc I suspect

node 4 fails with:

The package ajv@6.8.1 does not satisfy its siblings' peerDependencies requirements!

Fails during npm install
ajv seems to be part of eslint - perhaps other dependencies have it as a subdependency, and an early version of npm can't handle the different version complexity? Unsure why it passed before but not now otherwise.

Copy link
Contributor Author

whyboris commented Feb 9, 2019

Now both node4 and node5 fail with the Unexpected token = in the nyc library.

It looks like #44 PR will likely require abandoning earlier node versions anyway; do you think it would be acceptable / appropriate to call the next version a major release, dropping support for all node versions prior to 8?

The Node timeline suggests that everyone should be at least on version 8 by April 2019 (node 6 leaves maintenance status then).

Copy link
Owner

@whyboris sure. That sounds appropriate.

Copy link
Owner

We could also add 11 to the test list.

Copy link
Contributor Author

whyboris commented Feb 9, 2019

Great 👍 -- please let me know if there's anything I should do with this PR for you to merge it.

Of course I don't mean to hurry you - no rush on any of this 😁

Copy link
Owner

Remove the old node versions and add 11. That should be enough.

whyboris reacted with thumbs up emoji

Copy link
Contributor Author

😅 I hadn't realized that the configuration for this was in the .yml file 👍

rtfpessoa reacted with laugh emoji

- image: node:10

build-node_11:
<<: *latest-build
Copy link
Owner

@rtfpessoa rtfpessoa Feb 10, 2019

Choose a reason for hiding this comment

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

Sorry. Can you change latest-build to common-build in build-node_10 line 59 so we don't push coverage twice?

whyboris reacted with thumbs up emoji
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 have never dealt with this file / config before -- should have been less cavalier when copy-pasting the last command (node 10 -> 11) 😓

@rtfpessoa rtfpessoa merged commit 70434e2 into rtfpessoa:master Feb 10, 2019
@whyboris whyboris deleted the unit-testing branch February 11, 2019 01:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@rtfpessoa rtfpessoa rtfpessoa requested changes

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

AltStyle によって変換されたページ (->オリジナル) /