Discussion:
[Cucumber] [JS] require.js support for cucumber.js
renier
2012-05-24 22:01:01 UTC
Permalink
Hello,

This email is meant to get a feel of the level of interest and potential
concerns with making cucumber.js loadable with require.js-style functions
in the browser.

Currently running cucumber.js in the browser depends on running a node.js
server. The current approach is to use Browserify (a node module) to create
the commonjs functions (require, define) that the browser can use to load
the cucumber library, plus it inlines the whole library using these
functions.

While this allows cucumber.js to run in a browser, the global definition of
the require/define functions creates conflicts in the browser if you are
already using a JavaScript toolkit with AMD support that defines these
functions. Cucumber should be able to run within a browser without any
server runtime restrictions other than static file serving. It should also
work with any set of require/define functions without needing to specify
its own.

require.js support for cucumber.js means that we remove the hard dependency
on node without harming the ability to run within node. So if you are
already using a browser JavaScript toolkit that supports AMD (e.g. jQuery,
Dojo, require.js, etc.), you could load the cucumber.js library from
anywhere (like a CDN site) and have it work seamlessly with your other
loaded modules.

This support actually already exists at
https://github.com/cucumber/cucumber-js/tree/requirejs. Need people to try
the example out and comment on the general approach. A quick summary below:

* With the exception of the CLI library (which needs a server-side
JavaScript runtime anyway and which better than Node or any other strict
commonjs implementation), wrap all the modules in require.js-style
functions that return a reference to their export.

* Use the amdefine[1] node module to make modules wrapped in a
require.js-style function still loadable by node.

That's pretty much it. Oh and this also makes cucumber.js embeddable in
your JavaScript projects and you can use any number of tools from any
number of toolkits to optimize/inline/minify the cucumber library as part
of your normal build practices or as a one-time-only thing.

This also makes it possible to inject cucumber into a web page using a
headless browser to run your acceptance tests. But that is another story :-)

Thoughts?

-Renier

[1] http://requirejs.org/docs/node.html#nodeModules

-- There are two rules:

1) Please prefix the subject with [Ruby], [JVM] or [JS]. This allows people to filter messages.
2) Please use interleaved answers http://en.wikipedia.org/wiki/Posting_style#Interleaved_style

You received this message because you are subscribed to the Google Groups Cukes group. To post to this group, send email to cukes-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org To unsubscribe from this group, send email to cukes+***@googlegroups.com. For more options, visit this group at https://groups.google.com/d/forum/cukes?hl=en
Julien Biezemans
2012-05-25 08:06:46 UTC
Permalink
Post by renier
Hello,
This email is meant to get a feel of the level of interest and potential
concerns with making cucumber.js loadable with require.js-style functions in
the browser.
Hi Renier,

