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
class ConsoleBase < Base
include FileDisplay

View File

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

View File

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

View File

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

View File

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