diff --git a/.gitignore b/.gitignore
index 49f96a9..5875e07 100644
--- a/.gitignore
+++ b/.gitignore
@@ -16,4 +16,4 @@ test/tmp
test/version_tmp
tmp
.tmp
-
+node_modules/
diff --git a/lib/flowerbox/runner/node.rb b/lib/flowerbox/runner/node.rb
index 9ab893a..52984b4 100644
--- a/lib/flowerbox/runner/node.rb
+++ b/lib/flowerbox/runner/node.rb
@@ -8,17 +8,18 @@ module Flowerbox
def run(sprockets)
super
- file = Tempfile.new("node")
- file.print template
- file.close
+ file = File.join(Dir.pwd, ".node-tmp.#{Time.now.to_i}.js")
+ File.open(file, 'wb') { |fh| fh.print template.tap { |o| puts o } }
server.start
- system %{node #{file.path}}
+ system %{node #{file}}
server.stop
$?.exitstatus
+ ensure
+ File.unlink(file) if file
end
def template
@@ -27,45 +28,54 @@ module Flowerbox
<<-JS
var fs = require('fs'),
vm = require('vm'),
- http = require('http');
+ http = require('http'),
+ jsdom = require('jsdom');
// expand the sandbox a bit
var context = function() {};
-context.window = true;
for (method in global) { context[method] = global[method]; }
-var files = #{sprockets.files.to_json};
-var fileRunner = function() {
- if (files.length > 0) {
- var file = files.shift();
- console.log(file);
+jsdom.env(
+ "
", [], function(errors, window) {
+ context.window = window;
- var options = {
- host: "localhost",
- port: #{server.port},
- path: "/__F__" + file,
- method: "GET"
- };
+ var files = #{sprockets.files.to_json};
+ var fileRunner = function() {
+ if (files.length > 0) {
+ var file = files.shift();
- var request = http.request(options, function(response) {
- var data = '';
+ var options = {
+ host: "localhost",
+ port: #{server.port},
+ path: "/__F__" + file,
+ method: "GET"
+ };
- response.on('data', function(chunk) {
- data += chunk;
+ var request = http.request(options, function(response) {
+ var data = '';
+
+ response.on('data', function(chunk) {
+ data += chunk;
+ });
+
+ response.on('end', function() {
+ vm.runInNewContext(data, context, file);
+
+ for (thing in window) {
+ if (!context[thing]) { context[thing] = window[thing] }
+ }
+
+ fileRunner();
+ });
});
- response.on('end', function() {
- vm.runInNewContext(data, context, file);
- fileRunner();
- });
- });
-
- request.end();
- } else {
- #{env}
- }
-};
-fileRunner();
+ request.end();
+ } else {
+ #{env}
+ }
+ };
+ fileRunner();
+});
JS
end
end
diff --git a/spec/javascripts/spec_helper.rb b/spec/javascripts/spec_helper.rb
index 810b9a1..f807ee6 100644
--- a/spec/javascripts/spec_helper.rb
+++ b/spec/javascripts/spec_helper.rb
@@ -1,10 +1,10 @@
Flowerbox.configure do |c|
c.test_with :jasmine
- c.run_with :selenium
+ c.run_with :node
c.spec_patterns << "*_spec.*"
c.spec_patterns << "**/*_spec.*"
- c.test_environment.reporters << "SimpleSeleniumReporter"
+ c.test_environment.reporters << "SimpleNodeReporter"
end
diff --git a/spec/javascripts/test_spec.js b/spec/javascripts/test_spec.js
index 8d22fd9..82ad0d3 100644
--- a/spec/javascripts/test_spec.js
+++ b/spec/javascripts/test_spec.js
@@ -1,5 +1,9 @@
describe("cats", function() {
it("should hiss", function() {
+ $("body").append("