Files
react-native-devtools-frontend/test/interactions
Jack Franklin d1d4bbee62 Remove TimelineFrameModel and migrate to FramesHandler
IMPORTANT: do not merge before the branch cut on Dec 4.

This CL removes the old TimelineFrameModel and migrates all usages of it
to the new engine.

Unfortunately this is a rather large CL, but there was no real way to
incrementally do this wwork without maintaining both frame models (old
and new) and implementing some way of linking them which did not seem
worth it.

This CL updates the frames track, paint profiler and layers view to use
data from the new frames model. Mostly this means implementing SDK based
lookups that were in the legacy TimelineFrameModel in other parts of the
codebase (to ensure the Trace engine does not rely on SDK).

I have manually tested this locally on a few different traces, and have
confirmed that things seem to be behaving as expected. That said, it
seems silly to risk landing this now just before a branch point, so I
will wait until next week.

There are a few TODOs left in the code; this CL was already big so I
have left those on purpose and will follow this CL up with those
improvements.

I also removed a "Show layers" link that is shown in the details view if
the frame has layers; this link is actually broken on stable right now,
and I wasn't entirely sure how to implement it. Given that, I have
removed the link (you don't need it, as the Layers tab appears). We can
consider if to bring the link back again after this CL lands.

Bug: 1499182
Change-Id: Id881202b944f814cbae0c45d9ffb0a7032030701
Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/5068258
Reviewed-by: Andres Olivares <andoli@chromium.org>
Commit-Queue: Jack Franklin <jacktfranklin@chromium.org>
2023-12-05 10:15:57 +00:00
..
2023-01-31 10:21:47 +00:00
2023-10-02 08:58:48 +00:00

Interaction tests

Interaction tests are used to test individual pieces of DevTools in isolation - whether that be a single UI component, or an entire panel, or something inbetween. They load up the page in the browser and use Puppeteer to query it.

Interaction tests are run against examples on the Components Server, so your first step to writing an Interaction test is to create the required examples you want to test against.

You can run the interaction tests with npm run auto-interactionstest. This will automatically run the components server and then the tests.

When writing an interactions test, you should use the loadComponentDocExample() helper to instruct the test to navigate to a particular example within the component server. Any pages that you load must also be passed into the preloadForCodeCoverage function, which enables the coverage instrumentation.

describe('Example test', () => {
  preloadForCodeCoverage('performance_panel/basic.html');

  it('does something', async () => {
    await loadComponentDocExample('performance_panel/basic.html?trace=basic');
    // Assertions go here
  });
});

Screenshot tests

Interaction tests also have the ability to store a screenshot of an element and in future tests ensure that the screenshot has not changed. These should be used sparingly - our usage so far has found that you should prefer HTML assertions if possible - but they are useful particularly for <canvas> based UI.

To create a screenshot test, query for an element and call the assertElementScreenshotUnchanged function, passing in the element and the file name:

itScreenshot('loads a trace file and renders it in the timeline', async () => {
  await loadComponentDocExample('performance_panel/basic.html?trace=basic');
  const flamechart = await waitFor('.timeline-flamechart');
  await assertElementScreenshotUnchanged(flamechart, 'performance/example-test.png');
});

The first time this test runs, it will create a new stored image in test/interactions/goldens. On any future runs, it will compare the generated screenshot against that golden, and fail if there is a difference.

Generating and/or updating screenshots on all platforms via CQ bots

We store golden screenshots on 3 platforms: Mac, Linux and Windows. Rather than require a developer to have access to all 3, we are able to run and use screenshots generated from the CQ bots.

Note: you must be a Google employee to follow this process.

Once you have generated your screenshot locally on your platform, you should upload your CL and trigger a dry-run. This will fail due to missing screenshots, but once it is complete we can then fetch the screenshots from the server.

First, authenticate (using your Google corp credentials):

# Run this in the devtools-frontend repository
./third_party/depot_tools/gsutil.py config

And then call the script to update the golden screenshots:

./scripts/tools/update_goldens_v2.py

This will fetch any relevant screenshots locally. You can then commit these and update your CL. Please manually check the screenshots to ensure they are as expected on all platforms!

Updating screenshots locally

When you need to update a screenshot because you have purposefully changed the UI, you need to run the interactions tests with a flag:

FORCE_UPDATE_ALL_GOLDENS=1 npm run auto-interactionstest

This tells the test runner to update any screenshots that fail. Once you've done this, the process is identical to when you add a new screenshot:

  1. Commit the changes for your platform locally.
  2. Trigger a CQ run and wait for it to finish.
  3. Fetch the new screenshots from the bots by using ./scripts/tools/update_goldens_v2.py.