trmnl_preview 0.18.0 → 0.18.1

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: 53759b5b952609676a6313c40932bf0aa015ba665044fa2dae6d6dd25e96dfc1
4
- data.tar.gz: 906e518e4193951665996a4ed7a49ff07e94cfec35269412f6fe2a172b1ae4c4
3
+ metadata.gz: 32924757751f8d15ad7979409c03f18906506af03558a90d27bfd122f0a44d0c
4
+ data.tar.gz: 5cba7d9f2cbd67868316826218a1237efafafdc0f9967b3670ef538859c11f56
5
5
  SHA512:
6
- metadata.gz: 51e39569a0ade12fc7f435176438ce3319adbaac3f613a4b36f441b3c01e7a89917f5df96395a62ad3a7a1dce3efb1e021847e1178afe84c47cdabfbec9b6f9d
7
- data.tar.gz: a7b3b71f8fb839bca061a9b2083622d076f9290a6f4f128cacaea34b36cc6e0833ea3ae7876b13358dc7670c4fb71a6b973564866614474893efdd5715f898f8
6
+ metadata.gz: b9b8692c362797cd9df4ee23cf7a081051ec9f6ea18b28c721426fc58860231a5b02541c0a6823a8a940a33eb1a9e81f8fdcba9f3d43ad43f6871a880706fb58
7
+ data.tar.gz: 1351106bc604919f20f0067a558eab0da46c1f08bf1cf7fd3ccce69db42dcac81136499d295629cfc64777b3f40586332701c312707b22348f56927611232fe0
data/CHANGELOG.md CHANGED
@@ -1,6 +1,11 @@
1
1
 
2
2
  # Changelog
3
3
 
