Sha256: ba7881ad2d16b142b94323deba9ba444eb214bd8b48d567b0128d15288fc0dd6

Contents?: true

Size: 1.46 KB

Versions: 5

Compression:

Stored size: 1.46 KB

Contents

require 'base64'
require 'spec_helper'
require 'opal/source_map'

describe Opal::SourceMap do
  let(:js_asset_path) { '/assets/source_map_example.debug.js' }

  before do
    expect(Rails.application.config.opal.source_map_enabled).to be_truthy
    expect(Rails.application.config.assets.compile).to be_truthy
    expect(Rails.application.assets).to be_present
    expect(Rails.application.config.assets.debug).to be_truthy
  end

  let(:map_body) do
    get js_asset_path

    inline_map_prefix = '//# sourceMappingURL=data:application/json;base64,'

    if response.body.lines.last.start_with? inline_map_prefix
      Base64.decode64(response.body.lines.last.split(inline_map_prefix, 2)[1])
    else
      source_map_regexp = %r{^//[@#] sourceMappingURL=([^\n]+)}

      header_map_path = response.headers['X-SourceMap'].presence
      comment_map_path = response.body.scan(source_map_regexp).flatten.first.to_s.strip.presence

      map_path = (header_map_path || comment_map_path)&.strip

      get URI.join("http://example.com/", js_asset_path, map_path).path

      expect(response).to be_successful, "url: #{map_path}\nstatus: #{response.status}"

      response.body
    end
  end

  let(:map) { JSON.parse(map_body, symbolize_names: true) }

  it 'has the source map be there' do
    expect(map).to be_present
    expect(map[:sections].size).to eq(1)
    expect(map[:sections][0][:map][:sources]).to be_present
    expect(map[:sections][0][:map][:mappings]).to be_present
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
opal-rails-2.0.4 spec/integration/source_map_spec.rb
opal-rails-2.0.3 spec/integration/source_map_spec.rb
opal-rails-2.0.2 spec/integration/source_map_spec.rb
opal-rails-2.0.1 spec/integration/source_map_spec.rb
opal-rails-2.0.0 spec/integration/source_map_spec.rb