JetBrains WebStorm/PHPStorm + jQuery + JsTestDriver + Jasmine


This post describes a workaround to get the triple jQuery + JsTestDriver + Jasmine working inside JetBrains WebStorm to be able to perform tests from the IDE.

As mentioned in this post http://blog.jetbrains.com/webide/2011/10/javascript-unit-testing-support/#comment-6600 there are apparently some issue when you try to run the built-in version of the JsUnitDriver. The result is the following exception that is thrown when you try to capture the browser:

Can't run tests. Details:
java.lang.NullPointerException
	at com.google.jstestdriver.PathResolver.expandDeepDirectoryGlobPaths(PathResolver.java:237)
	at com.google.jstestdriver.PathResolver.expandGlob(PathResolver.java:222)
	at com.google.jstestdriver.PathResolver.expandFileInfosFromFileInfo(PathResolver.java:119)
	at com.google.jstestdriver.PathResolver.resolve(PathResolver.java:96)
	at com.google.jstestdriver.config.ParsedConfiguration.resolvePaths(ParsedConfiguration.java:99)
	at com.google.jstestdriver.config.Initializer.initialize(Initializer.java:86)
	at com.google.jstestdriver.embedded.JsTestDriverImpl.createRunnerInjector(JsTestDriverImpl.java:368)
	at com.google.jstestdriver.embedded.JsTestDriverImpl.runConfigurationWithFlags(JsTestDriverImpl.java:342)
	at com.google.jstestdriver.embedded.JsTestDriverImpl.runConfiguration(JsTestDriverImpl.java:233)
	at com.google.jstestdriver.idea.TestRunner.runTests(TestRunner.java:177)
	at com.google.jstestdriver.idea.TestRunner.executeTests(TestRunner.java:101)
	at com.google.jstestdriver.idea.TestRunner.executeAll(TestRunner.java:87)
	at com.google.jstestdriver.idea.TestRunner.main(TestRunner.java:306)

You can set up the following workaround:

1. Install JsTestDriver

Just download JsTestDriver-X.X.X.jar from here (http://code.google.com/p/js-test-driver/) and add this run.sh file:

java -jar JsTestDriver-1.3.5.jar --port 9999

2. Define your own configuration in the IDE

Add this configuration by running Run... / Edit configurations .... Go to Defaults / JsTestDriver to the Server section and change Running in IDE to At address:. Put in http://localhost:9999.

JsTestDriver_custom_config

Go to the Before launch section and add a new Run external tool configuration like follows:

JsTestDriver_standalone

3. Adding a test file

Add a new test file (e.g. test.jstd) in which the server and all the needed javascript dependencies are listed:

server: http://localhost:9999

load:
  - jasmine/lib/jasmine-1.3.1/jasmine.js
  - jasmine-jstd-adapter/src/JasmineAdapter.js
  - jquery-ui/js/jquery-1.9.0.js
  - jquery-ui/js/jquery-ui-1.10.0.custom.js
  - jasmine-jquery/jasmine-jquery.js
  - my-own-plugin/js/my-own-plugin.js

test:
  - my-own-plugin-test/my-own-plugin-test.js

Note: to achieve the JsTestDriver + Jasmine + jQuery integration you’ll need the JasmineAdapter.js (which is an JsTestDriver adapter for Jasmine) and jasmine-jquery.js (which provides the integration between jasmine and jQuery). Download them:

Note: I think that the latter one is optional. Just try to remove it just to see if the whole machinery still works.

4. Starting tests

Go to Run / Run... and check if your test.jstd is associated with the custom configuration of JsTestDriver (see step 2). If not then add the settings as described above. Click at the > Run button.
The JsTestDriver dialog will appear in your IDE (normally at the bottom). The dialog will most likely contain this error message:

Could not connect to a JsTestDriver server running at http://localhost:9999
Check that the server is running.

Process finished with exit code 1

jstestdriver_complain_not_running

Click at the button “Rerun” located in the upper left corner of the JsTestDriver dialog. You should be able to see the following message:

No captured browsers found.
To capture browser open http://localhost:9999 in browser.

Process finished with exit code 1

jstestdriver_non_capturing

Open the url http://localhost:9999 in your Chrome browser. You should see the link Capture this browser. Click it. This should change the content of your browser to this one:

JsTestDriver
Last:1361062701447 | Next:1994 | Server:Waiting...

jstestdriver_browser_capturing

Re-try the tests in your IDE by clicking > Rerun again.
The tests should pass.

jstestdriver_result

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s