Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 465
Odalrick Avatar asked Jun 01 '12 20:06

Odalrick


1 Answers

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.

like image 191
meyertee Avatar answered Oct 08 '22 00:10

meyertee