Skip to content

Commit

Permalink
Showing 5 changed files with 127 additions and 315 deletions.
1 change: 0 additions & 1 deletion lib/mspec/opal/new.html.erb

This file was deleted.

250 changes: 0 additions & 250 deletions lib/mspec/opal/rake_task.rb

This file was deleted.

168 changes: 110 additions & 58 deletions tasks/testing.rake
Original file line number Diff line number Diff line change
@@ -1,16 +1,117 @@
require_relative './testing/mspec_special_calls'

require 'rspec/core/rake_task'
RSpec::Core::RakeTask.new(:rspec) do |t|
t.pattern = 'spec/lib/**/*_spec.rb'
end

require 'mspec/opal/rake_task'
MSpec::Opal::RakeTask.new(:mspec_phantom) do |config|
config.pattern = ENV['MSPEC_PATTERN'] if ENV['MSPEC_PATTERN']
config.basedir = ENV['MSPEC_BASEDIR'] if ENV['MSPEC_BASEDIR']
module Testing
extend self

def stubs
%w[
mspec/helpers/tmp
mspec/helpers/environment
mspec/guards/block_device
mspec/guards/endian
]
end

def specs
excepting = []
rubyspecs = File.read('spec/rubyspecs').lines.reject do |l|
l.strip!
l.start_with?('#') || l.empty? || (l.start_with?('!') && excepting.push(l.sub('!', 'spec/') + '.rb'))
end.flat_map do |path|
path = "spec/#{path}"
File.directory?(path) ? Dir[path+'/*.rb'] : "#{path}.rb"
end - excepting

filters = Dir['spec/filters/**/*.rb']
shared = Dir['spec/{opal,lib/parser}/**/*_spec.rb'] + ['spec/lib/lexer_spec.rb']

specs = []
add_specs = ->(name, new_specs) { p [new_specs.size, name]; specs + new_specs}

specs = add_specs.(:filters, filters)
pattern = ENV['PATTERN']
whitelist_pattern = !!ENV['RUBYSPECS']

if pattern
custom = Dir[pattern]
custom &= rubyspecs if whitelist_pattern
specs = add_specs.(:custom, custom)
elsif ENV['SUITE'] == 'opal'
specs = add_specs.(:shared, shared)
elsif ENV['SUITE'] == 'rubyspec'
specs = add_specs.(:rubyspecs, rubyspecs)
else
warn 'Please provide at lease one of the following ENV vars:'
warn 'PATTERN # e.g. env PATTERN="spec/rubyspec/core/numeric/**_spec.rb"'
warn 'SUITE # can be either SUITE=opal or SUITE=rubyspec'
exit 1
end
end

def write_file(filename, specs, bm_filepath = nil)
requires = specs.map{|s| "require '#{s.sub(/^spec\//,'')}'"}

if bm_filepath
enter_benchmarking_mode = "OSpecRunner.main.bm!(#{Integer(ENV['BM'])}, '#{bm_filepath}')"
end

File.write filename, <<-RUBY
require 'spec_helper'
#{enter_benchmarking_mode}
#{requires.join("\n ")}
OSpecRunner.main.did_finish
RUBY
end

def bm_filepath
mkdir_p 'tmp/bench'
index = 0
begin
index += 1
bm_filepath = "tmp/bench/Spec#{index}"
end while File.exist?(bm_filepath)
end
end

task :mspec_phantom do
filename = File.expand_path('tmp/mspec_phantom.rb')
runner = "#{__dir__}/testing/phantomjs1-sprockets.js"
port = 9999
url = "http://localhost:#{port}/"

Testing.write_file filename, Testing.specs
mkdir_p File.dirname(filename)

Testing.stubs.each {|s| ::Opal::Processor.stub_file s }

Opal::Config.arity_check_enabled = true
Opal::Config.freezing_stubs_enabled = false
Opal::Config.tainting_stubs_enabled = false
Opal::Config.dynamic_require_severity = :error

Opal.use_gem 'mspec'
Opal.append_path 'spec'
Opal.append_path 'lib'
Opal.append_path File.dirname(filename)

app = Opal::Server.new { |s| s.main = File.basename(filename) }
server = Thread.new { Rack::Server.start(app: app, Port: port) }
sleep 1

begin
sh 'phantomjs', runner, url
ensure
server.kill if server.alive?
end
end

