venetian 0.1.3 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8894a94bd04d285d094166aea97a598e5fe430d0517cd2727af3004c1c1e94ca
4
- data.tar.gz: 0bc4c8fa1e7b5188df862e0a1addba7beb46a4e52eb4baa2421c545cc7638fd8
3
+ metadata.gz: 2a4d0e9aeaf06ee35d6366722bf2a6b6b9bd9f09500f171d1515a73de97a7825
4
+ data.tar.gz: 04d7d10bc92a7b8b524f669b34dc0a7c456f7a8f7d90dff85e80ec2c29f2ff5d
5
5
  SHA512:
6
- metadata.gz: 53e51de62a9901d09b496f21f13fef0003d17ae21ee7284e722863fe3b1f8485d43bd2f255aaa8ab2252e736b474ca2d04742caa721dff29b48c319d4cd369ce
7
- data.tar.gz: 4fe720569a97919438869bb4e65e5fc1f132922837fca139174f86c20f059f28423ba0c7b376e9bec53fa92dcd52b876a4b64913ccb7857a21716c12f3fdbc47
6
+ metadata.gz: 1d11a9eb73105eb8700a9657769be900dc5239f59f6e230546b6a8c44dbf68d887a57027163648471b14c82d90200c09ac2d9cc414abfab4b328f1af238a6e0f
7
+ data.tar.gz: e110ce724c3cae3de2a0cd90ff23f9b141f76b38e5786fea91e010b6eeda63fb68f7821bc75466d771dcb27f93c2e9d3a8d4ea62f96915772e0cb5503229ce22
data/README.md CHANGED
@@ -14,9 +14,11 @@ bundle add venetian --group test
14
14
 
15
15
  ## Usage
16
16
 
17
+ ### Rails system tests
18
+
17
19
  In your system test case, choose the Playwright driver. Venetian will provide the base command to run Playwright,
18
20
  which you can still override by passing `:playwright_cli_executable_path`, and this plus any other options will be passed through
19
- to `capybara-playwright-driver`. If you specify a browser, this will be automatically downloaded if necessary.
21
+ to `capybara-playwright-driver`.
20
22
 
21
23
  ```ruby
22
24
  require "test_helper"
@@ -26,6 +28,73 @@ class ApplicationSystemTestCase < ActionDispatch::SystemTestCase
26
28
  end
27
29
  ```
28
30
 
