Skip to content

Commit c7af4a8

Browse files
committed
Fix source map spec
Implementation switched from the header to the magic comment.
1 parent e7138dd commit c7af4a8

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

spec/integration/source_map_spec.rb

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,23 @@
22
require 'opal/source_map'
33

44
describe Opal::SourceMap do
5-
before { get '/assets/source_map_example.js' }
5+
before do
6+
expect(Rails.application.config.opal.source_map_enabled).to be_true
7+
get '/assets/source_map_example.js'
8+
end
9+
10+
let(:map_url) { extract_map_url(response) }
611

712
let(:map_body) do
8-
get response.headers['X-SourceMap']
13+
get map_url
14+
raise "#{response.status}\n\n#{response.body}" unless response.success?
915
response.body
1016
end
1117

1218
let(:map) { JSON.parse(map_body) }
1319

14-
it 'has the source map header' do
15-
expect(response.headers['X-SourceMap']).to be_present
20+
it 'has the source map header or magic comment' do
21+
expect(extract_map_url(response)).to be_present
1622
end
1723

1824
it "the map is a valid json" do
@@ -27,4 +33,10 @@
2733
expect(pathname.exist?).to be_true
2834
end
2935

36+
37+
def extract_map_url response
38+
response.headers['X-SourceMap'] or
39+
response.body.scan(%r{^//@ sourceMappingURL=([^\n]+)}).flatten.first.strip
40+
end
41+
3042
end

test_app/config/application.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,5 +68,8 @@ class Application < Rails::Application
6868

6969
# Version of your assets, change this if you want to expire all your assets
7070
config.assets.version = '1.0'
71+
72+
# Disabled by default, we need it for tests
73+
config.opal.source_map_enabled = true
7174
end
7275
end

0 commit comments

Comments
 (0)