Question

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!

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top