Using closure library using jsTestDriver

I learned about Google's closing tools by writing a simple JavaScript game. I find it hard to figure out how to configure jsTestDriver to work well with the closure library.

In particular: I would like to use the goog.require mechanism to include any additional JavaScript files, rather than manually adding them to the configuration file.

Following meyertee's suggestion, I made a simple script to automatically write dependencies to a configuration 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 file test / jsTestDriver.conf.proto 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. 

This is a very fragile script, but hopefully someone (except me) finds it useful.

+7
source share
2 answers

You can do this semi-automatically by letting the Closure Compile generate a manifest file that will display all the files in the correct dependency order. You can then convert this file to relative paths and paste them into the JsTestDriver configuration file. This is how I do it. You can even write a script that automatically performs this conversion.

This is the corresponding compiler argument:

 --output_manifest manifest.MF 

There are a few details in the Closure Compiler Google Code Wiki

Edit: There are also some Python scripts to help you calculate dependencies. You can use calcdeps.py or closbuilder.py to create a manifest file that even includes files that werenโ€™t "needed" by your code.

+4
source

Since the JsTestDriver does not follow the Closure Library dependency declaration agreement with goog.provide() and goog.require() , a meyertee solution might be a better option.

However, the Closure library does include its own testing environment. Cm:

0
source

All Articles