Class: PlaywrightOnRails::LaunchesPlaywright

Inherits:
Object
  • Object
show all
Defined in:
lib/playwright-on-rails/launches_playwright.rb

Instance Method Summary collapse

Constructor Details

#initializeLaunchesPlaywright

Returns a new instance of LaunchesPlaywright.



9
10
11
12
13
14
# File 'lib/playwright-on-rails/launches_playwright.rb', line 9

def initialize
  @initializer_hooks = InitializerHooks.instance
  @manages_transactions = ManagesTransactions.instance
  @starts_rails_server = StartsRailsServer.new
  @finds_bin = FindsBin.new
end

Instance Method Details

#call(command, config) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/playwright-on-rails/launches_playwright.rb', line 16

def call(command, config)
  puts config
  @initializer_hooks.run(:before_server_start)
  if config.transactional_server
    @manages_transactions.begin_transaction
  end
  server = @starts_rails_server.call(
    host: config.host,
    port: config.port,
    transactional_server: config.transactional_server
  )
  bin = @finds_bin.call(config.playwright_dir)

  set_exit_hooks!(config)

  command = <<~EXEC
    PLAYWRIGHT_BASE_URL="http://#{server.host}:#{server.port}#{config.base_path}" "#{bin}" #{command} --config "#{config.playwright_dir}/playwright.config.js" #{config.playwright_cli_opts}
  EXEC

  puts "\nLaunching Playwright…\n$ #{command}\n"
  system command
end