31
+ ### Using Capybara directly
32
+
33
+ Likewise, register the Playwright driver before using it later:
34
+
35
+ ```ruby
36
+ Capybara.register_driver :playwright do |app|
37
+ Capybara::Playwright::Driver.new(app)
38
+ end
39
+ ```
40
+
41
+ ### Automatic browser and dependency installation
42
+
43
+ The gem will automatically install a browser and dependencies for you before attempting to use it.
44
+ Browsers are installed to `$XDG_CACHE_HOME/ms-playwright` on Linux, `~/Library/Caches/ms-playwright` on macOS,
45
+ and `%LOCALAPPDATA%\ms-playwright` on Windows. In CI, you will want to
46
+ [cache this directory](https://docs.github.com/en/actions/reference/workflows-and-actions/dependency-caching)
47
+ to avoid downloads on every run.
48
+
49
+ On Linux,
50
+ [Playwright currently only officially supports Debian and Ubuntu](https://playwright.dev/docs/intro#system-requirements)
51
+ due to e.g. differences between package managers and package names across distros,
52
+ so dependency installation happens only if a compatible package manager is found.
53
+ Depending on what you're doing, you may not need to install dependencies,
54
+ but if you do and your distro is unsupported, you will need to work out what you need and deal with that first.
55
+
56
+ When parallelizing tests, there's also the issue of multiple processes all trying to acquire the package manager lock:
57
+ if you use Rails system tests with `ActionDispatch::SystemTestCase`,
58
+ this is handled automatically by installing all required browsers before disabling auto-installation and then forking.
59
+
60
+ ### Installing browsers manually
61
+
62
+ If you can't rely on automatic installation, you can use the included Rake task to install browsers.
63
+ With Rails this is included automatically when the gem is required.
64
+
65
+ ```bash
66
+ $ RAILS_ENV=test rails venetian:install
67
+
68
+ # Or a specific browser
69
+ $ RAILS_ENV=test rails venetian:install[firefox]
70
+ ```
71
+
72
+ Otherwise in your Rakefile add:
73
+
74
+ ```ruby
75
+ load "tasks/venetian.rake"
76
+ ```
77
+
78
+ And then run:
79
+
80
+ ```bash
81
+ $ rake venetian:install
82
+ ```
83
+
84
+ ### Running Playwright yourself
85
+
86
+ The gem provides a `playwright` executable which you can use to run Playwright yourself.
87
+
88
+ ```bash
89
+ $ playwright --version
90
+ Version 1.61.1
91
+ ```
92
+
93
+ ### Getting more output
94
+
95
+ Noisy output during a test run is often frustrating, so the gem is quiet by default.
96
+ You can get more output with `VENETIAN_DEBUG=1`.
97
+
29
98
  ## Development
30
99
 
31
100
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests.
@@ -5,6 +5,18 @@ module Venetian
5
5
  #
6
6
  # Installs browsers using the Playwright executable.
7
7
  class BrowserInstaller
8
+ class << self
9
+ private
10
+
11
+ def install_dependencies?
12
+ Venetian.auto_install_dependencies && dependencies_supported?
13
+ end
14
+
15
+ def install_dry_run
16
+ Venetian.system "install-deps", "--dry-run", exception: false, echo: ENV.fetch("VENETIAN_DEBUG", nil)
17
+ end
18
+ end
19
+
8
20
  # # Install Error
9
21
  #
10
22
  # Raised when the installation fails for some reason.
@@ -17,11 +29,18 @@ module Venetian
17
29
  end
18
30
 
19
31
  # Installs a browser. Raises InstallError if installation fails.
20
- def self.install(browser = nil, install_dependencies: true)
32
+ def self.install(browser = nil, install_dependencies: install_dependencies?)
21
33
  Venetian.system "install", *browser&.to_s, *("--with-deps" if install_dependencies),
22
34
  exception: true, echo: ENV.fetch("VENETIAN_DEBUG", nil)
23
35
  rescue StandardError => e
24
36
  raise InstallError, e.message
25
37
  end
38
+
39
+ # Returns true if the current OS supports Playwright's dependency installer.
40
+ def self.dependencies_supported?(force: false)
41
+ return @dependencies_supported unless @dependencies_supported.nil? || force
42
+
43
+ @dependencies_supported = install_dry_run || false
44
+ end
26
45
  end
27
46
  end
@@ -5,6 +5,10 @@ module Venetian
5
5
  #
6
6
  # Provides methods for locating the Playwright executable.
7
7
  module Executable
8
+ class Executor # :nodoc:
9
+ public :system, :exec
10
+ end
11
+
8
12
  DEFAULT_DIR = File.expand_path(File.join(__dir__, "..", "..", "exe")) # :nodoc:
9
13
  INSTALL_DIR_ENV_VAR = "VENETIAN_INSTALL_DIR" # :nodoc:
10
14
 
@@ -82,21 +86,26 @@ module Venetian
82
86
  end
83
87
 
84
88
  # Executes the Playwright executable with the given arguments.
85
- def execute(*args, echo: true)
86
- [base_command, *args].then do |command|
87
- puts command.inspect if echo
89
+ def execute(*args, echo: true, exception: true, **)
90
+ [*base_command, *args].then do |command|
88
91
  # due to mysterious Windows behavior; see equivalent in `tailwindcss-ruby`
89
- next system(*command, exception: true) if Gem.win_platform?
90
-
91
- exec(*command)
92
+ next system(*args, exception:, echo:) if Gem.win_platform?
93
+
94
+ puts command.shelljoin if echo
95
+ begin
96
+ executor.exec(*command)
97
+ rescue StandardError
98
+ exception ? raise : false
99
+ end
92
100
  end
93
101
  end
94
102
 
95
103
  # Runs the Playwright executable with the given arguments.
96
- def system(*args, echo: true, **)
104
+ def system(*args, echo: true, exception: true, **)
97
105
  [*base_command, *args].then do |command|
98
- puts command.inspect if echo
99
- super(*command, exception: true)
106
+ puts command.shelljoin if echo
107
+ executor.system(*command,
108
+ exception:, **{ out: echo ? nil : File::NULL, err: echo ? nil : File::NULL }.compact)
100
109
  end
101
110
  end
102
111
 
@@ -133,7 +142,7 @@ module Venetian
133
142
  def exe_path
134
143
  return custom_exe_path if ENV.key?(INSTALL_DIR_ENV_VAR)
135
144
 
136
- Upstream::NATIVE_PLATFORMS.select { |platform, _| Gem::Platform.match_gem?(Gem::Platform.new(platform), GEMSPEC.name) }
145
+ Upstream::NATIVE_PLATFORMS.select { |platform, _| Gem::Platform.match_gem?(Gem::Platform.new(platform), gem_name) }
137
146
  .collect { |platform, _info| File.join(exe_dir, platform, "node") }
138
147
  .detect { |candidate| File.exist?(candidate) }
139
148
  end
@@ -143,12 +152,20 @@ module Venetian
143
152
  end
144
153
 
145
154
  def gem_platforms_unsupported?
146
- Upstream::NATIVE_PLATFORMS.keys.none? { |platform| Gem::Platform.match_gem?(Gem::Platform.new(platform), GEMSPEC.name) }
155
+ Upstream::NATIVE_PLATFORMS.keys.none? { |platform| Gem::Platform.match_gem?(Gem::Platform.new(platform), gem_name) }
156
+ end
157
+
158
+ def gem_name
159
+ GEMSPEC&.name || "venetian"
147
160
  end
148
161
 
149
162
  def platform
150
163
  Gem::Platform.local.to_s
151
164
  end
165
+
166
+ def executor
167
+ @executor ||= Executor.new
168
+ end
152
169
  end
153
170
  end
154
171
  end
@@ -5,5 +5,12 @@ module Venetian
5
5
  rake_tasks do
6
6
  load "tasks/venetian.rake"
7
7
  end
8
+
9
+ initializer "venetian.system_test_setup" do
10
+ ActiveSupport.on_load :action_dispatch_system_test_case do
11
+ require "venetian/system_test_case_extension"
12
+ prepend SystemTestCaseExtension
13
+ end
14
+ end
8
15
  end
9
16
  end
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Venetian
4
+ module SystemTestCaseExtension # :nodoc:
5
+ extend ActiveSupport::Concern
6
+
7
+ prepended do
8
+ class_attribute :venetian_browser_type, default: :chromium, instance_writer: false
9
+
10
+ parallelize_before_fork do
11
+ install_playwright_browsers if venetian_preinstall_browsers_before_fork?
12
+ end
13
+ end
14
+
15
+ class_methods do # :nodoc:
16
+ def driven_by(driver, options: {}, **)
17
+ super
18
+
19
+ self.venetian_browser_type = driver == :playwright ? options.fetch(:browser_type, :chromium).to_sym : nil
20
+ end
21
+
22
+ def install_playwright_browsers
23
+ venetian_browsers.presence.try do |browsers|
24
+ browsers.each { |browser| BrowserInstaller.install(browser) }
25
+ Venetian.auto_install_browsers = false
26
+ end
27
+ end
28
+
29
+ private
30
+
31
+ def venetian_preinstall_browsers_before_fork?
32
+ Venetian.auto_install_browsers && defined? ActionDispatch::SystemTestCase
33
+ end
34
+
35
+ def venetian_browsers
36
+ Minitest::Runnable.runnables
37
+ .select { |klass| klass < ActionDispatch::SystemTestCase && klass.driver&.name == :playwright }
38
+ .filter_map(&:venetian_browser_type)
39
+ .uniq
40
+ end
41
+ end
42
+ end
43
+ end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Venetian
4
- VERSION = "0.1.3"
5
- COMPATIBLE_PLAYWRIGHT_VERSION = "1.60.0"
4
+ VERSION = "0.2.0"
5
+ COMPATIBLE_PLAYWRIGHT_VERSION = "1.61.1"
6
6
  end
data/lib/venetian.rb CHANGED
@@ -16,15 +16,16 @@ require "venetian/railtie" if defined? Rails
16
16
  # Native Playwright driver for Capybara.
17
17
  module Venetian
18
18
  class << self
19
- attr_accessor :auto_install_browsers
19
+ attr_accessor :auto_install_browsers, :auto_install_dependencies
20
20
  end
21
21
 
22
22
  class Error < StandardError; end
23
23
 
24
24
  self.auto_install_browsers = true
25
+ self.auto_install_dependencies = true
25
26
 
26
- def self.execute(*, echo: true)
27
- Executable.execute(*, echo: echo)
27
+ def self.execute(*, echo: true, **)
28
+ Executable.execute(*, echo: echo, **)
28
29
  end
29
30
 
30
31
  def self.system(*, echo: true, **)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: venetian
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Justin Malčić
@@ -29,14 +29,14 @@ dependencies:
29
29
  requirements:
30
30
  - - ">="
31
31
  - !ruby/object:Gem::Version
32
- version: 1.60.0
32
+ version: 1.61.0
33
33
  type: :runtime
34
34
  prerelease: false
35
35
  version_requirements: !ruby/object:Gem::Requirement
36
36
  requirements:
37
37
  - - ">="
38
38
  - !ruby/object:Gem::Version
39
- version: 1.60.0
39
+ version: 1.61.0
40
40
  description: Bundles the Playwright driver binary in platform-specific gem variants
41
41
  and integrates with `capybara-playwright-driver`.
42
42
  email:
@@ -59,6 +59,7 @@ files:
59
59
  - lib/venetian/gemspec.rb
60
60
  - lib/venetian/playwright_create_extensions.rb
61
61
  - lib/venetian/railtie.rb
62
+ - lib/venetian/system_test_case_extension.rb
62
63
  - lib/venetian/tasks.rb
63
64
  - lib/venetian/upstream.rb
64
65
  - lib/venetian/version.rb
@@ -69,7 +70,7 @@ metadata:
69
70
  homepage_uri: https://malcic.codes/software/venetian
70
71
  source_code_uri: https://github.com/jmalcic/venetian
71
72
  rubygems_mfa_required: 'true'
72
- playwright_version: 1.60.0
73
+ playwright_version: 1.61.1
73
74
  rdoc_options: []
74
75
  require_paths:
75
76
  - lib