4
+ ## 0.18.1
5
+
6
+ - Pages narrower than a Firefox window render, such as a 480x800 TRMNL OG in portrait, in `serve`, `build` and `test`. trmnlp sets the page's viewport with WebDriver BiDi, as TRMNL does, instead of resizing the window, which Firefox will not size under about 500px. (#178)
7
+ - `it_behaves_like 'a publishable recipe'` also draws every view on the TRMNL OG (2-bit) in portrait. (#179)
8
+
4
9
  ## 0.18.0
5
10
 
6
11
  - `it_behaves_like 'a publishable recipe'` checks what a recipe should hold before it is published: every view draws without overflow or page errors on the TRMNL OG (1-bit and 2-bit) and the TRMNL X (landscape and portrait), and the transform runs without error within TRMNL's limits. `trmnlp init`'s starter spec uses it. (#176)
data/README.md CHANGED
@@ -505,7 +505,7 @@ end
505
505
  - `mocks:` answer every request the run makes: polling urls, and the transform's own requests in any language, HTTPS included. Keys are urls, with `*` wildcards, a Regexp, or a method first (`'POST https://...'`). Values are `{ json:, body:, status:, headers:, delay:, body_delay:, advance_clock:, error: :reset }` (times in seconds: `body_delay:` sends the headers first and the body later, `advance_clock:` moves the transform's clock on when it answers), a string body, a lambda that takes the request, or an array of answers used in order. An unmocked request gets a 599. `requests` lists every request with its `status`, and `aborted: true` for one the transform gave up on before its answer arrived; `duration_ms` is how long the transform ran.
506
506
  - `now:` starts every clock: Liquid's, the markup's scripts', and the transform's, through libfaketime (`brew install libfaketime` or `apt-get install libfaketime`; already in the Docker image). On macOS the interpreter must come from brew, mise or similar, since macOS will not hand libfaketime to its own `/usr/bin` binaries.
507
507
  - `trmnlp test --report report` also writes `report/index.html` and `report/report.json`: every example with each screen it rendered (with a switch that outlines every drawn box, and the page's problems) and each transform it ran (time, memory, requests). Under GitHub Actions the counts and failures go to the run's summary too.
508
- - `it_behaves_like 'a publishable recipe'` is what a recipe should hold before it is published: every view draws without overflow or page errors on the TRMNL OG (1-bit and 2-bit) and the TRMNL X (landscape and portrait), and the transform runs without error within TRMNL's limits. It uses the group's `mocks` and `custom_fields` when the group defines them; `screens: [{ device: 'kobo_libra_2' }, ...]` draws on other devices.
508
+ - `it_behaves_like 'a publishable recipe'` is what a recipe should hold before it is published: every view draws without overflow or page errors on the TRMNL OG (1-bit, and 2-bit in landscape and portrait) and the TRMNL X (landscape and portrait), and the transform runs without error within TRMNL's limits. It uses the group's `mocks` and `custom_fields` when the group defines them; `screens: [{ device: 'kobo_libra_2' }, ...]` draws on other devices.
509
509
  - `match_snapshot` stores a missing snapshot under `tests/snapshots/<os>/` and fails one on CI; `trmnlp test --update` rewrites them. Fonts render differently per operating system, so run tests in the Docker image when CI should share your snapshots. `fit_image_size_limit` checks the PNG against the model's limit.
510
510
 
511
511
  ## Development
@@ -15,7 +15,7 @@ module TRMNLP
15
15
  end
16
16
 
17
17
  def options
18
- Selenium::WebDriver::Firefox::Options.new.tap do |opts|
18
+ Selenium::WebDriver::Firefox::Options.new(web_socket_url: true).tap do |opts|
19
19
  opts.add_argument('--headless')
20
20
  opts.add_argument('--disable-web-security')
21
21
  end
@@ -68,44 +68,29 @@ module TRMNLP
68
68
  end
69
69
 
70
70
  def resize(driver, width, height)
71
- apply_window_size(driver, width, height)
71
+ set_viewport(driver, width, height)
72
72
  wait_for_viewport(driver, width, height)
73
73
  end
74
74
 
75
- def apply_window_size(driver, width, height)
76
- borders = driver.execute_script(<<~JS)
77
- return {
78
- width: window.outerWidth - window.innerWidth,
79
- height: window.outerHeight - window.innerHeight
80
- }
81
- JS
82
-
83
- dim = Selenium::WebDriver::Dimension.new(width + borders['width'], height + borders['height'])
84
- driver.manage.window.size = dim
75
+ # The page's viewport, not the window: Firefox will not size a window under about 500px, as an OG in portrait.
76
+ def set_viewport(driver, width, height)
77
+ driver.bidi.send_cmd('browsingContext.setViewport', context: driver.window_handle, viewport: { width:, height: })
85
78
  end
86
79
 
87
80
  # NOTE: A cold Firefox — e.g. the first render after the container boots —
88
- # applies a window resize lazily. The old fixed sleep raced that reflow and
81
+ # applies a resize lazily. The old fixed sleep raced that reflow and
89
82
  # clipped the first screenshot short (800x433 instead of 800x480). Poll the
90
- # real viewport instead, re-applying the size until it lands. A width the
91
- # browser refuses to honour (below its ~500px window minimum) never settles;
92
- # that surfaces as a clear RenderError rather than an opaque, retried timeout.
83
+ # real viewport instead, re-applying the size until it lands.
93
84
  def wait_for_viewport(driver, width, height)
94
85
  Selenium::WebDriver::Wait.new(timeout: @viewport_timeout, interval: 0.1).until do
95
86
  next true if viewport(driver) == [width, height]
96
87
 
97
- apply_window_size(driver, width, height)
88
+ set_viewport(driver, width, height)
98
89
  false
99
90
  end
100
91
  rescue Selenium::WebDriver::Error::TimeoutError
101
- raise RenderError, viewport_clamp_message(driver, width, height)
102
- end
103
-
104
- def viewport_clamp_message(driver, width, height)
105
92
  actual_width, actual_height = viewport(driver)
106
- "Could not render at #{width}x#{height}: the browser clamped the viewport " \
107
- "to #{actual_width}x#{actual_height}. PNG rendering needs a width of " \
108
- 'roughly 500px or more — headless Firefox will not size its window narrower.'
93
+ raise RenderError, "Could not render at #{width}x#{height}: the viewport stayed #{actual_width}x#{actual_height}"
109
94
  end
110
95
 
111
96
  def viewport(driver)
@@ -2,9 +2,10 @@
2
2
 
3
3
  module TRMNLP
4
4
  module Testing
5
- # The screens a recipe is drawn on: TRMNL's own devices, and a portrait screen.
5
+ # The screens a recipe is drawn on: TRMNL's own devices, in landscape and portrait.
6
6
  PUBLISHABLE_RECIPE_SCREENS = [
7
- { device: 'og_png' }, { device: 'og_plus' }, { device: 'v2' }, { device: 'v2', orientation: :portrait }
7
+ { device: 'og_png' }, { device: 'og_plus' }, { device: 'og_plus', orientation: :portrait },
8
+ { device: 'v2' }, { device: 'v2', orientation: :portrait }
8
9
  ].freeze
9
10
  PUBLISHABLE_RECIPE_VIEWS = %w[full half_horizontal half_vertical quadrant].freeze
10
11
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module TRMNLP
4
- VERSION = '0.18.0'
4
+ VERSION = '0.18.1'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: trmnl_preview
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.18.0
4
+ version: 0.18.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rockwell Schrock