Using closure library with jsTestDriver
Asked Answered
T

2

7

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.

Territoriality answered 1/6, 2012 at 20:15 Comment(1)
Thanks for sharing your solution, I've changed my project to using the Python scripts too (I'm actually using calcdeps.py). It's better than using the compiler, because it picks up dependencies that aren't linked to your project yet - better for testing new code - and it's faster.Cost
C
4

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.

Cost answered 3/6, 2012 at 12:52 Comment(0)
C
0

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:

Calandracalandria answered 2/6, 2012 at 1:36 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.