hybridgroup / cylon

JavaScript framework for robotics, drones, and the Internet of Things (IoT)
https://cylonjs.com
Other
4.2k stars 362 forks source link

[Docs] more examples using testing #314

Closed 7yl4r closed 8 years ago

7yl4r commented 9 years ago

I've been trying to set up a basic robot along with a test, but am having some trouble. A few more examples which use testing would definitely help.

Here's a gist with my minimal robot.js and robot_test.js which is a stripped-down hello-world example. When I run the tests I get

2015-11-03T14:29:46.984Z : [cylon-test-bot] - Starting connection 'loopback'.
/home/user/cylon-test-bot/node_modules/cylon/lib/adaptor.js:60
  throw new Error(message);
  ^

Error: Error in connection 'loopback' - Adaptor#connect method must be overwritten by descendant classes.
    at TestAdaptor.Adaptor.connect (/home/user/cylon-test-bot/node_modules/cylon/lib/adaptor.js:60:9)
    at Robot.startConnection (/home/user/cylon-test-bot/node_modules/cylon/lib/robot.js:317:22)
    at Robot.<anonymous> (/home/user/cylon-test-bot/node_modules/cylon/lib/robot.js:288:19)
    at /home/user/cylon-test-bot/node_modules/cylon/lib/utils/helpers.js:237:36
    ...

I haven't quite been able to make sense of this, but I'm guessing I need to mock the connection?

I've also tried removing the loopback connection and ping device since they aren't really used and are just remnants from the hello world example. While the robot runs fine in this case, when running the test the robot seems to go uninstantiated:

2015-11-03T15:36:20.755Z : [cylon-test-bot] - Starting connections.
2015-11-03T15:36:20.757Z : [cylon-test-bot] - Starting devices.
2015-11-03T15:36:20.758Z : [cylon-test-bot] - Working.
/home/tylar/cylon-test-bot/test/robot_test.js:22
  var robot = Cylon.robots["cylon-test-bot"];
                          ^

TypeError: Cannot read property 'cylon-test-bot' of undefined
...

Some examples to clarify these issues would greatly help me (and possibly others) get started using cylon in a test-driven context.

deadprogram commented 9 years ago

Hi, @7yl4r

I made some corrections to the test drive robotics example in the docs site here: https://github.com/hybridgroup/cylon-site/commit/3f6dc7f16c7b6d28378710ffbb8dad3796fa6327

Thanks for pointing out that the example was not correct! It needed to be updated for a while.

Test Driven Robotics (TDR) is a subject that probably deserves an entire blog post/book on its own. However, please let me know if the above is sufficient to unblock you and close this particular issue.

halley-eng commented 8 years ago

Hello, one error happened when I update from 1.0.0 to 1.2.0 I am sure it is well when i use 1.0.0

Following is the error

   > TypeError: Cannot read property 'IOT' of undefined

Following is my source code

  Cylon.robot({
          name: 'IOT',
         description: 'Description is optional...'
          .......
  });

the error happened when i call that

     Cylon.robots['IOT']        

SORRY FOR MY POOR ENGLISH,TANKS

deadprogram commented 8 years ago

Hi, @llwoll the correct syntax is now:

Cylon.MCP.robots["IOT"];

The documentation was updated as part of https://github.com/hybridgroup/cylon-site/commit/3f6dc7f16c7b6d28378710ffbb8dad3796fa6327

Hope that helps!

deadprogram commented 8 years ago

Since this issue appears to be resolved, I am going to close it. Please reopen if needed.

geryb-bg commented 8 years ago

Hi

I am still seeing this same issue. I copied the example exactly as it appears on the website but am getting the same error that @7yl4r described. Any chance you could help me?

Thanks