JavascriptCompressionTesting

OurWork Edit-chalk-10bo12.png

What (summary)

We want an automated test to make sure our javascript doesn't have invalid syntax that emerges when packed.

Why this is important

It is annoying to have to set $auPackJavascript = true; every time one wants to deploy new code. Setting javascript packing to false is useful to keep on during development.

DoneDone

If the javascript files contain a syntax error that causes decompression to fail, running "rake test integration" both show an error.

Steps to get to DoneDone

  • install jline so that in the Rhino environment, we can use shell features like Up Arrow to display last executed command, besides many other features suspended for now
  • temporary solution:
  1. php javascript.php > wholefile.js
  2. remove the warnings from wholefile.js to make it a valid javascript file (if any are outputted)
  3. type "js" at command line so that you enter the Rhino shell
  4. type the following commands
    1. load('env.js')//assuming that u have pasted the file from where u r running. (it can be found here)
    2. window.location = 'somefile.html' //assuming u have pasted a valid html file named somefile.html from where u r running
    3. load('wholefile.js');
  5. if ur file does not have syntax errors, the load should be silently completed, otherwise expect the Rhino to scream. also, it gave me a compile error for window.top being not defined, so i simply did "window.top = window" before "load('wholefile.js')", and it worked
  • to have a browser environment so that window etc are defined, copy the file env..js to the classpath folder, that is, the folder having the js.jar file
  • how to include files, for example, in ruby console, we can say: require 'irb/completion'. how to do sth like : inlcude 'jquery.js' using this shell? Without this power, it doesn't look of much use??? solution: load('filename.js');

Miscellaneous comments

  • On the other hand, there are many useful Java tools we may want to be able to use...and Mac OS already has it installed
  • You'd probably want to distribute the Rhino [jar|http://www.mozilla.org/rhino/download.html] with the repo.
  • Shelling out to the command line is probably how to go.
  • Even if this doesn't prove useful I'm curious to know how it worked. -Stephen Judkins 23:51, 30 January 2008 (PST)

Rhino Install instructions

  • Instructions taken from here
  1. make sure you have java installed. You can check this by typing "java" at your command prompt and reading the output
  2. download Rhino from [1], (click on the "Rhino---.zip" file, the '---' representing version)
  3. unzip it, and copy the "js.jar" file to "/www/sites/branches/classpath/js.jar"
  4. open up your .bashrc file to export path to the jar file. Your paths shoudl look like this:
    1. CLASSPATH="/www/sites/classpath:/www/sites/classpath/js.jar"
    2. PATH="/www/bin:/www/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/s bin:/bin:/usr/games"
    3. export PATH CLASSPATH
    4. alias js='java org.mozilla.javascript.tools.shell.Main'
  5. close your shell prompt and reopen it to make the changes take effect
  6. Test your installations:
    1. create a js file, example helloworld.js, and write
    2. print("Hello world");
    3. save and close it
    4. run it by typing :
    5. java org.mozilla.javascript.tools.shell.Main helloworld.js
    6. your shell output should read:
    7. Hello world
  7. Your are done!
  8. note: the line: "alias js='java org.mozilla.javascript.tools.shell.Main'" in the bashrc file enables you to write "js helloworld.js" instead of the lengthy "java org.mozilla.javascript.tools.shell.Main helloworld.js".
  9. if in following these instructions, you come across an error/omission/ambiguity etc, do not hesitate to make constructive edits to rectify it, or at least report a problem. Thanks!

Jline Install instructions

  • instructions taken from here
  1. download the jline source from here
  2. unzip it, and place the jline-0.9.93.jar file so that java can find it. Example: /usr/lib/jvm/java-6-sun/jre/lib/ext


Retrieved from "http://aboutus.com/index.php?title=JavascriptCompressionTesting&oldid=14700798"