have node retrieve js files via ws instead of http

This commit is contained in:
John Bintz 2012-03-26 10:51:26 -04:00
parent fcb3e2e83f
commit 75f6ebdcf5
5 changed files with 30 additions and 30 deletions

View File

@ -1,3 +1,5 @@
require 'flowerbox/reporter/base'
module Flowerbox::Reporter module Flowerbox::Reporter
class ConsoleBase < Base class ConsoleBase < Base
include FileDisplay include FileDisplay

View File

@ -1,3 +1,5 @@
require 'flowerbox/reporter/console_base'
module Flowerbox::Reporter module Flowerbox::Reporter
class Verbose < ConsoleBase class Verbose < ConsoleBase
def initialize def initialize

View File

@ -32,6 +32,10 @@ module Flowerbox
Flowerbox.reporters Flowerbox.reporters
end end
def load(file)
sprockets.find_asset(file.first, :bundle => false).body
end
def ensure_alive def ensure_alive
while @count < MAX_COUNT && !finished? while @count < MAX_COUNT && !finished?
@count += 1 if @timer_running @count += 1 if @timer_running

View File

@ -66,27 +66,16 @@ jsdom.env(
var gotFlowerbox = false; var gotFlowerbox = false;
var socket = new ws('ws://localhost:#{server.port + 1}/');
socket.onopen = function() {
var files = #{sprockets.files.to_json}; var files = #{sprockets.files.to_json};
var fileRunner = function() {
var fileLoader = function() {
if (files.length > 0) { if (files.length > 0) {
var file = files.shift(); var file = files.shift();
var options = { socket.onmessage = function(data) {
host: "localhost", vm.runInNewContext(data.data, context, file);
port: #{server.port},
path: "/__F__/" + file,
method: "GET"
};
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) { for (thing in window) {
if (!context[thing]) { context[thing] = window[thing] } if (!context[thing]) { context[thing] = window[thing] }
@ -95,18 +84,18 @@ jsdom.env(
if (!gotFlowerbox && context.Flowerbox) { if (!gotFlowerbox && context.Flowerbox) {
context.Flowerbox.environment = 'node'; context.Flowerbox.environment = 'node';
context.Flowerbox.UNKNOWN = '#{Flowerbox::Result::FileInfo::UNKNOWN}'; context.Flowerbox.UNKNOWN = '#{Flowerbox::Result::FileInfo::UNKNOWN}';
context.Flowerbox.socket = socket;
gotFlowerbox = true; gotFlowerbox = true;
} }
fileRunner(); fileLoader();
}); };
});
request.end(); socket.send(JSON.stringify(['load', file]));
} else { } else {
context.Flowerbox.socket = new ws('ws://localhost:#{server.port + 1}/'); socket.onmessage = null;
context.Flowerbox.socket.onopen = function() {
#{env} #{env}
var waitForFinish; var waitForFinish;
@ -118,10 +107,11 @@ jsdom.env(
} }
}; };
waitForFinish(); waitForFinish();
};
} }
}; };
fileRunner();
fileLoader();
};
}); });
JS JS
end end

View File

@ -43,7 +43,9 @@ module Flowerbox
ws.onmessage { |message| ws.onmessage { |message|
command, data = JSON.parse(message) command, data = JSON.parse(message)
runner.send(command, data.flatten) output = runner.send(command, [ data ].flatten)
ws.send(output) if command == 'load'
} }
end end