Skip to content

Commit

Permalink
Modularize Cucumber.js (close #3)
Browse files Browse the repository at this point in the history
- This temporarily limits Gherkin language support to English only. Browserify does not know how to handle dynamic module names and Gherkin is just doing that.
  • Loading branch information
jbpros committed Jul 17, 2011
1 parent 8d5940e commit f5396c5
Show file tree
Hide file tree
Showing 30 changed files with 799 additions and 752 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ And probably lots of other browsers.

## Play with it!

$ open example/index.html
$ node example/server.js

Then go to [localhost:9797](http://localhost:9797/).

## Setup for using in Node.js and running tests

Expand Down
17 changes: 1 addition & 16 deletions cucumber.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,4 @@ var supportCode = require(supportCodePath);
var cucumber = Cucumber(fs.readFileSync(process.ARGV[2]), supportCode);
var progressFormatter = Cucumber.Listener.ProgressFormatter;
cucumber.attachListener(progressFormatter());
cucumber.start(function() {
/*
Some "after" messages from the tree walker are still not processed when
the callback is triggered. It means that post-processing might still
be on hold on listeners. This is due to
Cucumber.TreeWalker.broadcastMessagesBeforeAndAfterFunction() using no
callback and expecting the passed function to handle the possible
callback.
Fixing this is easy: broadcastMessagesBeforeAndAfterFunction() would
need a callback and run it AFTER broadcasting "after" messages.
Uncomment the following line to see that behaviour:
*/
// console.log("Done. But too soon, some dudes haven't finished doing their stuff just yet.");
});
cucumber.start(function() {});
16 changes: 2 additions & 14 deletions example/example.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
function runFeature() {
var Cucumber = require('./cucumber');
var supportCode;
var output = $('#output');
var errors = $('#errors');
Expand All @@ -15,20 +16,7 @@ function runFeature() {
errorsContainer.hide();
try {
cucumber.start(function() {
/*
Some "after" messages from the tree walker are still not processed when
the callback is triggered. It means that post-processing might still
be on hold on listeners. This is due to
Cucumber.TreeWalker.broadcastMessagesBeforeAndAfterFunction() using no
callback and expecting the passed function to handle the possible
callback.
Fixing this is easy: broadcastMessagesBeforeAndAfterFunction() would
need a callback and run it AFTER broadcasting "after" messages.
Uncomment the following line to see that behaviour:
*/
//console.log("Done. But too soon, some dudes haven't finished doing their stuff just yet.");
console.log("Done.");
});
} catch(err) {
errorsContainer.show();
Expand Down
14 changes: 7 additions & 7 deletions example/index.html
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>Cucumber.js</title>
<link href="example.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="vendor/jquery-1.6.1.min.js"></script>
<script type="text/javascript" src="vendor/gherkin.en.js"></script>
<script type="text/javascript" src="../lib/cucumber.js"></script>
<script type="text/javascript" src="example.js"></script>
<script type="text/javascript" src="/browserify.js"></script>
<script type="text/javascript" src="/example.js"></script>
</head>
<body>
<h1>Cucumber.js</h1>
Expand All @@ -24,7 +24,7 @@ <h2>Feature source</h2>
Then the variable should contain 2</textarea>
<h2>Step definitions</h2>
<textarea id="step-definitions">var variable;

Given(/a variable set to (\d+)/, function(number, callback) {
variable = parseInt(number);
callback();
Expand All @@ -34,13 +34,13 @@ <h2>Step definitions</h2>
variable += parseInt(number);
callback();
});

Then(/the variable should contain (\d+)/, function(number, callback) {
if (variable != parseInt(number))
throw('Variable should contain '+number+' but it contains '+variable+'.');
callback();
});</textarea>

<h2>Output</h2>
<p><button id="run-feature">Run feature</button></p>
<textarea readonly="readonly" id="output"></textarea>
Expand Down
10 changes: 10 additions & 0 deletions example/server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
var connect = require('connect');
var server = connect.createServer();

server.use(connect.static(__dirname));
server.use(require('browserify')({
require : __dirname + '/../lib/cucumber.js'
}));

server.listen(9797);
console.log('Listening on 9797...');
Loading

0 comments on commit f5396c5

Please sign in to comment.