look at that, jquery

This commit is contained in:
John Bintz 2012-02-29 15:16:55 -05:00
parent 230034ed16
commit e5dd9634a8
4 changed files with 50 additions and 36 deletions

2
.gitignore vendored
View File

@ -16,4 +16,4 @@ test/tmp
test/version_tmp test/version_tmp
tmp tmp
.tmp .tmp
node_modules/

View File

@ -8,17 +8,18 @@ module Flowerbox
def run(sprockets) def run(sprockets)
super super
file = Tempfile.new("node") file = File.join(Dir.pwd, ".node-tmp.#{Time.now.to_i}.js")
file.print template File.open(file, 'wb') { |fh| fh.print template.tap { |o| puts o } }
file.close
server.start server.start
system %{node #{file.path}} system %{node #{file}}
server.stop server.stop
$?.exitstatus $?.exitstatus
ensure
File.unlink(file) if file
end end
def template def template
@ -27,45 +28,54 @@ module Flowerbox
<<-JS <<-JS
var fs = require('fs'), var fs = require('fs'),
vm = require('vm'), vm = require('vm'),
http = require('http'); http = require('http'),
jsdom = require('jsdom');
// expand the sandbox a bit // expand the sandbox a bit
var context = function() {}; var context = function() {};
context.window = true;
for (method in global) { context[method] = global[method]; } for (method in global) { context[method] = global[method]; }
var files = #{sprockets.files.to_json}; jsdom.env(
var fileRunner = function() { "<html><head><title></title></head><body></body></html>", [], function(errors, window) {
if (files.length > 0) { context.window = window;
var file = files.shift();
console.log(file);
var options = { var files = #{sprockets.files.to_json};
host: "localhost", var fileRunner = function() {
port: #{server.port}, if (files.length > 0) {
path: "/__F__" + file, var file = files.shift();
method: "GET"
};
var request = http.request(options, function(response) { var options = {
var data = ''; host: "localhost",
port: #{server.port},
path: "/__F__" + file,
method: "GET"
};
response.on('data', function(chunk) { var request = http.request(options, function(response) {
data += chunk; 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() { request.end();
vm.runInNewContext(data, context, file); } else {
fileRunner(); #{env}
}); }
}); };
fileRunner();
request.end(); });
} else {
#{env}
}
};
fileRunner();
JS JS
end end
end end

View File

@ -1,10 +1,10 @@
Flowerbox.configure do |c| Flowerbox.configure do |c|
c.test_with :jasmine c.test_with :jasmine
c.run_with :selenium c.run_with :node
c.spec_patterns << "*_spec.*" c.spec_patterns << "*_spec.*"
c.spec_patterns << "**/*_spec.*" c.spec_patterns << "**/*_spec.*"
c.test_environment.reporters << "SimpleSeleniumReporter" c.test_environment.reporters << "SimpleNodeReporter"
end end

View File

@ -1,5 +1,9 @@
describe("cats", function() { describe("cats", function() {
it("should hiss", function() { it("should hiss", function() {
$("body").append("<div /");
console.log($('body').html())
expect("hiss").toEqual("hiss"); expect("hiss").toEqual("hiss");
}); });
}); });