Skip to content

Commit

Permalink
Fix source map spec
Browse files Browse the repository at this point in the history
Implementation switched from the header to the magic comment.
  • Loading branch information
elia committed Nov 2, 2013
1 parent e7138dd commit c7af4a8
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
20 changes: 16 additions & 4 deletions spec/integration/source_map_spec.rb
Expand Up @@ -2,17 +2,23 @@
require 'opal/source_map'

describe Opal::SourceMap do
before { get '/assets/source_map_example.js' }
before do
expect(Rails.application.config.opal.source_map_enabled).to be_true
get '/assets/source_map_example.js'
end

let(:map_url) { extract_map_url(response) }

let(:map_body) do
get response.headers['X-SourceMap']
get map_url
raise "#{response.status}\n\n#{response.body}" unless response.success?
response.body
end

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

it 'has the source map header' do
expect(response.headers['X-SourceMap']).to be_present
it 'has the source map header or magic comment' do
expect(extract_map_url(response)).to be_present
end

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


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

end
3 changes: 3 additions & 0 deletions test_app/config/application.rb
Expand Up @@ -68,5 +68,8 @@ class Application < Rails::Application

# Version of your assets, change this if you want to expire all your assets
config.assets.version = '1.0'

# Disabled by default, we need it for tests
config.opal.source_map_enabled = true
end
end

0 comments on commit c7af4a8

Please sign in to comment.