Using closure library with jsTestDriver

I'm learning about google closure tools by writing a simple JavaScript game. I'm having trouble figuring out how to set up jsTestDriver so that it works well with closure library.

Specifically: I'd like to use the goog.require mechanism to include any additional JavaScript files rather than have to manually add them all to the config file.

Following meyertee's suggestion I made a simple script to automatically write the dependencies to a config file

#!/bin/bash
cp tests/jsTestDriver.conf.proto tests/jsTestDriver.conf
libs/closure-library/closure/bin/build/closurebuilder.py --root="./libs/closure-library" --root="./js" --namespace="lds" | sed "s#^#  - ../#" >> tests/jsTestDriver.conf

The tests/jsTestDriver.conf.proto file is a simple template:

test:
  - "*.js"
load:
  - ../libs/knockout-2.1.0.js
# Crucial, the load key needs to be last, and this comment must be followed by a newline.

It is a very fragile script, but hopefully someone (other than me) will find it useful.


You can do it semi-automatically by letting Closure Compile generate a manifest file, which will output all files in the correct order of dependency. You can then transform that file to relative paths and paste them into the JsTestDriver config file. That's how I do it.
You could even write a script that does this transformation automatically.

This is the relevant compiler argument:

--output_manifest manifest.MF

There are some details on the Closure Compiler's Google Code Wiki

Edit: There are also some Python scripts to help you calculate dependencies. You can use calcdeps.py or closurebuilder.py to generate a manifest file, which even includes files that haven't been 'required' by your code.


Since JsTestDriver does not following the Closure Library convention of declaring dependencies with goog.provide() and goog.require() , your best option may be meyertee's solution.

However, the Closure Library includes its own testing framework. See:

  • Test Driven Development with the Closure Framework
  • Asserts API
  • 链接地址: http://www.djcxy.com/p/60086.html

    上一篇: 始终保持git镜像同步

    下一篇: 在jsTestDriver中使用闭包库