trmnl_preview 0.17.2 → 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 +4 -4
- data/CHANGELOG.md +9 -0
- data/README.md +2 -1
- data/lib/trmnlp/firefox_driver.rb +1 -1
- data/lib/trmnlp/screenshot.rb +8 -23
- data/lib/trmnlp/testing/publishable_recipe.rb +35 -0
- data/lib/trmnlp/testing/rspec.rb +1 -0
- data/lib/trmnlp/version.rb +1 -1
- data/templates/init/tests/plugin_spec.rb +2 -12
- metadata +2 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 32924757751f8d15ad7979409c03f18906506af03558a90d27bfd122f0a44d0c
|
|
4
|
+
data.tar.gz: 5cba7d9f2cbd67868316826218a1237efafafdc0f9967b3670ef538859c11f56
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: b9b8692c362797cd9df4ee23cf7a081051ec9f6ea18b28c721426fc58860231a5b02541c0a6823a8a940a33eb1a9e81f8fdcba9f3d43ad43f6871a880706fb58
|
|
7
|
+
data.tar.gz: 1351106bc604919f20f0067a558eab0da46c1f08bf1cf7fd3ccce69db42dcac81136499d295629cfc64777b3f40586332701c312707b22348f56927611232fe0
|
data/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,15 @@
|
|
|
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
|
+
|
|
9
|
+
## 0.18.0
|
|
10
|
+
|
|
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)
|
|
12
|
+
|
|
4
13
|
## 0.17.2
|
|
5
14
|
|
|
6
15
|
- `trmnlp test` no longer inlines a stylesheet link inside a script's string, such as a CDN fallback written with `document.write`. It broke the script, and every render came out blank. (#174)
|
data/README.md
CHANGED
|
@@ -473,7 +473,7 @@ See [TRMNL documentation](https://help.trmnl.com/en/articles/10542599-importing-
|
|
|
473
473
|
|
|
474
474
|
## Testing Plugins
|
|
475
475
|
|
|
476
|
-
`trmnlp init` starts a plugin with `tests/plugin_spec.rb` (
|
|
476
|
+
`trmnlp init` starts a plugin with `tests/plugin_spec.rb` (`it_behaves_like 'a publishable recipe'`, below) and a GitHub workflow that runs it in the `trmnl/trmnlp` image, uploads the report, can rewrite the snapshots on a manual run, and pushes to TRMNL only once lint and tests pass. `trmnlp test` runs the RSpec files in your plugin's `tests/` folder, through the same pipeline `serve` and `build` use, with fake APIs and a fixed clock:
|
|
477
477
|
|
|
478
478
|
```ruby
|
|
479
479
|
# tests/weather_spec.rb
|
|
@@ -505,6 +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 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.
|
|
508
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.
|
|
509
510
|
|
|
510
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
|
data/lib/trmnlp/screenshot.rb
CHANGED
|
@@ -68,44 +68,29 @@ module TRMNLP
|
|
|
68
68
|
end
|
|
69
69
|
|
|
70
70
|
def resize(driver, width, height)
|
|
71
|
-
|
|
71
|
+
set_viewport(driver, width, height)
|
|
72
72
|
wait_for_viewport(driver, width, height)
|
|
73
73
|
end
|
|
74
74
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
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
|
|
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.
|
|
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
|
-
|
|
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
|
|
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)
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module TRMNLP
|
|
4
|
+
module Testing
|
|
5
|
+
# The screens a recipe is drawn on: TRMNL's own devices, in landscape and portrait.
|
|
6
|
+
PUBLISHABLE_RECIPE_SCREENS = [
|
|
7
|
+
{ device: 'og_png' }, { device: 'og_plus' }, { device: 'og_plus', orientation: :portrait },
|
|
8
|
+
{ device: 'v2' }, { device: 'v2', orientation: :portrait }
|
|
9
|
+
].freeze
|
|
10
|
+
PUBLISHABLE_RECIPE_VIEWS = %w[full half_horizontal half_vertical quadrant].freeze
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
RSpec.shared_examples 'a publishable recipe' do |screens: TRMNLP::Testing::PUBLISHABLE_RECIPE_SCREENS|
|
|
15
|
+
let(:recipe_inputs) do
|
|
16
|
+
{ mocks: respond_to?(:mocks) ? mocks : {}, custom_fields: respond_to?(:custom_fields) ? custom_fields : {} }
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
TRMNLP::Testing::PUBLISHABLE_RECIPE_VIEWS.product(screens).each do |view, screen|
|
|
20
|
+
device = screen[:device].is_a?(Hash) ? screen[:device][:model] : screen[:device]
|
|
21
|
+
screen_name = [device, screen[:orientation]].compact.join(' ')
|
|
22
|
+
|
|
23
|
+
it "draws the #{view} view on #{screen_name} without overflow or page errors" do
|
|
24
|
+
expect(trmnl.render(view:, **screen, **recipe_inputs)).to have_no_overflow.and have_no_problems
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
it 'runs its transform without error' do
|
|
29
|
+
expect(trmnl.transform(device: screens.first[:device], **recipe_inputs).error).to be_nil
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
it "stays within TRMNL's serverless limits" do
|
|
33
|
+
expect(trmnl.transform(device: screens.first[:device], **recipe_inputs)).to stay_within_serverless_limits
|
|
34
|
+
end
|
|
35
|
+
end
|
data/lib/trmnlp/testing/rspec.rb
CHANGED
data/lib/trmnlp/version.rb
CHANGED
|
@@ -10,18 +10,8 @@ RSpec.describe 'My Plugin' do
|
|
|
10
10
|
# The values of the custom fields in src/settings.yml to test with.
|
|
11
11
|
let(:custom_fields) { {} }
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
screen = trmnl.render(view:, mocks:, custom_fields:)
|
|
16
|
-
|
|
17
|
-
expect(screen).to have_no_overflow
|
|
18
|
-
expect(screen).to have_no_problems
|
|
19
|
-
end
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
it "stays within TRMNL's serverless limits" do
|
|
23
|
-
expect(trmnl.transform(mocks:, custom_fields:)).to stay_within_serverless_limits
|
|
24
|
-
end
|
|
13
|
+
# Every view on TRMNL's devices without overflow or page errors, and the transform within TRMNL's limits.
|
|
14
|
+
it_behaves_like 'a publishable recipe'
|
|
25
15
|
|
|
26
16
|
# A picture of the full view, compared pixel for pixel on every run. Record it once with
|
|
27
17
|
# `trmnlp test --update` (or the workflow's update_snapshots run) and commit tests/snapshots.
|
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.
|
|
4
|
+
version: 0.18.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Rockwell Schrock
|
|
@@ -468,6 +468,7 @@ files:
|
|
|
468
468
|
- lib/trmnlp/testing/mock_table.rb
|
|
469
469
|
- lib/trmnlp/testing/node_version.rb
|
|
470
470
|
- lib/trmnlp/testing/plugin.rb
|
|
471
|
+
- lib/trmnlp/testing/publishable_recipe.rb
|
|
471
472
|
- lib/trmnlp/testing/report.html.erb
|
|
472
473
|
- lib/trmnlp/testing/report.rb
|
|
473
474
|
- lib/trmnlp/testing/rspec.rb
|