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

[tests] Add unit tests to existing codebase #181

Merged
merged 14 commits into from
Dec 2, 2022

Conversation

sfriedle
Copy link
Contributor

Relates to #166

Description

This PR adds unit tests to the existing codebase. Until now there are only two unit tests, written with Mocha. The newly added tests use Jest as testing framework. To distinguish between the Mocha and Jest tests, we use this filename pattern:

  • Mocha tests end with *.test.js
  • Jest tests end with *.spec.js

The tests can be run with this commands:

  • npm run test runs all tests and lints the sources.
  • npm run test:mocha runs the existing Mocha tests.
  • npm run test:jestruns the new Jest tests.

Signed-off-by: Stefan Friedle <[email protected]>
Signed-off-by: Stefan Friedle <[email protected]>
Signed-off-by: Stefan Friedle <[email protected]>
Signed-off-by: Stefan Friedle <[email protected]>
Signed-off-by: Stefan Friedle <[email protected]>
Signed-off-by: Stefan Friedle <[email protected]>
Signed-off-by: Stefan Friedle <[email protected]>
The Jest mock functions and spies are now closer to their callers. java.mock.js is now independent of Jest.

Signed-off-by: Stefan Friedle <[email protected]>
Signed-off-by: Stefan Friedle <[email protected]>
Signed-off-by: Stefan Friedle <[email protected]>
Copy link
Contributor

@florian-h05 florian-h05 left a comment

Choose a reason for hiding this comment

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

Honestly, I‘ve no experience with jest, but reading through the tests, I think I understand it.
So, as fas as I can say: LGTM, thanks!

Please have a look at my minor comments.

Please do not force push from now on!!

test/.eslintrc Outdated Show resolved Hide resolved
test/actions.spec.js Outdated Show resolved Hide resolved
Signed-off-by: Stefan Friedle <[email protected]>
@sfriedle
Copy link
Contributor Author

sfriedle commented Dec 1, 2022

@florian-h05 Shall we merge and close this pull request? The contained tests cover nearly all JavaScript files in the root directory. I can open new pull requests when I continue to write tests for the remaining files in subdirectories, like items, things, etc.

@sfriedle sfriedle marked this pull request as ready for review December 2, 2022 07:26
@florian-h05
Copy link
Contributor

I‘ll have a final look later, but I am very happy with merging this first PR!

Copy link
Contributor

@florian-h05 florian-h05 left a comment

Choose a reason for hiding this comment

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

LGTM, thanks for your contribution!

@florian-h05 florian-h05 merged commit e4e5237 into openhab:main Dec 2, 2022
@florian-h05 florian-h05 changed the title [WIP] [tests] Add unit tests to existing codebase [tests] Add unit tests to existing codebase Dec 2, 2022
florian-h05 pushed a commit that referenced this pull request Dec 2, 2022
Relates to #166.

* Add Jest dependencies and configuration.
* Add tests for utils.js.
* Add tests for triggers.js.
* Add tests for cache.js.
* Refactor mocking of global Java types.
* Ignore .DS_Store.
* Reorganize npm test scripts.
* Move Jest mock functions.
The Jest mock functions and spies are now closer to their callers. java.mock.js is now independent of Jest.
* Add tests for osgi.js.
* Add tests for actions.js.

Signed-off-by: Stefan Friedle <[email protected]>
@florian-h05 florian-h05 added the infrastructure Build and test infrastructur and workflows label Dec 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
infrastructure Build and test infrastructur and workflows
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants