spade-runtime 0.1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +2 -0
- data/bin/spaderun +9 -0
- data/lib/spade-runtime.rb +1 -0
- data/lib/spade/runtime.rb +20 -0
- data/lib/spade/runtime/bundle.rb +173 -0
- data/lib/spade/runtime/cli.rb +7 -0
- data/lib/spade/runtime/cli/base.rb +181 -0
- data/lib/spade/runtime/compiler.rb +34 -0
- data/lib/spade/runtime/console.rb +39 -0
- data/lib/spade/runtime/context.rb +114 -0
- data/lib/spade/runtime/exports.rb +86 -0
- data/lib/spade/runtime/loader.rb +209 -0
- data/lib/spade/runtime/reactor.rb +159 -0
- data/lib/spade/runtime/server.rb +66 -0
- data/lib/spade/runtime/shell.rb +36 -0
- data/lib/spade/runtime/version.rb +5 -0
- data/spade-runtime.gemspec +36 -0
- data/spec/cli/update_spec.rb +64 -0
- data/spec/javascript/async-test.js +123 -0
- data/spec/javascript/compiler/javascript.js +13 -0
- data/spec/javascript/compiler/ruby.js +14 -0
- data/spec/javascript/loader-test.js +64 -0
- data/spec/javascript/normalize-test.js +73 -0
- data/spec/javascript/packages-test.js +44 -0
- data/spec/javascript/relative-require-test.js +72 -0
- data/spec/javascript/require-test.js +117 -0
- data/spec/javascript/sandbox/compile.js +37 -0
- data/spec/javascript/sandbox/creation.js +44 -0
- data/spec/javascript/sandbox/format.js +79 -0
- data/spec/javascript/sandbox/misc.js +57 -0
- data/spec/javascript/sandbox/preprocessor.js +81 -0
- data/spec/javascript/sandbox/require.js +48 -0
- data/spec/javascript/sandbox/run-command.js +21 -0
- data/spec/javascript/spade/externs.js +14 -0
- data/spec/javascript/spade/load-factory.js +15 -0
- data/spec/javascript/spade/misc.js +23 -0
- data/spec/javascript/spade/ready.js +12 -0
- data/spec/javascript/spade/register.js +13 -0
- data/spec/javascript_spec.rb +7 -0
- data/spec/spec_helper.rb +23 -0
- data/spec/support/cli.rb +109 -0
- data/spec/support/core_test.rb +61 -0
- data/spec/support/matchers.rb +12 -0
- data/spec/support/path.rb +62 -0
- metadata +218 -0
@@ -0,0 +1,81 @@
|
|
1
|
+
// ==========================================================================
|
2
|
+
// Project: Spade - CommonJS Runtime
|
3
|
+
// Copyright: ©2011 Strobe Inc. All rights reserved.
|
4
|
+
// License: Licened under MIT license (see __preamble__.js)
|
5
|
+
// ==========================================================================
|
6
|
+
|
7
|
+
var Ct = require('core-test/sync'),
|
8
|
+
Spade = require('spade').Spade,
|
9
|
+
Sandbox = require('spade').Sandbox;
|
10
|
+
|
11
|
+
Ct.module('spade: Sandbox preprocessor compilation');
|
12
|
+
|
13
|
+
Ct.setup(function(t) {
|
14
|
+
t.sandbox = new Sandbox(new Spade());
|
15
|
+
|
16
|
+
t.sandbox.spade.register('commenter', {
|
17
|
+
'name': 'commenter',
|
18
|
+
'plugin:preprocessors': ['commenter/preprocessor']
|
19
|
+
});
|
20
|
+
t.sandbox.spade.register('commenter/preprocessor',
|
21
|
+
"exports.compilePreprocessor = function(code, _, filename){ "+
|
22
|
+
"return '// From '+filename+'\\n'+code; "+
|
23
|
+
"};");
|
24
|
+
});
|
25
|
+
|
26
|
+
Ct.teardown(function(t) {
|
27
|
+
delete t.sandbox;
|
28
|
+
});
|
29
|
+
|
30
|
+
Ct.test('normal', function(t){
|
31
|
+
var pkg = t.sandbox.spade.package('commenter');
|
32
|
+
|
33
|
+
t.equal(t.sandbox.compilePreprocessors('var hello = "hi";', 'test_file.js', pkg), '// From test_file.js\nvar hello = "hi";');
|
34
|
+
});
|
35
|
+
|
36
|
+
Ct.test('multiple', function(t){
|
37
|
+
t.sandbox.spade.register('functionizer', {
|
38
|
+
'name': 'functionizer',
|
39
|
+
'dependencies': { 'commenter': '1.0' },
|
40
|
+
'plugin:preprocessors': ['functionizer/preprocessor', 'commenter/preprocessor']
|
41
|
+
});
|
42
|
+
t.sandbox.spade.register('functionizer/preprocessor',
|
43
|
+
"exports.compilePreprocessor = function(code){ "+
|
44
|
+
"return 'function(){ '+code+' };'; "+
|
45
|
+
"};");
|
46
|
+
|
47
|
+
var pkg = t.sandbox.spade.package('functionizer');
|
48
|
+
|
49
|
+
t.equal(t.sandbox.compilePreprocessors('var hello = "hi";', 'test_file.js', pkg), '// From test_file.js\nfunction(){ var hello = "hi"; };');
|
50
|
+
});
|
51
|
+
|
52
|
+
Ct.test("checks dependencies", function(t){
|
53
|
+
t.sandbox.spade.register('test', {
|
54
|
+
'name': 'test',
|
55
|
+
'dependencies': { 'commenter': '1.0' }
|
56
|
+
});
|
57
|
+
|
58
|
+
var pkg = t.sandbox.spade.package('test');
|
59
|
+
|
60
|
+
t.equal(t.sandbox.compilePreprocessors('var hello = "hi";', 'test_file.js', pkg), '// From test_file.js\nvar hello = "hi";');
|
61
|
+
});
|
62
|
+
|
63
|
+
Ct.test("only checks immediate dependencies", function(t){
|
64
|
+
t.sandbox.spade.register('intermediate', {
|
65
|
+
'name': 'intermediate',
|
66
|
+
'dependencies': { 'commenter': '1.0' }
|
67
|
+
});
|
68
|
+
t.sandbox.spade.register('test', {
|
69
|
+
'name': 'test',
|
70
|
+
'dependencies': { 'intermediate': '1.0' }
|
71
|
+
});
|
72
|
+
|
73
|
+
var pkg = t.sandbox.spade.package('test');
|
74
|
+
|
75
|
+
t.equal(t.sandbox.compilePreprocessors('var hello = "hi";', 'test_file.js', pkg), 'var hello = "hi";');
|
76
|
+
});
|
77
|
+
|
78
|
+
Ct.test("handles preprocessor loop");
|
79
|
+
|
80
|
+
Ct.test("proper order?");
|
81
|
+
|
@@ -0,0 +1,48 @@
|
|
1
|
+
// ==========================================================================
|
2
|
+
// Project: Spade - CommonJS Runtime
|
3
|
+
// Copyright: ©2011 Strobe Inc. All rights reserved.
|
4
|
+
// License: Licened under MIT license (see __preamble__.js)
|
5
|
+
// ==========================================================================
|
6
|
+
|
7
|
+
var Ct = require('core-test/sync'),
|
8
|
+
Spade = require('spade').Spade,
|
9
|
+
Sandbox = require('spade').Sandbox;
|
10
|
+
|
11
|
+
Ct.module('spade: Sandbox require');
|
12
|
+
|
13
|
+
Ct.setup(function(t) {
|
14
|
+
t.sandbox = new Sandbox(new Spade());
|
15
|
+
t.sandbox.spade.register('testing', { name: 'testing' });
|
16
|
+
t.sandbox.spade.register('testing/main', "exports.hello = 'hi';");
|
17
|
+
});
|
18
|
+
|
19
|
+
Ct.teardown(function(t) {
|
20
|
+
delete t.sandbox;
|
21
|
+
});
|
22
|
+
|
23
|
+
Ct.test("require new", function(t){
|
24
|
+
t.equal(t.sandbox.require('testing').hello, 'hi');
|
25
|
+
});
|
26
|
+
|
27
|
+
// NOTE: This test doesn't necessarily tell us that anything special is happening, just that it works
|
28
|
+
Ct.test("require existing", function(t){
|
29
|
+
// Cache it
|
30
|
+
t.sandbox.require('testing');
|
31
|
+
// Now require again
|
32
|
+
t.equal(t.sandbox.require('testing').hello, 'hi');
|
33
|
+
});
|
34
|
+
|
35
|
+
// TODO: I'm not actually sure how this should work - PW
|
36
|
+
Ct.test("require circular");
|
37
|
+
/*
|
38
|
+
Ct.test("require circular", function(t){
|
39
|
+
t.sandbox.spade.register('testing/file1', "exports.value = require('testing/file2').value * 2;");
|
40
|
+
t.sandbox.spade.register('testing/file2', "exports.value = require('testing/file1').value * 2;");
|
41
|
+
t.equal(t.sandbox.require('testing/file1').value, 4);
|
42
|
+
});
|
43
|
+
*/
|
44
|
+
|
45
|
+
Ct.test("throw if doesn't exist", function(t){
|
46
|
+
t.throws(function(){ t.sandbox.require('missing'); }, "Module missing not found");
|
47
|
+
});
|
48
|
+
|
@@ -0,0 +1,21 @@
|
|
1
|
+
// ==========================================================================
|
2
|
+
// Project: Spade - CommonJS Runtime
|
3
|
+
// Copyright: ©2011 Strobe Inc. All rights reserved.
|
4
|
+
// License: Licened under MIT license (see __preamble__.js)
|
5
|
+
// ==========================================================================
|
6
|
+
|
7
|
+
var Ct = require('core-test/sync'),
|
8
|
+
Spade = require('spade').Spade,
|
9
|
+
Sandbox = require('spade').Sandbox;
|
10
|
+
|
11
|
+
Ct.module('spade: Sandbox runCommand');
|
12
|
+
|
13
|
+
// TODO: Add the next 3 tests when adding Ruby and node.js support
|
14
|
+
Ct.test('success');
|
15
|
+
|
16
|
+
Ct.test('failure');
|
17
|
+
|
18
|
+
Ct.test('not supported');
|
19
|
+
|
20
|
+
// Not really sure how to test this, other than a bunch of stubbing
|
21
|
+
Ct.test('browser');
|
@@ -0,0 +1,14 @@
|
|
1
|
+
// ==========================================================================
|
2
|
+
// Project: Spade - CommonJS Runtime
|
3
|
+
// Copyright: ©2011 Strobe Inc. All rights reserved.
|
4
|
+
// License: Licened under MIT license (see __preamble__.js)
|
5
|
+
// ==========================================================================
|
6
|
+
//
|
7
|
+
|
8
|
+
var Ct = require('core-test/sync');
|
9
|
+
|
10
|
+
Ct.module('spade: Spade externs');
|
11
|
+
|
12
|
+
Ct.test('works');
|
13
|
+
|
14
|
+
|
@@ -0,0 +1,15 @@
|
|
1
|
+
// ==========================================================================
|
2
|
+
// Project: Spade - CommonJS Runtime
|
3
|
+
// Copyright: ©2011 Strobe Inc. All rights reserved.
|
4
|
+
// License: Licened under MIT license (see __preamble__.js)
|
5
|
+
// ==========================================================================
|
6
|
+
//
|
7
|
+
|
8
|
+
var Ct = require('core-test/sync');
|
9
|
+
|
10
|
+
Ct.module('spade: Spade loadFactory');
|
11
|
+
|
12
|
+
Ct.test('works');
|
13
|
+
|
14
|
+
|
15
|
+
|
@@ -0,0 +1,23 @@
|
|
1
|
+
// ==========================================================================
|
2
|
+
// Project: Spade - CommonJS Runtime
|
3
|
+
// Copyright: ©2011 Strobe Inc. All rights reserved.
|
4
|
+
// License: Licened under MIT license (see __preamble__.js)
|
5
|
+
// ==========================================================================
|
6
|
+
//
|
7
|
+
|
8
|
+
var Ct = require('core-test/sync');
|
9
|
+
|
10
|
+
Ct.module('spade: Spade miscellaneous');
|
11
|
+
|
12
|
+
Ct.test('globalize works');
|
13
|
+
|
14
|
+
Ct.test('noConflict works');
|
15
|
+
|
16
|
+
Ct.test('sandbox works');
|
17
|
+
|
18
|
+
Ct.test('factoryExists works');
|
19
|
+
|
20
|
+
Ct.test('package works');
|
21
|
+
|
22
|
+
|
23
|
+
|
@@ -0,0 +1,12 @@
|
|
1
|
+
// ==========================================================================
|
2
|
+
// Project: Spade - CommonJS Runtime
|
3
|
+
// Copyright: ©2011 Strobe Inc. All rights reserved.
|
4
|
+
// License: Licened under MIT license (see __preamble__.js)
|
5
|
+
// ==========================================================================
|
6
|
+
//
|
7
|
+
|
8
|
+
var Ct = require('core-test/sync');
|
9
|
+
|
10
|
+
Ct.module('spade: Spade ready');
|
11
|
+
|
12
|
+
Ct.test('works');
|
@@ -0,0 +1,13 @@
|
|
1
|
+
// ==========================================================================
|
2
|
+
// Project: Spade - CommonJS Runtime
|
3
|
+
// Copyright: ©2011 Strobe Inc. All rights reserved.
|
4
|
+
// License: Licened under MIT license (see __preamble__.js)
|
5
|
+
// ==========================================================================
|
6
|
+
//
|
7
|
+
|
8
|
+
var Ct = require('core-test/sync');
|
9
|
+
|
10
|
+
Ct.module('spade: Spade miscellaneous');
|
11
|
+
|
12
|
+
Ct.test('register works');
|
13
|
+
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
Bundler.require :default, :development
|
2
|
+
|
3
|
+
require 'support/cli'
|
4
|
+
require 'support/core_test'
|
5
|
+
require 'support/path'
|
6
|
+
require 'support/matchers'
|
7
|
+
|
8
|
+
RSpec.configure do |config|
|
9
|
+
working_dir = Dir.pwd
|
10
|
+
|
11
|
+
config.include SpecHelpers
|
12
|
+
|
13
|
+
config.around do |blk|
|
14
|
+
reset!
|
15
|
+
|
16
|
+
blk.call
|
17
|
+
|
18
|
+
kill!
|
19
|
+
Dir.chdir working_dir if Dir.pwd != working_dir
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
|
data/spec/support/cli.rb
ADDED
@@ -0,0 +1,109 @@
|
|
1
|
+
require 'spade/runtime'
|
2
|
+
require 'thor'
|
3
|
+
|
4
|
+
module SpecHelpers
|
5
|
+
attr_reader :stdin, :stdout, :stderr
|
6
|
+
|
7
|
+
# Dummy wrapper for testing
|
8
|
+
class CLI < Thor
|
9
|
+
desc "runtime", "Runtime commands"
|
10
|
+
subcommand "runtime", Spade::Runtime::CLI::Base
|
11
|
+
end
|
12
|
+
|
13
|
+
def env
|
14
|
+
@env ||= {}
|
15
|
+
end
|
16
|
+
|
17
|
+
def unthreaded_spade(*argv)
|
18
|
+
opts = Hash === argv.last ? argv.pop : {}
|
19
|
+
CLI.start(argv)
|
20
|
+
end
|
21
|
+
|
22
|
+
def spade(*argv)
|
23
|
+
opts = Hash === argv.last ? argv.pop : {}
|
24
|
+
|
25
|
+
kill!
|
26
|
+
create_pipes
|
27
|
+
|
28
|
+
@pid = Process.fork do
|
29
|
+
Dir.chdir opts[:chdir] if opts[:chdir]
|
30
|
+
|
31
|
+
@stdout.close
|
32
|
+
STDOUT.reopen @stdout_child
|
33
|
+
|
34
|
+
@stdin.close
|
35
|
+
STDIN.reopen @stdin_child
|
36
|
+
|
37
|
+
if opts[:track_stderr]
|
38
|
+
@stderr.close
|
39
|
+
STDERR.reopen @stderr_child
|
40
|
+
end
|
41
|
+
|
42
|
+
env.each do |key, val|
|
43
|
+
ENV[key] = val
|
44
|
+
end
|
45
|
+
|
46
|
+
CLI.start(argv)
|
47
|
+
end
|
48
|
+
|
49
|
+
@stdout_child.close
|
50
|
+
@stdin_child.close
|
51
|
+
@stderr_child.close
|
52
|
+
@pid
|
53
|
+
end
|
54
|
+
|
55
|
+
def out_until_block(io = stdout)
|
56
|
+
# read 1 first so we wait until the process is done processing the last write
|
57
|
+
chars = io.read(1)
|
58
|
+
|
59
|
+
loop do
|
60
|
+
chars << io.read_nonblock(1000)
|
61
|
+
sleep 0.05
|
62
|
+
end
|
63
|
+
rescue Errno::EAGAIN, EOFError
|
64
|
+
chars
|
65
|
+
end
|
66
|
+
|
67
|
+
def input(line, opts = {})
|
68
|
+
if on = opts[:on]
|
69
|
+
should_block_on on
|
70
|
+
end
|
71
|
+
stdin << "#{line}\n"
|
72
|
+
end
|
73
|
+
|
74
|
+
def wait
|
75
|
+
return unless @pid
|
76
|
+
|
77
|
+
pid, status = Process.wait2(@pid, 0)
|
78
|
+
|
79
|
+
@exit_status = status
|
80
|
+
@pid = nil
|
81
|
+
end
|
82
|
+
|
83
|
+
def exit_status
|
84
|
+
wait
|
85
|
+
@exit_status
|
86
|
+
end
|
87
|
+
|
88
|
+
def kill!
|
89
|
+
Process.kill(9, @pid) if @pid
|
90
|
+
end
|
91
|
+
|
92
|
+
def create_pipes
|
93
|
+
@stdout, @stdout_child = IO.pipe
|
94
|
+
@stdin_child, @stdin = IO.pipe
|
95
|
+
@stderr, @stderr_child = IO.pipe
|
96
|
+
end
|
97
|
+
|
98
|
+
def write_api_key(api_key)
|
99
|
+
write_creds("user@example.com", api_key)
|
100
|
+
end
|
101
|
+
|
102
|
+
def write_creds(email, api_key)
|
103
|
+
FileUtils.mkdir_p(spade_dir)
|
104
|
+
File.open(spade_dir("credentials"), "w") do |file|
|
105
|
+
file.write YAML.dump(:spade_api_key => api_key, :spade_email => email)
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
@@ -0,0 +1,61 @@
|
|
1
|
+
require 'spade/runtime/context'
|
2
|
+
|
3
|
+
RSpec::Matchers.define :be_ct_success do
|
4
|
+
match do |actual|
|
5
|
+
actual.first == 'passed'
|
6
|
+
end
|
7
|
+
|
8
|
+
failure_message_for_should do |actual|
|
9
|
+
actual.last
|
10
|
+
end
|
11
|
+
|
12
|
+
failure_message_for_should_not do |actual|
|
13
|
+
"expected not to be a success"
|
14
|
+
end
|
15
|
+
|
16
|
+
description do
|
17
|
+
"be a success"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
module RSpecCoreTest
|
22
|
+
def run_core_tests(path, &block)
|
23
|
+
describe "#{path}" do
|
24
|
+
rootdir = File.expand_path(File.join(__FILE__, '/../../../'));
|
25
|
+
context = Spade::Runtime::MainContext.new(:rootdir => rootdir) do |ctx|
|
26
|
+
ctx['checkRSpec'] = lambda do |status, test_info, message|
|
27
|
+
it "#{test_info.module.name}: #{test_info.name}" do
|
28
|
+
if status == 'warnings' && message == "Not Yet Implemented"
|
29
|
+
pending
|
30
|
+
else
|
31
|
+
[status.to_s, message.to_s].should be_ct_success
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
ctx.eval <<END
|
37
|
+
var Ct;
|
38
|
+
try {
|
39
|
+
Ct = require('core-test');
|
40
|
+
} catch (e) { }
|
41
|
+
|
42
|
+
if (Ct) {
|
43
|
+
RubyLogger = require('core-test/utils').extend(Ct.DefaultLogger, {
|
44
|
+
add: function(status, testInfo, message){
|
45
|
+
checkRSpec(status, testInfo, message);
|
46
|
+
}
|
47
|
+
});
|
48
|
+
Ct.defaultLogger = new RubyLogger('ruby');
|
49
|
+
|
50
|
+
require('file:#{path}');
|
51
|
+
|
52
|
+
Ct.run();
|
53
|
+
} else {
|
54
|
+
console.log("CoreTest is not installed. Use `spade install core-test`.");
|
55
|
+
}
|
56
|
+
END
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
RSpec::Core::ExampleGroup.extend(RSpecCoreTest)
|