Thank you for your post and contribution.
Post by renier
Currently running cucumber.js in the browser depends on running a node.js
server. The current approach is to use Browserify (a node module) to create
the commonjs functions (require, define) that the browser can use to load
the cucumber library, plus it inlines the whole library using these
functions.
One can actually require the *browserified* JS file without Node.js,
once it's been generated. The latest release is always available at
http://cucumber.no.de/cucumber.js.
Post by renier
While this allows cucumber.js to run in a browser, the global definition of
the require/define functions creates conflicts in the browser if you are
already using a JavaScript toolkit with AMD support that defines these
functions. Cucumber should be able to run within a browser without any
server runtime restrictions other than static file serving. It should also
work with any set of require/define functions without needing to specify its
own.
Agreed. I understand how the conflicting require() definitions can be
a bummer. I tried put the browserified bundle into a closure but we
then have to arbitrarily declare some stuff (Cucumber, cucumber-html)
globally so that it can be used by third parties. Not a valid option.
Post by renier
require.js support for cucumber.js means that we remove the hard dependency
on node without harming the ability to run within node. So if you are
already using a browser JavaScript toolkit that supports AMD (e.g. jQuery,
Dojo, require.js, etc.), you could load the cucumber.js library from
anywhere (like a CDN site) and have it work seamlessly with your other
loaded modules.
This support actually already exists at
https://github.com/cucumber/cucumber-js/tree/requirejs. Need people to try
* With the exception of the CLI library (which needs a server-side
JavaScript runtime anyway and which better than Node or any other strict
commonjs implementation), wrap all the modules in require.js-style functions
that return a reference to their export.
* Use the amdefine[1] node module to make modules wrapped in a
require.js-style function still loadable by node.
That's pretty much it. Oh and this also makes cucumber.js embeddable in your
JavaScript projects and you can use any number of tools from any number of
toolkits to optimize/inline/minify the cucumber library as part of your
normal build practices or as a one-time-only thing.
This also makes it possible to inject cucumber into a web page using a
headless browser to run your acceptance tests. But that is another story :-)
Thoughts?
I read many blog posts and articles about require.js and AMD. AMD is a
hot topic; strong opinions are being expressed from both opponents
(http://tomdale.net/2012/01/amd-is-not-the-answer/) and supporters
(http://geddesign.com/post/15994566577/amd-is-the-answer). Quite
frankly, due to my lack of experience with those, I can't yet decide
whether require.js support in Cucumber would be *good*, *bad*,
harmless or not.

Are there any drawbacks/potential issues introduced by require.js we
should be aware of? Could the define/require methods clash with some
other known frameworks/libs?

Oh and one little thing, the clutter it adds to the top of every
source file is just awful ;)

-- Julien.
Post by renier
        -Renier
[1] http://requirejs.org/docs/node.html#nodeModules
1) Please prefix the subject with [Ruby], [JVM] or [JS]. This allows people
to filter messages.
2) Please use interleaved answers
http://en.wikipedia.org/wiki/Posting_style#Interleaved_style
You received this message because you are subscribed to the Google Groups
unsubscribe from this group, send email to
https://groups.google.com/d/forum/cukes?hl=en
-- There are two rules:

1) Please prefix the subject with [Ruby], [JVM] or [JS]. This allows people to filter messages.
2) Please use interleaved answers http://en.wikipedia.org/wiki/Posting_style#Interleaved_style

You received this message because you are subscribed to the Google Groups Cukes group. To post to this group, send email to cukes-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org To unsubscribe from this group, send email to cukes+***@googlegroups.com. For more options, visit this group at https://groups.google.com/d/forum/cukes?hl=en
renier
2012-05-25 22:25:28 UTC
Permalink
On Friday, May 25, 2012 4:06:46 AM UTC-4, Julien Biezemans wrote:
<snip>
Post by renier
Post by renier
Currently running cucumber.js in the browser depends on running a
node.js
Post by renier
server. The current approach is to use Browserify (a node module) to
create
Post by renier
the commonjs functions (require, define) that the browser can use to
load
Post by renier
the cucumber library, plus it inlines the whole library using these
functions.
One can actually require the *browserified* JS file without Node.js,
once it's been generated. The latest release is always available at
http://cucumber.no.de/cucumber.js.
Yes, that's true. But, apart from having to live with Browserify's own
version of require/define, you also have to live with the optimization that
it does of the code. If you want to tweak the optimization to be different
(e.g. add variable obfuscation, remove newlines, etc.), you have to spin up
Node to regenerate it. Whether one-time or dynamically.

