Ui eng vision test scaffolder

From ChromeDevTools/devtools-frontend · View interactive version

Ui eng vision test scaffolder is an AI agent skill from the GitHub repository ChromeDevTools/devtools-frontend. Scaffolds unit tests and screenshot tests to establish visual and functional rendering baselines for views before refactoring.

How to use this skill

Skill file

Subskill: Test Scaffolder

This subskill establishes the safety net of existing and new visual/functional

tests before any codebase modifications occur, ensuring that no rendering or

logical regressions are introduced during modernization.


1. Test Verification Lifecycle

  1. Verify Existing Tests:

implementation in front_end/**/*.test.ts (for example,

front_end/panels/application/IndexedDBViews.test.ts for

IndexedDBViews.ts).

*.test.ts file (with Linux golden PNGs under test/goldens/linux/) and

full-browser E2E tests under test/e2e/ to verify layout and styling.

  1. Detect Sub-component Testing Gaps (Hybrid Files):

file while missing another class being migrated (e.g., tests exist for

IDBDatabaseView but are scarce/missing for IDBDataView).

  1. Scaffold Missing Tests:

migrated, draft a basic Mocha/Chai rendering test.

synthetic DOM helper or unit-test container.

adding the styles itself. If the test pass, keep the version without

{includeCommonStyles: true}. Otherwise, bring it back.

```typescript

describe('view', () => {

it('renders the base state', async () => {

const target = document.createElement('div');

target.style.width = '600px';

target.style.height = '400px';

renderElementIntoDOM(target, {includeCommonStyles: true});

MyComponent.DEFAULT_VIEW(mockViewInput, undefined, target);

await assertScreenshot('my_component/base.png');

});

});

```

Prefer 600x400 for compact component views (and <= 600px tall,

such as 800x600, for full panels or split views) so containers fit

inside Karma's ~685px-tall test iframe without triggering and

capturing Karma's outer iframe scrollbar.

new MyWidget() defaults this.element to <div class="widget">

rather than <devtools-widget>. When testing a Light DOM widget

whose stylesheet uses an explicit @scope (devtools-widget) root,

instantiate new MyWidget(document.createElement('devtools-widget'))

(or mount via UI.Widget.widget(...)) so @scope rules match.

When calling DEFAULT_VIEW(input, output, target) directly for views

that render <devtools-split-view>, UI.Widget.WrapperWidget, or

imperatively attached child widgets:

instead of a plain document.createElement('div'), otherwise

widgetCounterMap underflows during cleanTestDOM() and throws

Attempt to modify widget with native DOM method removeChild.

new UI.Widget.VBox()) instead of

sinon.createStubInstance(MyWidget) (which stubs constraints()

to return undefined and throws on mount).

before teardown when child widgets are attached imperatively.

When scaffolding unit tests ahead of replacing a legacy widget engine

(TreeOutline, DataGrid, ListControl, ListWidget):

and element queries through small local helper functions (dumpTree(),

findTreeItem(), activateRow(), openContextMenuOnRow()) rather

than scattering direct internal widget queries across every it()

block. When the legacy widget is subsequently swapped for

<devtools-tree> or <devtools-data-grid>, only the helper

implementations change while dozens of tests remain untouched.

assertScreenshot(...) golden tests covering critical visual

states (grouping modes, icons/badges, dimmed/dirty states). Unit

tests often inspect internal state that changes during migration;

screenshot goldens ensure the user-visible UI remains identical.

  1. Wait for confirmation:

2. Environment Detection & Test Execution Guide

Always detect the execution environment first to run tests successfully:

Scenario A: Google-Internal Cog Workspaces (PRIMARY PATH for Google Workspaces)

/google/src/.

1. Ensure depot_tools is at the front of your PATH:

```bash

export PATH="/path/to/depot_tools:$PATH"

```

2. Execute tests using ./dt test directly from chromium/third_party/devtools-frontend/src:

```bash

./dt test front_end/panels/application/IndexedDBViews.test.ts

```

Scenario B: Standard Chromium Environment (Fallback)

checkout without Cog paths.

python3_bin_reldir.txt not found.

1. Export depot_tools path:

```bash

export PATH="/path/to/depot_tools:$PATH"

```

2. Initialize the depot_tools binaries by running update/gclient help

once from the checkout root:

```bash

update_depot_tools

```

3. Execute the tests:

```bash

./dt test front_end/panels/application/IndexedDBViews.test.ts

```

Scenario C: ESLint TS Module Resolution Failure (ERR_UNKNOWN_FILE_EXTENSION)

[ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension ".ts" for

scripts/eslint_rules/...`

1. Compile the custom eslint rules and build assets first so that Node can

parse the rules:

```bash

./dt build

```

Scenario D: Screenshot Test Fails (Visual Diffs > 0%)

1. Do NOT ask the user to accept the new screenshot yet.

2. Inspect the failure log to see if it is a layout shift or a missing style.

3. If it's a layout shift, check if you replaced a block element with an inline element (e.g. div -> span).

4. If styles are missing, verify if the test wrapper needs {includeCommonStyles: true}.

Scenario E: Lightweight Test Hook Gotchas (`describe` vs `describeWithEnvironment`)

When registering actions, shortcuts, or context menus in tests, singleton registries MUST be reset in afterEach:

```typescript

afterEach(() => {

UI.ActionRegistration.reset();

UI.ActionRegistry.ActionRegistry.reset();

UI.ShortcutRegistry.ShortcutRegistry.removeInstance();

});

```

Without these resets, repeated runs (such as --repeat=10 or CQ flake detection) will fail on iteration 2+ with Duplicate action ID: '...'.

If testing UI that opens a GlassPane or long-press option menu (e.g. bindToAction with long-press buttons) in a test suite using describe without describeWithEnvironment, call:

```typescript

beforeEach(() => {

UI.GlassPane.GlassPane.setContainer(document.body);

});

```

Otherwise, menu rendering will fail because GlassPane lacks an attached container element.

When a mounted panel or widget instantiates components that chain 3+ nested ScheduledRender passes (such as <devtools-shortcut-dialog> or <devtools-perf-export-trace-options> -> ButtonDialog -> Dialog), call await RenderCoordinator.done() after detach() in afterEach. Synchronous 0ms tests otherwise exceed checkForPendingActivity's retry budget under --repeat=10 CQ flake detection.

UI.Widget.prototype.requestUpdate() schedules performUpdate() on fake window.requestAnimationFrame (+16ms). Advance an additional animation frame (await clock.tickAsync(16) or clock.tick(16)) after fake-timer callbacks that trigger requestUpdate() (for example, clock.tick(300) for a popover delay) before asserting, before the test finishes when suite-level afterEach hooks reset state ahead of test_setup.ts (which otherwise drains and restores fake timers automatically, while @devtools/no-manual-sinon-restore forbids .restore() in after/afterEach), and before any mid-test clock.restore().


🔍 Mental Audit (Internal Self-Correction)

Before reporting back or committing, re-read the instructions and verify:

  1. ❓ Coverage: Did I cover all classes in the file, or only the main one?
  2. ❓ Stability: Can the tests run repeatedly without flakiness?
  3. ❓ Integrations: Did I verify that the component mounts correctly?
Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.