The book Test-Driven JavaScript Development is great, http://tddjs.com/
. It indeed changed my thoughts on javascript, it is such a powerful dynamic language, very close to ruby, e.g. similar features like everything is object, including functions. While some other feature like hoist variable declaration, this variable scope and closure are very weird.
JsTestDriver is very successful xUnit like test environment. Its community is very active, during only 3 days while I was playing it, its version bumped from 1.2.2. to 1.3.0!
It’s very annoying that there is no GUI Runner for jsRunner , but picking NetBeans as my javascript IDE seems not a bad choice. I really like the ALT+Shit+F to reformat feature.
Here is some trick to embed jsTestDriver in NetBeans.
- Create Ruby project to hold all those javascript source code.
- Create Rake file at project root, content look like this:
directory "test/output" task :run_js_test => "test/output" do ff = "C:\\Program Files\\Mozilla Firefox\\firefox.exe" output = "--testOutput test/output" sh "java -jar tools/JsTestDriver-1.3.0.jar --port 4224 --tests all #{output} --browser \"#{ff}\" " end task :default => [ :run_js_test ]
- Run this Rake file, we can see the test results from output window:
Note: Those MUST be a space before the dash in front of coverage name in conf file, otherwise you will get an error:while scanning a block mapping
expected , but found org.jvyaml.tokens.BlockMappingStartToken
org.jvyaml.ParserException: ParserException while scanning a block mapping we had this expected , but found org.jvyaml.tokens.BlockMappingStartToken
Room to improve for NetBeans IDE:
- View codecoverage data file in IDE (Windows ENV)
- GUI view of those test results
- Better embed of those test-cases.
All those features already exist in NetBeans Ruby IDE, hope in the future it can also apply for javascript.