Rajah
Rajah is a Jasmine 2.0 spec runner for Node.js and Google apps script.
Want to use GAS-Library now? Project key is here.
Version info:
Version: 2.0.1
Stability: 3 - Stable
Date: 2014-05-09
Changes:
- add tests for Google apps script library.
- small fix.
What’s Rajah?
Rajah is a simple Jasmine spec runner, but has 3 faces.
-
Jasmine spec runner for Node.js.
-
Jasmine spec runner for Google apps script.
-
Script Library for Google apps script.
Rajah allows you to test Node.js project files in your command line shell. - (1)
And also allows to compile Node.js project files and spec files into one source file. That source code is executable on Google apps script environment and run all specs like as on your PC. - (2)
Last face of Rajah is Google apps script Library. In this case, Rajah is a thin wrapper of Jasmine. It’s almost same as Jasmine itself, but simple and easy to use. - (3)
Following sections explain those 3 ways to use Rajah / Jasmine 2.0.
Jasmine spec runner for Node.js
Nothing special. It's simple and easy to use jasmine spec runner.
Install
$ npm install -g rajah
usage
$ rajah SPECS [ options ]
-
SPECS
Spec files or directories. -
Options
-
-m RegExp / --match=RegExp
Only math files in SPECS directories are loaded to run. -
--color / --noColor
Use color to report. -
-o FILEPATH / --output=FILEPATH
Store result into the file. -
[Not implemented yet] -r TYPE / --reporttype=TYPE
It will be 'console' or 'junit'.
-
Jasmine spec runner for Google apps script
This is for codegs user. Need understanding how codegs
works first.
- codegs is a tool to develop Google apps script application using Node.js development tools.
Rajah execute codegs to pack your project and spec files with special doGet
function.
This doGet function provides spec runner functionality.
You can kick doGet
by web IDE, HTTP Request(need to publish as web service), or Other triggers.
For quick understanding, see this sample.
- Access sample project as web service.
Or
-
Open
gas-console
. -
Open sample project and run
doGet
function.
Install
Need to install into project’s local directory.
$ npm install rajah // NO -g option.
When package.json exists, install with --save-dev
option.
$ npm install --save-dev rajah
Usage
-
Run Rajah in local Node.js environment
rajah command is in local node_modules/.bin directory.
$ ./node_modules/.bin/rajah SPECS [ options ]This works as same as above section (Jasmine spec runner for Node.js).
-
Compile with --codegs option switch
Then, add option switch
--codegs
and you see merged long source code in your terminal.-o filepath
let Rajah to store source code in that file.$ ./node_modules/.bin/rajah SPECS [ options ] --codegs -o out.js [ codegs-options ] -
Paste to Google apps script file
Create new project for unit testing and import
console
script library (Project key: MYBwh3izlQThbSz1-36mOjVJodnbMh4p7).Open
Code.gs
file and paste compiled code. -
Open console
Open
gas-console
in onother browser window. >> more about gas-console -
Run doGet function
Back to google IDE.
On toolbar, select function
doGet
and pressRun
button.You see result in gas-console window.
doGet
function
Running mode of doGet
function is able to be kicked by 3 ways.
-
IDE Run / Debug button
Explained in usage section is this pattern.
-
HTTP request
This is for headless unit testing.
-
Deploy your unit testing project as a web service.
- Goto menu:
File
>Manage versions...
and put version number. - Goto menu:
Publish
>Deploy as web app...
and get URL ofLatest code
.
- Goto menu:
-
Access that URL. When access by browser, result is displayed in the window.
-
It's possible to add option values as url query parameters.
- Valid options: specs, showColor, match
- ex. script.google.com/xxxxxx/exec/?sepcs=test/spec&showColor=true
-
-
[NOT YET IMPLEMENTED] Timer or other triggers
Time trrigered unit testing for health checking.
onComplete
option(see below) let you set any function to notify the result or store as you like.
Command line options for --codegs
$ ./node_modules/.bin/rajah SPECS [ options ] --codegs -o out.js [ codegs-options ]
-
-o FILEPATH / --output=FILEPATH
-
-p PACKAGEFILE / --package=PACKAGEFILE
Package file let rajah know which files should be packed for running specs on the GAS environment. -
--stamp=STAMP_STRING
This STAMP_STRING will be sotred into compiled file. And rajah output STAMP_STRING before any report results when executed in GAS environment.This is for checking if the result of doGet access is exactly from this source code.
Execute options for doGet function
-
Top of compiled file, config object is defined as below.
var rajahConfig ="specs":"test/jasmine/jasmine-spec.js""match": null"reportType": null"showColor": true"stamp": "Fri May 09 2014 14:51:44 GMT+0900 (JST)"; -
These values is handed to rajah by command line option when compile with
--codegs
option switch. -
You can chenge this as you like in GAS online IDE.
-
When http-access, url query parameters overwrite this(specs will be added).
Script Library for Google apps script
Project keys
-
Project key: MW3WzHQgUPiNsCAKwIwmYtVJodnbMh4p7
-
Console URL: https://script.google.com/macros/s/AKfycbzZaq3NPqMHYBno7ByxV-bpTbDt6EZ4M_5-kjYXXeQ9HI-k_w8/exec
Install
-
Open your apps script project.
-
Goto menu:
Resources
>Libraries...
-
Copy & paste project key(above) into
Find a Library
and pressSelect
button. -
rajah
will be showed up. select version(chose latest one). -
Save
button.
Usage
-
Write code
Here's First sample code. You need to call only 2 methods.
rajah;{// Any spec-code;rajah;}Only 2 methods to call:
-
rajah.init(this)
At the top of sourcefile, call init method withthis
argument.
rajah copy Jasmine-interface functions intothis
object. At the top of sourcefile,this
points global scope. -
rajah.run()
Execute Jasmine after setup any spec-code.
Jasmine-interface functions setup spec-code but not execute at that timing. run method execute Jasmine.
-
-
Run your function
On toolbar, select function you wrote. And then press
Run
orDebug
button.
You see result in gas-console.- note: rajah itself is using gas-console. so you don't need import gas-console in your library.
Other Methods and Properties:
-
rajah.init(scopeObject)
It's necessary to call first. rajah will copy jasmine interface API's(describe, it,..) into scopeObject.
'scopeObject' should be
this
(global object). -
rajah.run(onComplete)
Run rajah and execute jasmine. By default, results are printed to gas-console.
onComplete
is callback function called with arguments below. -
rajah.addReporter(reporter)
Just call jasmine original
addReporter
. -
rajah.addConsoleReporter(showColor, print)
Instead of gas-console, rajah report to
print
function.- tips:
gas-console
use cache service of google apps script and it take time-cost. Using this method, you can change it faster on-memory console.
var resultString = '';rajah;rajah; - tips:
-
rajah.jasmine
original
jasmine
object.