Skip to content

Commit df78609

Browse files
OrKoNDevtools-frontend LUCI CQ
authored andcommitted
Document screenshot assertions in unit tests
Bug: 401489541 Change-Id: I2755a7868421456d43b7a80a920ddc31ddf93374 Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/6429364 Commit-Queue: Danil Somsikov <[email protected]> Auto-Submit: Alex Rudenko <[email protected]> Reviewed-by: Danil Somsikov <[email protected]>
1 parent 2c00f81 commit df78609

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed

test/unit/README.md

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,3 +143,59 @@ describe.skip('[crbug.com/12345678] Foo', () => {
143143
```
144144

145145
if all the tests for `Foo` should be skipped.
146+
147+
## Screenshot tests
148+
149+
Unit tests also have the ability to store a screenshot of an element and
150+
in future tests ensure that the screenshot has not changed. The purpose
151+
of screenshot tests is to test view functions of presenters to ensure
152+
that visual styles do not regress.
153+
154+
```ts
155+
describe('view', () => {
156+
it('renders the feedback form', async () => {
157+
const target = document.createElement('div');
158+
renderElementIntoDOM(target);
159+
AiAssistance.UserActionRow.DEFAULT_VIEW(
160+
{
161+
onRatingClick: () => {},
162+
onReportClick: () => {},
163+
scrollSuggestionsScrollContainer: () => {},
164+
onSuggestionsScrollOrResize: () => {},
165+
onSuggestionClick: () => {},
166+
onSubmit: () => {},
167+
onClose: () => {},
168+
onInputChange: () => {},
169+
showRateButtons: true,
170+
isSubmitButtonDisabled: false,
171+
isShowingFeedbackForm: true,
172+
},
173+
{}, target);
174+
await assertScreenshot('ai_assistance/user_action_row.png');
175+
});
176+
});
177+
```
178+
179+
Currently, screenshot tests require that they are run in the browser
180+
instance started by the test runner because they rely on custom bindings
181+
to take and compare screenshots.
182+
183+
Screenshot assertions are only supported on Linux. On other platforms,
184+
they are reported as passing without actually capturing any screenshots.
185+
186+
### Updating screenshots locally
187+
188+
When you need to update a screenshot because you have purposefully changed the UI:
189+
190+
```sh
191+
npm run test -- $TESTPATH --on-diff=update
192+
```
193+
194+
### Generating and/or updating screenshots via CQ bots
195+
196+
This feature is not yet available in unit tests (b/408113752).
197+
198+
### Known issues
199+
200+
Currently, screenshot diffs are not shown as images on resultsdb pages
201+
(b/408112810).

0 commit comments

Comments
 (0)