5

I hope someone out there might be able to help me out with a coding problem I am having. I am currently working with server side JavaScript code that executed within a third party Java application (mirth connect) that executes the implemented JavaScript using the Rhino JavaScript compiler. This is of of special interest since I sometimes have the need to interact with external Java packages.

I have been looking at ways of formalising our testing process on this code. With this in mind I have been looking at JavaScript unit testing frameworks such as QUnit and Jasmine. Unfortunately as I understand it, these frameworks are primarily aimed at testing JavaScript code running in a browser environment, but I need to test as if the code were being executed on a server. But this could be achieved by running these frameworks with a headless browser browser.

What I'd really like to know is if this is at all possible? I have looked at many resources that claim to be able to implement this but have been unable to do this myself. If it is indeed possible, does anyone have any links or simple walkthroughs I could follow?

I'd be more than happy to provide examples of the JavaScript code I'd want to test, the Java class I'd want to call from the JavaScript and the unit tests once anyone can confirm I'm sure I'm not barking up the wrong tree with this as a possible solution.

Thanks in advance!

hizni
  • 53
  • 4
  • I'm wondering why Mirth is added to your question tags? Debugging JavaScript under Mirth Connect is a bit different than debugging JavaScript in a "normal" way. – Shamil Apr 07 '14 at 17:36
  • Hi. That is undoubtedly true - but trying to perform any formal testing in MC is currently not a native option. So we have opted for a solution of attempting to emulate a MC environment. Have you had any experience of attempting to develop in MC? I would love to know any insights you might have. – hizni Apr 09 '14 at 09:00
  • Since you've asked, do not consider this as an ads. There is a book called "Unofficial Mirth Connect v3.0 Developer's Guide" that explains some of the debugging options. It's available at http://mirthconnect.isarp.com Disclaimer: I'm the author of this book, so any comments or suggestions are welcome. – Shamil Apr 10 '14 at 16:47
  • @user3005941 LOL! I beat you to it and had already bought it before your shameless plugging of your book! :) and am working my way through some of the topics (debugging, extensions, etc) that you have written about. Very interesting and useful read. Thanks. – hizni Apr 14 '14 at 09:19

1 Answers1

3

I'd recommend writing your tests in Groovy/Java and running them that way. It's not ideal, but Rhino provides a handy bridge to get at the JavaScript objects.

I've written about setting it up here: http://ryanbrooks.co.uk/posts/2014-03-27-testing-rhino-js-spock/

You could always try writing your tests in Jasmine and running them with Karma. You'd need to run Karma on Rhino, which caused us problems, but you might have more luck if you use CommonJS for Rhino.

My view is that (generally) Rhino is only used these days where JavaScript needs to be executed by Java processes, in which case you probably care about testing the Java-side output, but YMMV.

spikeheap
  • 3,827
  • 1
  • 32
  • 47