<snip>
Post by renier
Post by renier
require.js support for cucumber.js means that we remove the hard
dependency
Post by renier
on node without harming the ability to run within node. So if you are
already using a browser JavaScript toolkit that supports AMD (e.g.
jQuery,
Post by renier
Dojo, require.js, etc.), you could load the cucumber.js library from
anywhere (like a CDN site) and have it work seamlessly with your other
loaded modules.
This support actually already exists at
https://github.com/cucumber/cucumber-js/tree/requirejs. Need people to
try
Post by renier
the example out and comment on the general approach. A quick summary
* With the exception of the CLI library (which needs a server-side
JavaScript runtime anyway and which better than Node or any other strict
commonjs implementation), wrap all the modules in require.js-style
functions
Post by renier
that return a reference to their export.
* Use the amdefine[1] node module to make modules wrapped in a
require.js-style function still loadable by node.
That's pretty much it. Oh and this also makes cucumber.js embeddable in
your
Post by renier
JavaScript projects and you can use any number of tools from any number
of
Post by renier
toolkits to optimize/inline/minify the cucumber library as part of your
normal build practices or as a one-time-only thing.
This also makes it possible to inject cucumber into a web page using a
headless browser to run your acceptance tests. But that is another story
:-)
Post by renier
Thoughts?
I read many blog posts and articles about require.js and AMD. AMD is a
hot topic; strong opinions are being expressed from both opponents
(http://tomdale.net/2012/01/amd-is-not-the-answer/) and supporters
(http://geddesign.com/post/15994566577/amd-is-the-answer). Quite
frankly, due to my lack of experience with those, I can't yet decide
whether require.js support in Cucumber would be *good*, *bad*,
harmless or not.
The good and harmless would be to make the library flexibly embeddable and
injectable in any browser environment, without changing how you load it and
use it in node.js.

Specifically, Tom's concerns about AMD, from the amd-is-not-the-answer
post, basically boils down to this (all the other concerns are very well
refuted in the comments I think):
"Too much ceremony" - meaning, having to wrap the module code in a function.

But in fact, the practice of wrapping module code for the browser in a
self-executing anonymous function is a commonly used best practice to avoid
clutter in the global namespace (which is not a problem in Node). From that
to the require ceremony there is less than half a step of distance.
Post by renier
Are there any drawbacks/potential issues introduced by require.js we
should be aware of? Could the define/require methods clash with some
other known frameworks/libs?
For sure. Also, if you want to do an AMD build of everything, having to
deal with disparate loading mechanism becomes a mountainous obstacle. With
a require.js-style loader, you at least have a level of standard that is
supported by several js builders.
Post by renier
Oh and one little thing, the clutter it adds to the top of every
source file is just awful ;)
I suppose code aesthetics are a subjective issue. You can enforce some if
it with good coding guidelines, but beyond that it is up for grabs.

Here I think we just have to evaluate whether that extra padding, which
enables loading from both node.js and web require.js-style, is worth it.


Saludos,

-Renier

-- There are two rules:

1) Please prefix the subject with [Ruby], [JVM] or [JS]. This allows people to filter messages.
2) Please use interleaved answers http://en.wikipedia.org/wiki/Posting_style#Interleaved_style

You received this message because you are subscribed to the Google Groups Cukes group. To post to this group, send email to cukes-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org To unsubscribe from this group, send email to cukes+***@googlegroups.com. For more options, visit this group at https://groups.google.com/d/forum/cukes?hl=en
Christopher R. Wedman
2012-05-27 03:59:38 UTC
Permalink
Post by renier
Hello,
This email is meant to get a feel of the level of interest and potential
concerns with making cucumber.js loadable with require.js-style functions
in the browser.
Currently, I'm interested in using cucumber.js with the Dojo Toolkit in
the browser. If I have any concerns, it would be how to weigh rolling your
changes into the original source versus maintaining a fork.

<snip>
Post by renier
This support actually already exists at
https://github.com/cucumber/cucumber-js/tree/requirejs. Need people to
try the example out and comment on the general approach. A quick summary
* With the exception of the CLI library (which needs a server-side
JavaScript runtime anyway and which better than Node or any other strict
commonjs implementation), wrap all the modules in require.js-style
functions that return a reference to their export.
* Use the amdefine[1] node module to make modules wrapped in a
require.js-style function still loadable by node.
That's pretty much it. Oh and this also makes cucumber.js embeddable in
your JavaScript projects and you can use any number of tools from any
number of toolkits to optimize/inline/minify the cucumber library as part
of your normal build practices or as a one-time-only thing.
I'm actually using your fork, but haven't yet inspected your
implementation enough to comment, except to say that it is working for me.
Post by renier
This also makes it possible to inject cucumber into a web page using a
headless browser to run your acceptance tests. But that is another story :-)
...another story that I'm also interested in. :)
Post by renier
Thoughts?
-Renier
[1] http://requirejs.org/docs/node.html#nodeModules
-- There are two rules:

1) Please prefix the subject with [Ruby], [JVM] or [JS]. This allows people to filter messages.
2) Please use interleaved answers http://en.wikipedia.org/wiki/Posting_style#Interleaved_style

