Skip to content

Commit 412ffe8

Browse files
authored
Merge pull request #105 from opal/staging
16th Staging (Opal v1.6)
2 parents 85b5f6a + dd5b366 commit 412ffe8

12 files changed

+130
-37
lines changed

.github/workflows/build.yml

+13-8
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ jobs:
1717
combo:
1818
- name: Chromium/Linux/Opal-master
1919
opal: master
20+
opal-rspec: '1.0'
21+
- name: Chromium/Linux/Opal-1.6
22+
opal: 1.6
23+
opal-rspec: '1.0'
2024
- name: Chromium/Linux/Opal-1.5
2125
opal: 1.5
2226
- name: Chromium/Linux/Opal-1.5/PromiseV2
@@ -30,8 +34,8 @@ jobs:
3034
opal: '1.0'
3135
- name: Chromium/Linux/Ruby-head
3236
ruby: head
33-
- name: Chromium/Linux/Ruby-3.1
34-
ruby: 3.1
37+
- name: Chromium/Linux/Ruby-3.0
38+
ruby: '3.0'
3539
- name: Chromium/Linux/Ruby-2.7
3640
ruby: 2.7
3741
- name: Chromium/Linux/Ruby-2.6
@@ -62,20 +66,21 @@ jobs:
6266
- name: set environment variables
6367
run: |
6468
echo "OPAL_VERSION=${{ matrix.combo.opal || '1.5' }}" >> $GITHUB_ENV
69+
echo "OPAL_RSPEC_VERSION=${{ matrix.combo.opal-rspec || '' }}" >> $GITHUB_ENV
6570
echo "OPAL_BROWSER_PROMISE=${{ matrix.combo.promise || 'v1' }}" >> $GITHUB_ENV
6671
- uses: ruby/setup-ruby@v1
6772
with:
68-
ruby-version: ${{ matrix.combo.ruby || '3.0' }}
73+
ruby-version: ${{ matrix.combo.ruby || '3.1' }}
6974
- run: bundle lock
7075
- uses: actions/cache@v2
7176
with:
7277
path: ./vendor/bundle
73-
key: ${{ runner.os }}-${{ matrix.combo.ruby || '3.0' }}-gems-${{ matrix.combo.opal || '1.5' }}-${{ github.ref }}-${{ hashFiles('**/Gemfile.lock') }}
78+
key: ${{ runner.os }}-${{ matrix.combo.ruby || '3.1' }}-gems-${{ matrix.combo.opal || '1.5' }}-${{ github.ref }}-${{ hashFiles('**/Gemfile.lock') }}
7479
restore-keys: |
75-
${{ runner.os }}-${{ matrix.combo.ruby || '3.0' }}-gems-${{ matrix.combo.opal || '1.5' }}-${{ github.ref }}
76-
${{ runner.os }}-${{ matrix.combo.ruby || '3.0' }}-gems-${{ matrix.combo.opal || '1.5' }}-master
77-
${{ runner.os }}-${{ matrix.combo.ruby || '3.0' }}-gems-${{ matrix.combo.opal || '1.5' }}-
78-
${{ runner.os }}-${{ matrix.combo.ruby || '3.0' }}-gems-
80+
${{ runner.os }}-${{ matrix.combo.ruby || '3.1' }}-gems-${{ matrix.combo.opal || '1.5' }}-${{ github.ref }}
81+
${{ runner.os }}-${{ matrix.combo.ruby || '3.1' }}-gems-${{ matrix.combo.opal || '1.5' }}-master
82+
${{ runner.os }}-${{ matrix.combo.ruby || '3.1' }}-gems-${{ matrix.combo.opal || '1.5' }}-
83+
${{ runner.os }}-${{ matrix.combo.ruby || '3.1' }}-gems-
7984
- name: bundle install
8085
run: |
8186
bundle config path $PWD/vendor/bundle

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.3.4
2+
* DOM::Element::Form: #valid?, #request_submit, #ajax_submit
3+
* Compatibility for Opal-RSpec 1.0
4+
15
## 0.3.3
26
* Compatibility fix for Opal 1.4
37

Gemfile

