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

chore(tests): add unit tests for js/modules #180

Open
wants to merge 24 commits into
base: master
Choose a base branch
from

Conversation

mellodev
Copy link
Contributor

@mellodev mellodev commented Nov 30, 2024

Changes Proposed

  • Create /test/tests/modules folder
  • Add test suites for (almost) all module files. We now have 311 unit tests covering most of the modules logic (before there were 41 tests)
  • ⚠️ Fair warning: these tests were created with an AI tool, so please review carefully. Figured this approach would be an easy way to backfill tests for the low hanging fruit.
  • The goal was 100% function coverage and >= 80% conditional/branch coverage, but that didn't happen (see chart below)
  • Due to the nature of the test generation and the project's heavy reliance on jquery/DOM, many tests are not written and some are marked as skip.
  • Interestingly, the tests did uncover a few inconsistencies (check out FIXME note in firmware.test.js for OSApp.Firmware.versionCompare!)
  • Setup unit test coverage html reporting: Run npm test then open test/reports/Chrome xx/index.html with your browser (See below)

Demo Video or Screenshots

image

Coverage with this PR. Nowhere near the >= 80% I was hoping for, but at least it's a start!
image

@mellodev mellodev changed the title chore(tests): analog module tests chore(tests): add unit test coverage for modules Dec 5, 2024
@mellodev mellodev marked this pull request as ready for review December 5, 2024 03:00
@mellodev mellodev changed the title chore(tests): add unit test coverage for modules chore(tests): add unit test coverage for js/modules Dec 5, 2024
@mellodev mellodev changed the title chore(tests): add unit test coverage for js/modules chore(tests): add unit tests for js/modules Dec 5, 2024
Copy link
Member

@salbahra salbahra left a comment

Choose a reason for hiding this comment

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

I suspect these are from the AI generations but far too much of these tests mock major functionality. I am not sure what they are testing with the level of mocking. I would rather properly intercept HTTP requests and not mock anything else. The app should fully function in testing so long HTTP requests to the firmware are mocked.

}
},
lang: 'en'
};
Copy link
Member

Choose a reason for hiding this comment

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

Instead of overwriting the current session in the test, I think I would prefer to change the mocked payload (sinon) for the respective changes. For this example, the /jp and /jo responses would be different to match this test criteria. I think this avoids possible differences in what we expect versus what the firmware sends (also sets us up to support testing different firmware versions).

};
OSApp.currentDevice = { isMetric: false };
OSApp.Language = { _: function(key) { return key; } };
OSApp.Utils = { pad: function(num) { return ('0' + num).slice(-2); } };
Copy link
Member

Choose a reason for hiding this comment

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

I don't think we should be mocking these functions. Why don't we just use the method itself?

}
};
setTimeout = function(func, delay) {};
clearTimeout = function(timeout) {};
Copy link
Member

Choose a reason for hiding this comment

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

This type of mocking doesn't make much sense to me. Why do we need to mock set and clear timeout?

};

// Mock OSApp.Errors.showError
originalShowError = OSApp.Errors.showError;
Copy link
Member

Choose a reason for hiding this comment

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

I don't think we should be mocking all of this (same comments so will stop making these).

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.

2 participants