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

Fix testing errors when module uses ROS context #86

Open
laurentboisvert opened this issue Apr 23, 2021 · 0 comments
Open

Fix testing errors when module uses ROS context #86

laurentboisvert opened this issue Apr 23, 2021 · 0 comments

Comments

@laurentboisvert
Copy link
Contributor

Expected Enhancement

Running npm run test should not yield any errors when tests are actually passing.
For example, we run it once:
image
and then run it again, filtering on powermodule:
image

The tests pass but errors are output because of the ROS queries.

Current Behavior

Errors because some modules, when tested, try to subscribe to ROS topics.

Possible Solution

There are 3 main solutions:

  1. Make the modules as generic as possible, and use a decorator around them that makes the call to ROS. This way, when we test, we only test the wrapped module and not the wrapper that actually calls ROS:
// Example
<ROSSubscriber route="/provider_power/power" messageType="sonia_common/PowerMsg">
  // ROSSubscriber "injects" PowerModule with the message from topics
  <PowerModule />
</ROSSubscriber>

In this example, we would only test <PowerModule /> with dummy datas.
2. Another way would be to add conditional logic in the useROSTopicSubscriber. We could check if we are currently in a test/jest context, with something like

function areWeTestingWithJest() {
    return process.env.JEST_WORKER_ID !== undefined;
}

This way, we don't have to add wrapper components. ⚠️ This is not so easy though because we are using hooks so we can't either return a context or 'nothing'...
3. Another way, not so ideal, is to change the affected components into non-functional components (so they would have more 'lifecycle' methods. The goal would be to use a conditional statement (like method 2) and only subscribe or publish to ROS when we are not testing.

Comments

N/A.

Environment Used

N/A.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant