Gherkin for Javascript

671 views
Skip to first unread message

aslak hellesoy

unread,
Mar 18, 2011, 8:44:58 PM3/18/11
to Cucumber Users
Hi folks,

I'm finally starting to get somewhere on Gherkin for Javascript
(https://github.com/aslakhellesoy/gherkin/issues#issue/38). I have
managed to get Ragel to generate the Gherkin lexer in Javascript. It's
all on my javascript branch. The next step is to get all of the
existing solid specs and features to validate its correctness. This
can be done with therubyracer - a Ruby<->V8 Javascript bridge.

The short README_JAVASCRIPT.md file should be enough to get you up and
running and try out this little example:
https://github.com/aslakhellesoy/gherkin/blob/javascript/js/example/print.js
(runs on node.js)
In theory, this should do more or less the same:
https://github.com/aslakhellesoy/gherkin/blob/javascript/js/example/print.rb

However, it doesn't (the scan method gets called, but somehow we never
get into the code where events are fired - calls to this.emit).

Anyone want to help? It would be cool to:

a) Have a "try cuke" in your browser (with some http://ace.ajax.org/ love)
b) Get started on cucumber for Node.js

Aslak

aslak hellesoy

unread,
Mar 19, 2011, 10:08:36 PM3/19/11
to Cucumber Users
I've made some progress on this - I got gherkin running in a browser!

If you check out my javascript branch of the gherkin repo and open js/example/index.html you should get an editor for a simple feature. Check what goes on in the console when you edit it.
To get this working, you have to:

* Build the js lexer - see README_JAVASCRIPT.md
* Grab the ace editor - you'll get instructions about how to do that when looking at index.html

The lexer is still quite buggy, but I have done the minimal plumbing to make it possible to test it with our existing specs. (Those are already used to test the Ruby, C and Java builds of gherkin). See spec/gherkin/js_lexer_spec.rb and spec/gherkin/js_lexer.rb. I'm using therubyracer to talk to the V8 engine+Gherkin JS from Ruby+specs.

The next step now would be to iron out the bugs in the lexer. The logic is implemented in ragel/lexer.js.rl.erb, and if you compare with ragel/lexer.rb.rl.erb (or the java or c one) - you'll see that it's a fairly straight port. There are some small hacks to deal with conversion of strings to byte arrays (ragel works on bytes, not strings). There are also some hacks to make the lexer work in different environments, such as Node.js, browsers and therubyracer.

I'm looking for volunteers to fix the remaining bugs. A working Javascript lexer for Gherkin opens up for some very interesting possibilities, such as:

* A try cucumber app on the web site
* A cucumber implementation in Javascript

Any takers?

Cheers,
Aslak

Aslak

Julien Biezemans

unread,
Mar 20, 2011, 7:38:32 AM3/20/11
to Cukes
Hi Aslak,

As we discussed on #cucumber three days ago, I am willing to help
there. I'm really missing cucumber when developing for node :)

I have already looked at gherkin and your JavaScript branch, ragel-js
is installed, specs and cukes are all passing. If you're not too busy
then, we could discuss it during cukeup!

Cheers,

Julien.

On Mar 20, 3:08 am, aslak hellesoy <aslak.helle...@gmail.com> wrote:
> On Sat, Mar 19, 2011 at 12:44 AM, aslak hellesoy
> <aslak.helle...@gmail.com>wrote:
>
>
>
>
>
> > Hi folks,
>
> > I'm finally starting to get somewhere on Gherkin for Javascript
> > (https://github.com/aslakhellesoy/gherkin/issues#issue/38). I have
> > managed to get Ragel to generate the Gherkin lexer in Javascript. It's
> > all on my javascript branch. The next step is to get all of the
> > existing solid specs and features to validate its correctness. This
> > can be done with therubyracer - a Ruby<->V8 Javascript bridge.
>
> > The short README_JAVASCRIPT.md file should be enough to get you up and
> > running and try out this little example:
>
> >https://github.com/aslakhellesoy/gherkin/blob/javascript/js/example/p...
> > (runs on node.js)
> > In theory, this should do more or less the same:
>
> >https://github.com/aslakhellesoy/gherkin/blob/javascript/js/example/p...
Reply all
Reply to author
Forward
0 new messages