+10-3
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,14 @@ gem 'rake'
66
gem 'rack'
77
gem 'sinatra'
88
gem 'sinatra-websocket'
9-
gem 'opal-rspec'
10-
gem 'opal-sprockets'
9+
case ENV['OPAL_RSPEC_VERSION']
10+
when nil, ''
11+
gem 'opal-rspec'
12+
when /\./
13+
gem 'opal-rspec', "~> #{ENV['OPAL_RSPEC_VERSION']}.0a"
14+
else
15+
gem 'opal', github: 'opal/opal', ref: ENV['OPAL_VERSION']
16+
end
1117
# Force build of eventmachine... I wish we could find a way to not use
1218
# this unmaintained library anymore.
1319
gem 'eventmachine', github: 'eventmachine/eventmachine'
@@ -18,10 +24,11 @@ gem 'selenium-webdriver', require: false
1824
gem 'rest-client', require: false
1925
gem 'webdrivers', require: false
2026
gem 'rexml', require: false
27+
gem 'ffi'
2128

2229
# browser
2330
case ENV['OPAL_VERSION']
24-
when nil
31+
when nil, ''
2532
# noop
2633
when ->(path) { File.exist? path }
2734
gem 'opal', path: ENV['OPAL_VERSION']

config.ru

+19-12
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,24 @@ Bundler.require
33

44
apps = []
55

6-
sprockets_env = Opal::RSpec::SprocketsEnvironment.new(spec_pattern = 'spec/**/*_spec.{rb,opal}',
7-
spec_exclude_pattern = nil,
8-
spec_files = nil,
9-
default_path = 'spec')
10-
11-
apps << Opal::Sprockets::Server.new(sprockets: sprockets_env) { |s|
12-
s.main = 'opal/rspec/sprockets_runner'
13-
s.append_path 'spec'
14-
s.index_path = 'index.html.erb'
15-
s.debug = true
16-
}
6+
require 'opal/rspec'
7+
8+
Opal::Config.arity_check_enabled = true
9+
Opal::Config.enable_source_location = true if Opal::Config.respond_to? :enable_file_source_location=
10+
Opal::Config.enable_file_source_embed = true if Opal::Config.respond_to? :enable_file_source_embed=
11+
12+
Opal.append_path "#{__dir__}/spec"
13+
14+
apps << Opal::SimpleServer.new do |s|
15+
require_relative './spec/browser_runner_compat'
16+
17+
$locator = Opal::RSpec::Locator.new(
18+
pattern: 'spec/**/*_spec.{rb,opal}',
19+
default_path: 'spec'
20+
)
21+
22+
s.index_path = 'spec/browser_runner_index.html.erb'
23+
end
1724