desc <<-DESC
Run the MSpec test suite on node
Run the MSpec test suite on Node.js
Use PATTERN and env var to manually set the glob for specs:
@@ -20,66 +121,17 @@ Use PATTERN and env var to manually set the glob for specs:
env PATTERN="spec/rubyspec/core/numeric/**_spec.rb" rake mspec_node
DESC
task :mspec_node do
excepting = []
rubyspecs = File.read('spec/rubyspecs').lines.reject do |l|
l.strip!; l.start_with?('#') || l.empty? || (l.start_with?('!') && excepting.push(l.sub('!', 'spec/') + '.rb'))
end.flat_map do |path|
path = "spec/#{path}"
File.directory?(path) ? Dir[path+'/*.rb'] : "#{path}.rb"
end - excepting

filters = Dir['spec/filters/**/*.rb']
shared = Dir['spec/{opal,lib/parser}/**/*_spec.rb'] + ['spec/lib/lexer_spec.rb']

specs = []
add_specs = ->(name, new_specs) { p [new_specs.size, name]; specs + new_specs}

specs = add_specs.(:filters, filters)
pattern = ENV['PATTERN']
whitelist_pattern = !!ENV['RUBYSPECS']

if pattern
custom = Dir[pattern]
custom &= rubyspecs if whitelist_pattern
specs = add_specs.(:custom, custom)
elsif ENV['SUITE'] == 'opal'
specs = add_specs.(:shared, shared)
elsif ENV['SUITE'] == 'rubyspec'
specs = add_specs.(:rubyspecs, rubyspecs)
else
warn 'Please provide at lease one of the following ENV vars:'
warn 'PATTERN # e.g. env PATTERN="spec/rubyspec/core/numeric/**_spec.rb"'
warn 'SUITE # can be either SUITE=opal or SUITE=rubyspec'
exit 1
end

requires = specs.map{|s| "require '#{s.sub(/^spec\//,'')}'"}
include_paths = '-Ispec -Ilib'

filename = 'tmp/mspec_node.rb'
js_filename = 'tmp/mspec_node.js'
mkdir_p File.dirname(filename)
bm_filepath = Testing.bm_filepath if ENV['BM']
Testing.write_file filename, Testing.specs, bm_filepath

if ENV['BM']
mkdir_p 'tmp/bench'
index = 0
begin
index += 1
bm_filepath = "tmp/bench/Spec#{index}"
end while File.exist?(bm_filepath)
enter_benchmarking_mode = "OSpecRunner.main.bm!(#{Integer(ENV['BM'])}, '#{bm_filepath}')"
end

File.write filename, <<-RUBY
require 'spec_helper'
#{enter_benchmarking_mode}
#{requires.join("\n ")}
OSpecRunner.main.did_finish
RUBY

stubs = '-smspec/helpers/tmp -smspec/helpers/environment -smspec/guards/block_device -smspec/guards/endian'
stubs = Testing.stubs.map{|s| "-s#{s}"}.join(' ')

sh "ruby -rbundler/setup -rmspec/opal/special_calls "\
sh "ruby -rbundler/setup -r#{__dir__}/testing/mspec_special_calls "\
"bin/opal -gmspec #{include_paths} #{stubs} -rnodejs/io -rnodejs/kernel -Dwarning -A #{filename} -c > #{js_filename}"
sh "NODE_PATH=stdlib/nodejs/node_modules node #{js_filename}"

File renamed without changes.
Original file line number Diff line number Diff line change
@@ -3,6 +3,17 @@
*/
var args = phantom.args;
var page = require('webpage').create();
var url = args[0];


/*
* Exit phantom instance "safely" see - https://github.com/ariya/phantomjs/issues/12697
* https://github.com/nobuoka/gulp-qunit/commit/d242aff9b79de7543d956e294b2ee36eda4bac6c
*/
function phantom_exit(code) {
page.close();
setTimeout(function () { phantom.exit(code); }, 0);
}

page.onConsoleMessage = function(msg) {
console.log(msg);
@@ -19,7 +30,7 @@ page.onCallback = function(data) {
switch (data[0]) {
case 'exit':
var status = data[1] || 0;
phantom.exit(status);
phantom_exit(status);
case 'stdout':
system.stdout.write(data[1] || '');
break;
@@ -31,25 +42,25 @@ page.onCallback = function(data) {
}
};

page.open(args[0], function(status) {
page.open(url, function(status) {
if (status !== 'success') {
console.error("Cannot load: " + args[0]);
phantom.exit(1);
console.error("Cannot load: " + url);
phantom_exit(1);
} else {
var timeout = parseInt(args[1] || 60000, 10);
var start = Date.now();
var interval = setInterval(function() {
if (Date.now() > start + timeout) {
console.error("Specs timed out");
phantom.exit(124);
phantom_exit(124);
} else {
var code = page.evaluate(function() {
return window.OPAL_SPEC_CODE;
});

if (code === 0 || code === 1) {
clearInterval(interval);
phantom.exit(code);
phantom_exit(code);
}
}
}, 500);

0 comments on commit de31de4

Please sign in to comment.