rajah v2.0.2
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 rajahusage
$ 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
doGetfunction.
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 rajahUsage
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
--codegsand you see merged long source code in your terminal.-o filepathlet 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
consolescript library (Project key: MYBwh3izlQThbSz1-36mOjVJodnbMh4p7).Open
Code.gsfile and paste compiled code.
Open console
Open
gas-consolein onother browser window. >> more about gas-console
Run doGet function
Back to google IDE.
On toolbar, select function
doGetand pressRunbutton.You see result in gas-console window.
Running mode of doGet function
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.
onCompleteoption(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
--codegsoption 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 Libraryand pressSelectbutton.rajahwill be showed up. select version(chose latest one).Savebutton.
Usage
Write code
Here's First sample code. You need to call only 2 methods.
rajah.init(this); function MyFunction() { // Any spec-code describe("Rajah", function () { it("is the best friend of Jasmine.", function () { expect(rajah.rajah.hasOwnProperty('jasmine')).toBe(true); }); }); rajah.run(); }Only 2 methods to call:
rajah.init(this) At the top of sourcefile, call init method with
thisargument. rajah copy Jasmine-interface functions intothisobject. At the top of sourcefile,thispoints 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
RunorDebugbutton. 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.
onCompleteis callback function called with arguments below.function onComplete(bool passed, num specs, num failures, num pendings)rajah.addReporter(reporter)
Just call jasmine original
addReporter.
rajah.addConsoleReporter(showColor, print)
Instead of gas-console, rajah report to
printfunction.function print(string)tips:
gas-consoleuse 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.addReporter(false, function (str) { resultSting += str; }); rajah.run(function () { console.log(resultStr); // or Report anyway you like. });
rajah.jasmine
original
jasmineobject.
11 years ago
11 years ago
11 years ago
11 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago