have node retrieve js files via ws instead of http
This commit is contained in:
parent
fcb3e2e83f
commit
75f6ebdcf5
@ -1,3 +1,5 @@
|
||||
require 'flowerbox/reporter/base'
|
||||
|
||||
module Flowerbox::Reporter
|
||||
class ConsoleBase < Base
|
||||
include FileDisplay
|
||||
|
@ -1,3 +1,5 @@
|
||||
require 'flowerbox/reporter/console_base'
|
||||
|
||||
module Flowerbox::Reporter
|
||||
class Verbose < ConsoleBase
|
||||
def initialize
|
||||
|
@ -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
|
||||
|
@ -66,27 +66,16 @@ jsdom.env(
|
||||
|
||||
var gotFlowerbox = false;
|
||||
|
||||
var socket = new ws('ws://localhost:#{server.port + 1}/');
|
||||
socket.onopen = function() {
|
||||
var files = #{sprockets.files.to_json};
|
||||
var fileRunner = function() {
|
||||
|
||||
var fileLoader = function() {
|
||||
if (files.length > 0) {
|
||||
var file = files.shift();
|
||||
|
||||
var options = {
|
||||
host: "localhost",
|
||||
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);
|
||||
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();
|
||||
};
|
||||
|
||||
request.end();
|
||||
socket.send(JSON.stringify(['load', file]));
|
||||
} else {
|
||||
context.Flowerbox.socket = new ws('ws://localhost:#{server.port + 1}/');
|
||||
context.Flowerbox.socket.onopen = function() {
|
||||
socket.onmessage = null;
|
||||
|
||||
#{env}
|
||||
|
||||
var waitForFinish;
|
||||
@ -118,10 +107,11 @@ jsdom.env(
|
||||
}
|
||||
};
|
||||
waitForFinish();
|
||||
};
|
||||
}
|
||||
};
|
||||
fileRunner();
|
||||
|
||||
fileLoader();
|
||||
};
|
||||
});
|
||||
JS
|
||||
end
|
||||
|
@ -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
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user