SlimJS
An Async Node.js SliM server for FitNesse
To use slimjs on an existing FitNesse server:
npm install -g slimjs
On windows there might be an error when java is trying to execute SlimJS
even though installed globally. Try to replace COMMAND_PATTERN
with an absolute path.
!define COMMAND_PATTERN {node C:\Users\<MY_USER>\AppData\Roaming\npm\node_modules\slimjs\src\SlimJS %p}
Create a test page in FitNesse and add this to the top of the page, remember on windows to replace COMMAND_PATTERN
with an absolute path if needed:
!define TEST_SYSTEM {slim}
!define COMMAND_PATTERN {SlimJS %p}
!path /Path/To/My/Fixtures
|import |
|my-test-file|
|Hi |
|echo |sayHi? |
|Bob |Hi! Bob |
/Path/To/My/Fixtures/my-test-file.js
{ this{ thisecho = str; } this{ return "Hi! " + thisecho; }} moduleexportsHi = Hi;
If you want to do something asynchronous, return a thenable
(promise):
|script |child_process |
|check |exec |node -v |v5.4.0 |
var exec = exec; { this { return { ; } }} moduleexportschild_process=child_process;
Using namespaces:
|eg.Division |
|numerator |denominator |quotient? |
|10 |2 |$result= |
|$result |10 |0.5 |
|12.6 |3 |4.2 |
|100 |4 |25 |
var eg= { var num; var denom; this{ num = n; } this{ denom=n; } this{ return num/denom; } }; moduleexportseg=eg;
Name conversion:
|should I buy milk |
|cash in wallet|credit card|pints of milk remaining|go to store?|
|0 |no |0 |no |
|10 |no |0 |yes |
|0 |yes |0 |yes |
|10 |yes |0 |yes |
|0 |no |1 |no |
|10 |no |1 |no |
|0 |yes |1 |no |
|10 |yes |1 |no |
{ var _dollars; var _pints; var _creditCard; this { _dollars = dollars; } this { _pints = pints; } this { _creditCard = "yes"===valid; } this { var ret=_pints == 0 && _dollars > 2 || _creditCard ? "yes" : "no"; return ret; }} moduleexportsShouldIBuyMilk=ShouldIBuyMilk;
Using JSON
|Json |
|json |X and Y ?|
|{x:1,y:2} |3 |
|{x:'Bar', y:' Baz'}|Bar Baz |
{ this{ thisobj = jsonObject; } this{ return thisobjx + thisobjy; }} moduleexportsJson=Json;
--
For contributors
I'm working to pass the FitNesse Test Suite for Slim.
- ChainTest - pass
- ChainWithInstanceTest - pass
You can run these test locally here (after you startup): http://localhost:8080/FitNesse.SuiteAcceptanceTests.SuiteSlimTests
To start the environment:
npm install
cd fitnesse
java -jar fitnesse-standalone.jar -p 8080
To start the UDP logger (for debugging)
node src/utils/LogUdpServer.js
Thanks to:
Tomasz @mrt123. The first user of slimjs and for the async exec example.
Gregor Gramlich @ggramlich. For help with the SliM protocol, the PHP implementation and the promise proposal.
Christian Gagneraud @chgans. QtSlim
Libraries:
json5