Sha256: 56051e34cca0c077de2ad2ca4788b3a8fce8cb6ceb252f921ac5d192bf4d79b4

Contents?: true

Size: 1.99 KB

Versions: 22

Compression:

Stored size: 1.99 KB

Contents

require 'lib/spec_helper'
require 'rack/test'

RSpec.describe Opal::SimpleServer do
  include Rack::Test::Methods

  attr_accessor :app

  before do
    Opal.append_path "#{__dir__}/fixtures"
    self.app = described_class.new(main: 'console')
  end

  it 'serves opal assets' do
    response = get '/assets/console.js'
    expect(response.body).to start_with(Opal::Builder.build('console').to_s)
  end

  it 'serves index for all non opal paths' do
    %w[/ /foo /foo/bar/baz].each do |path|
      response = get path
      expect(response.body).to include('<html>')
      expect(response.body).to include('<script')
      expect(response.body).to include('src="/assets/console.js')
      expect(response.headers['Content-type']).to eq('text/html')
    end
  end

  it 'serves the source map as data uri' do
    response = get '/assets/console.js'
    expect(response.body).to include("\n//# sourceMappingURL=data:application/json;base64,")
    base64_map = response.body.split("\n//# sourceMappingURL=data:application/json;base64,").last
    expect(Base64.decode64(base64_map)).to eq(Opal::Builder.build('console').source_map.to_json)
  end

  it 'takes a :prefix option to set the assets prefix' do
    self.app = described_class.new(main: 'opal', prefix: 'foo')
    expect(get('/foo/console.js').body).to start_with(Opal::Builder.build('console').to_s)
    self.app = described_class.new(main: 'opal', prefix: '/foo')
    expect(get('/foo/console.js').body).to start_with(Opal::Builder.build('console').to_s)
  end

  it 'takes a :main option to set the main asset' do
    self.app = described_class.new(main: 'foo')
    expect(get('/').body).to include('src="/assets/foo.js')
  end

  it 'respects config set in Opal::Config' do
    Opal::Config.arity_check_enabled = false
    expect(get('/assets/console.js').body).not_to include('$$parameters: []')

    Opal::Config.arity_check_enabled = true
    self.app = described_class.new(main: 'console')
    expect(get('/assets/console.js').body).to include('$$parameters: []')
  end
end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
opal-1.8.3.rc1 spec/lib/simple_server_spec.rb
opal-1.8.2 spec/lib/simple_server_spec.rb
opal-1.8.1 spec/lib/simple_server_spec.rb
opal-1.8.0 spec/lib/simple_server_spec.rb
opal-1.8.0.beta1 spec/lib/simple_server_spec.rb
opal-1.7.4 spec/lib/simple_server_spec.rb
opal-1.8.0.alpha1 spec/lib/simple_server_spec.rb
opal-1.7.3 spec/lib/simple_server_spec.rb
opal-1.7.2 spec/lib/simple_server_spec.rb
opal-1.7.1 spec/lib/simple_server_spec.rb
opal-1.7.0 spec/lib/simple_server_spec.rb
opal-1.7.0.rc1 spec/lib/simple_server_spec.rb
opal-1.6.1 spec/lib/simple_server_spec.rb
opal-1.6.0 spec/lib/simple_server_spec.rb
opal-1.6.0.rc1 spec/lib/simple_server_spec.rb
opal-1.6.0.alpha1 spec/lib/simple_server_spec.rb
opal-1.5.1 spec/lib/simple_server_spec.rb
opal-1.5.0 spec/lib/simple_server_spec.rb
opal-1.5.0.rc1 spec/lib/simple_server_spec.rb
opal-1.4.1 spec/lib/simple_server_spec.rb