You received this message because you are subscribed to the Google Groups Cukes group. To post to this group, send email to cukes-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org To unsubscribe from this group, send email to cukes+***@googlegroups.com. For more options, visit this group at https://groups.google.com/d/forum/cukes?hl=en
renier
2012-06-01 23:11:03 UTC
Permalink
Post by Christopher R. Wedman
Post by renier
Hello,
This email is meant to get a feel of the level of interest and potential
concerns with making cucumber.js loadable with require.js-style functions
in the browser.
Currently, I'm interested in using cucumber.js with the Dojo Toolkit in
the browser. If I have any concerns, it would be how to weigh rolling your
changes into the original source versus maintaining a fork.
Christopher,

I'm keeping the requirejs branch in sync with upstream here:
https://github.com/renier/cucumber-js/tree/requirejs

--Renier

-- There are two rules:

1) Please prefix the subject with [Ruby], [JVM] or [JS]. This allows people to filter messages.
2) Please use interleaved answers http://en.wikipedia.org/wiki/Posting_style#Interleaved_style

You received this message because you are subscribed to the Google Groups Cukes group. To post to this group, send email to cukes-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org To unsubscribe from this group, send email to cukes+***@googlegroups.com. For more options, visit this group at https://groups.google.com/d/forum/cukes?hl=en
Julien Biezemans
2012-06-02 10:06:32 UTC
Permalink
On Sat, Jun 2, 2012 at 1:11 AM, renier
Post by renier
Post by Christopher R. Wedman
Post by renier
Hello,
This email is meant to get a feel of the level of interest and potential
concerns with making cucumber.js loadable with require.js-style
functions in
Post by renier
Post by Christopher R. Wedman
Post by renier
the browser.
Currently, I'm interested in using cucumber.js with the Dojo Toolkit in
the browser. If I have any concerns, it would be how to weigh rolling your
changes into the original source versus maintaining a fork.
Christopher,
https://github.com/renier/cucumber-js/tree/requirejs
As no strong arguments were raised against require.js up until now, we'll
merge support for it soon. If you don't like the idea, please let us know
quickly.
Post by renier
--Renier
1) Please prefix the subject with [Ruby], [JVM] or [JS]. This allows
people
Post by renier
to filter messages.
2) Please use interleaved answers
http://en.wikipedia.org/wiki/Posting_style#Interleaved_style
You received this message because you are subscribed to the Google Groups
To
Post by renier
unsubscribe from this group, send email to
visit this group at
Post by renier
https://groups.google.com/d/forum/cukes?hl=en
-- There are two rules:

1) Please prefix the subject with [Ruby], [JVM] or [JS]. This allows people to filter messages.
2) Please use interleaved answers http://en.wikipedia.org/wiki/Posting_style#Interleaved_style

You received this message because you are subscribed to the Google Groups Cukes group. To post to this group, send email to cukes-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org To unsubscribe from this group, send email to cukes+***@googlegroups.com. For more options, visit this group at https://groups.google.com/d/forum/cukes?hl=en
Patrick Berkeley
2012-12-06 17:08:58 UTC
Permalink
I like the idea of cucumber.js supporting require.js modules. Any update on
how renier's integration effort is going?
Post by renier
Post by renier
Post by Christopher R. Wedman
Post by renier
Hello,
This email is meant to get a feel of the level of interest and
potential
Post by renier
Post by Christopher R. Wedman
Post by renier
concerns with making cucumber.js loadable with require.js-style
functions in
Post by renier
Post by Christopher R. Wedman
Post by renier
the browser.
Currently, I'm interested in using cucumber.js with the Dojo Toolkit
in
Post by renier
Post by Christopher R. Wedman
the browser. If I have any concerns, it would be how to weigh rolling
your
Post by renier
Post by Christopher R. Wedman
changes into the original source versus maintaining a fork.
Christopher,
https://github.com/renier/cucumber-js/tree/requirejs
As no strong arguments were raised against require.js up until now, we'll
merge support for it soon. If you don't like the idea, please let us know
quickly.
Post by renier
--Renier
1) Please prefix the subject with [Ruby], [JVM] or [JS]. This allows
people
Post by renier
to filter messages.
2) Please use interleaved answers
http://en.wikipedia.org/wiki/Posting_style#Interleaved_style
You received this message because you are subscribed to the Google Groups
To
Post by renier
unsubscribe from this group, send email to
at
Post by renier
https://groups.google.com/d/forum/cukes?hl=en
--
-- Rules --