1825
apps << Class.new(Sinatra::Base) {
1926
get '/http' do
@@ -78,4 +85,4 @@ apps << Class.new(Sinatra::Base) {
7885
end
7986
}
8087

81-
run Rack::Cascade.new(apps)
88+
run Rack::Cascade.new(apps.reverse)

opal/browser/dom/element/form.rb

+23-1
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,33 @@ def form_data
1010
FormData.create(self)
1111
end
1212

13-
# Submit a form. This will fire a submit event.
13+
# Returns true if form is valid, false otherwise
14+
def valid?
15+
`#@native.reportValidity()`
16+
end
17+
18+
# Submit a form. This will NOT fire a submit event.
1419
def submit
1520
`#@native.submit()`
1621
end
1722

23+
# Submit a form, optionally with a button argument.
24+
# This will fire a submit event.
25+
def request_submit(submitter = nil)
26+
if submitter
27+
`#@native.requestSubmit(#{submitter.to_n})`
28+
else
29+
`#@native.requestSubmit()`
30+
end
31+
end
32+
33+
# Submit a form using AJAX.
34+
def ajax_submit(&block)
35+
data = form_data
36+
data = data.to_h unless encoding == 'multipart/form-data'
37+
HTTP.send(method, target, form_data, &block)
38+
end
39+
1840
# Reset a form. This will fire a reset event.
1941
def reset
2042
`#@native.reset()`

spec/browser_runner.rb.erb

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# This file is used by Opal::SimpleServer to basically load all spec files that
2+
# can be found in the spec/ directory.
3+
4+
require 'opal'
5+
require 'opal-rspec'
6+
7+
<%
8+
$locator.get_opal_spec_requires.each do |s| %>
9+
require <%= s.split("/spec/").last.inspect %>
10+
<% end %>
11+
require 'opal/rspec/spec_opts'
12+
13+
::RSpec::Core::Runner.autorun
14+
::Kernel.exit

spec/browser_runner_compat.rb

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Compatiblity for Opal < 1.6
2+
3+
unless defined? Opal::BuilderProcessors::RubyERBProcessor
4+
# This handler is for files named ".rb.erb", which ought to
5+
# first get preprocessed via ERB, then via Opal.
6+
class Opal::BuilderProcessors::RubyERBProcessor < Opal::BuilderProcessors::RubyProcessor
7+
handles :"rb.erb"
8+
9+
def compiled
10+
@compiled ||= begin
11+
@source = ::ERB.new(@source.to_s).result
12+
module_name = ::Opal::Compiler.module_name(@filename)
13+
14+
compiler = compiler_for(@source, file: @filename)
15+
compiler.compile
16+
compiler
17+
end
18+
end
19+
end
20+
21+
Opal::Builder.processors.sort_by!.with_index do |processor,idx|
22+
if processor == Opal::BuilderProcessors::RubyERBProcessor
23+
# Move RubyERBProcessor to the front
24+
-1
25+
else
26+
idx
27+
end
28+
end
29+
end

index.html.erb renamed to spec/browser_runner_index.html.erb

+1-5
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,7 @@
1414
}
1515
</script>
1616

17-
<script src="spec/json2.js"></script>
18-
<script src="spec/sizzle.js"></script>
19-
<script src="spec/wgxpath.install.js"></script>
20-
21-
<%= javascript_include_tag @server.main %>
17+
<%= javascript_include_tag 'browser_runner' %>
2218
</body>
2319
</html>
2420

spec/database/sql_spec.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454

5555
promise = Browser::Promise.new
5656
sql.transaction {|t|
57-
expect(t.query('hue')).to be_a(Promise)
57+
expect(t.query('SELECT 1')).to be_a(Browser::Promise)
5858
promise.resolve
5959
}
6060
promise.for_rspec

spec/immediate_spec.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@
1212
promise.for_rspec
1313
end
1414
end
15-
end
15+
end if Opal::RSpec::VERSION.to_f >= 1.0

spec/runner.rb

+2-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@
6565
Selenium::WebDriver::Wait.new(timeout: 3000, interval: 30).until {
6666
print '.'
6767

68-
not browser['totals'].text.strip.empty?
68+
((not browser['totals'].text.strip.empty?) rescue false) &&
69+
(browser[css: '#duration strong'] rescue false)
6970
}
7071

7172
totals = browser['totals'].text

spec/spec_helper_promise.rb.erb

+13-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
<% if ENV['OPAL_BROWSER_PROMISE'] == 'v2' %>
1+
require 'opal/rspec/async'
2+
3+
<% if ENV['OPAL_BROWSER_PROMISE'] == 'v2' || Opal::VERSION.to_f >= 1.6 %>
24
require 'promise'
35
require 'promise/v2'
46
<% else %>
@@ -16,10 +18,16 @@ require 'browser/utils'
1618

1719
module Browser
1820
class Promise
19-
# Return a correct promise for opal-rspec, which for now is
20-
# PromiseV1 until opal-rspec is ported.
21+
# Return a correct promise for opal-rspec, which for RSpec
22+
# < 1.0 is PromiseV1, and for >= 1.0 is PromiseV2.
2123
def for_rspec
22-
to_v1
24+
<% if Opal::RSpec::VERSION.to_f >= 1.0 %>
25+
to_v2
26+
<% else %>
27+
to_v1
28+
<% end %>
2329
end
2430
end
25-
end
31+
end
32+
33+
Opal::RSpec::VERSION = <%= Opal::RSpec::VERSION.inspect %> unless defined? Opal::RSpec::VERSION

0 commit comments

Comments
 (0)