1) Please prefix the subject with [Ruby], [JVM] or [JS].
2) Please use interleaved answers http://en.wikipedia.org/wiki/Posting_style#Interleaved_style
3) If you have a question, don't reply to an existing message. Start a new topic instead.

You received this message because you are subscribed to the Google Groups Cukes group. To post to this group, send email to cukes-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org To unsubscribe from this group, send email to cukes+***@googlegroups.com. For more options, visit this group at https://groups.google.com/d/forum/cukes?hl=en
Julien Biezemans
2012-12-06 20:01:05 UTC
Permalink
Received: by 10.180.91.38 with SMTP id cb6mr1316876wib.7.1354824093677;
Thu, 06 Dec 2012 12:01:33 -0800 (PST)
X-BeenThere: cukes-/***@public.gmane.org
Received: by 10.181.13.78 with SMTP id ew14ls2647647wid.20.canary; Thu, 06 Dec
2012 12:01:32 -0800 (PST)
Received: by 10.180.93.6 with SMTP id cq6mr742341wib.2.1354824092106;
Thu, 06 Dec 2012 12:01:32 -0800 (PST)
Received: by 10.180.93.6 with SMTP id cq6mr742340wib.2.1354824092096;
Thu, 06 Dec 2012 12:01:32 -0800 (PST)
Received: from outmail149113.authsmtp.com (outmail149113.authsmtp.com. [62.13.149.113])
by gmr-mx.google.com with ESMTP id cn1si1062029wib.1.2012.12.06.12.01.31;
Thu, 06 Dec 2012 12:01:31 -0800 (PST)
Received-SPF: neutral (google.com: 62.13.149.113 is neither permitted nor denied by best guess record for domain of jb-35/tczEXBqHQT0dZR+***@public.gmane.org) client-ipb.13.149.113;
Received: from mail-c226.authsmtp.com (mail-c226.authsmtp.com [62.13.128.226])
by punt5.authsmtp.com (8.14.2/8.14.2/Kp) with ESMTP id qB6K1VVu074159
for <cukes-/***@public.gmane.org>; Thu, 6 Dec 2012 20:01:31 GMT
Received: from mail-ie0-f177.google.com (mail-ie0-f177.google.com [209.85.223.177])
(authenticated bits=0)
by mail.authsmtp.com (8.14.2/8.14.2/) with ESMTP id qB6K1QC3097644
(version=TLSv1/SSLv3 cipher=RC4-SHA bits8 verifyúIL)
for <cukes-/***@public.gmane.org>; Thu, 6 Dec 2012 20:01:27 GMT
Received: by mail-ie0-f177.google.com with SMTP id k13so10953547iea.36
for <cukes-/***@public.gmane.org>; Thu, 06 Dec 2012 12:01:25 -0800 (PST)
Received: by 10.50.0.171 with SMTP id 11mr2804829igf.14.1354824085908; Thu, 06
Dec 2012 12:01:25 -0800 (PST)
Received: by 10.64.65.106 with HTTP; Thu, 6 Dec 2012 12:01:05 -0800 (PST)
In-Reply-To: <19dc90a7-ba35-45b4-82f6-be3533409e59-/***@public.gmane.org>
X-Server-Quench: b81395a6-3fdf-11e2-98a9-0025907ec6c5
X-AuthReport-Spam: If SPAM / abuse - report it at: http://www.authsmtp.com/abuse
X-AuthRoute: OCd3Zg8QA1ZXRiwY ADseCzQGQgIgMBZR AhIYBQRdJ1UNWAtL NVtCNRxYN1gKHQ8e dzNYRFZUUV9hW2N/ awtbbwITYEpHQQ1v TkpLQUxTEwJ3Axke B1BfIB8JdmQ1e355 YkBmWj5cWkJ8OxR1 Q01dEDwAeGQ2PDYC UUENdR5deFJDYx9F aFV2VHRYMmNUYzQC El17DBssNihaIilP d0k+D2knCVwGByM9 XR1EHy5nBlAdXyIp M1QoLURUF1saL0A4 PEFnW0lw
X-Authentic-SMTP: 61633436373530.1020:706
X-AuthFastPath: 0 (Was 255)
X-AuthSMTP-Origin: 209.85.223.177/25
X-AuthVirus-Status: No virus detected - but ensure you scan with your own anti-virus system.
X-Original-Sender: jb-35/tczEXBqHQT0dZR+***@public.gmane.org
X-Original-Authentication-Results: gmr-mx.google.com; spf=neutral (google.com:
62.13.149.113 is neither permitted nor denied by best guess record for domain
of jb-35/tczEXBqHQT0dZR+***@public.gmane.org) smtp.mail=jb-35/tczEXBqHQT0dZR+***@public.gmane.org
Precedence: list
Mailing-list: list cukes-/***@public.gmane.org; contact cukes+owners-/***@public.gmane.org
List-ID: <cukes.googlegroups.com>
X-Google-Group-Id: 178380748255
List-Post: <http://groups.google.com/group/cukes/post?hl=en>, <mailto:cukes-/***@public.gmane.org>
List-Help: <http://groups.google.com/support/?hl=en>, <mailto:cukes+help-/***@public.gmane.org>
List-Archive: <http://groups.google.com/group/cukes?hl=en>
Sender: cukes-/***@public.gmane.org
List-Subscribe: <http://groups.google.com/group/cukes/subscribe?hl=en>, <mailto:cukes+subscribe-/***@public.gmane.org>
List-Unsubscribe: <http://groups.google.com/group/cukes/subscribe?hl=en>, <mailto:googlegroups-manage+178380748255+unsubscribe-/***@public.gmane.org>
Archived-At: <http://permalink.gmane.org/gmane.comp.programming.tools.cucumber/12361>

On Thu, Dec 6, 2012 at 6:08 PM, Patrick Berkeley
Post by Patrick Berkeley
I like the idea of cucumber.js supporting require.js modules. Any update on
how renier's integration effort is going?
This has been put on hold because of an acceptable alternative way of
bundling cucumber for browsers (through browserify and a closure to
avoid polluting the global scope).

Do you have use cases for cucumber.js require.js support?
Post by Patrick Berkeley
Post by Julien Biezemans
Post by renier
Post by Christopher R. Wedman
Post by renier
Hello,
This email is meant to get a feel of the level of interest and potential
concerns with making cucumber.js loadable with require.js-style
functions in
the browser.
Currently, I'm interested in using cucumber.js with the Dojo Toolkit in
the browser. If I have any concerns, it would be how to weigh rolling your
changes into the original source versus maintaining a fork.
Christopher,
https://github.com/renier/cucumber-js/tree/requirejs
As no strong arguments were raised against require.js up until now, we'll
merge support for it soon. If you don't like the idea, please let us know
quickly.
Post by renier
--Renier
1) Please prefix the subject with [Ruby], [JVM] or [JS]. This allows
people
to filter messages.
2) Please use interleaved answers
http://en.wikipedia.org/wiki/Posting_style#Interleaved_style
You received this message because you are subscribed to the Google Groups
Cukes group. To post to this group, send email to
unsubscribe from this group, send email to
at
https://groups.google.com/d/forum/cukes?hl=en
--
-- Rules --
1) Please prefix the subject with [Ruby], [JVM] or [JS].
2) Please use interleaved answers
http://en.wikipedia.org/wiki/Posting_style#Interleaved_style
3) If you have a question, don't reply to an existing message. Start a new topic instead.
You received this message because you are subscribed to the Google Groups
unsubscribe from this group, send email to
https://groups.google.com/d/forum/cukes?hl=en
--
-- Rules --

1) Please prefix the subject with [Ruby], [JVM] or [JS].
2) Please use interleaved answers http://en.wikipedia.org/wiki/Posting_style#Interleaved_style
3) If you have a question, don't reply to an existing message. Start a new topic instead.

You received this message because you are subscribed to the Google Groups Cukes group. To post to this group, send email to cukes-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org To unsubscribe from this group, send email to cukes+***@googlegroups.com. For more options, visit this group at https://groups.google.com/d/forum/cukes?hl=en
Loading...