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
- Verify Existing Tests:
- Inspect the co-located unit and screenshot test file alongside the
implementation in front_end/**/*.test.ts (for example,
front_end/panels/application/IndexedDBViews.test.ts for
IndexedDBViews.ts).
- Check for logic tests (verifying presenter interactions and view function callbacks).
- Check for
assertScreenshot(...)golden tests in the co-located
*.test.ts file (with Linux golden PNGs under test/goldens/linux/) and
full-browser E2E tests under test/e2e/ to verify layout and styling.
- Detect Sub-component Testing Gaps (Hybrid Files):
- Identify if the existing test suite only covers one class of a hybrid
file while missing another class being migrated (e.g., tests exist for
IDBDatabaseView but are scarce/missing for IDBDataView).
- Scaffold Missing Tests:
- If logic tests are missing, draft tests verifying that callbacks trigger the expected state updates or model interactions.
- If rendering/screenshot tests are missing or inadequate for the legacy class being
migrated, draft a basic Mocha/Chai rendering test.
- Verify that the component compiles and mounts successfully inside a
synthetic DOM helper or unit-test container.
- Screenshot Tests: Create screenshot tests to establish visual baselines before refactoring. Follow the pattern seen in
CategorizedBreakpointsSidebarPane.test.ts: - First run the test having
renderElementIntoDOMwith{includeCommonStyles: true}to ensure styles are applied. - The first run will generate the screenshot.
- Now try removing
{includeCommonStyles: true}to see if class is
adding the styles itself. If the test pass, keep the version without
{includeCommonStyles: true}. Otherwise, bring it back.
- Screenshot tests are unittests that render either the full widget (if not migrated to the MVP architecture) or its view function (if already in MVP shape).
- Ship unit tests in the same CL as the production code they cover; never defer tests to a follow-up test-only CL.
- Test presenter logic via
createViewFunctionStuband rely onassertScreenshot/ E2E tests for template layout (perdocs/ui_engineering.md). When adding targeted unit tests for view rendering, name the suitedescribe('view', ...)(neverdescribe('... DEFAULT_VIEW', ...)), and avoid verbose syntheticDEFAULT_VIEWDOM assertion suites that duplicate presenter assertions. - Example structure:
```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');
});
});
```
- Keep
assertScreenshotContainers Within Karma's Iframe Viewport:
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.
- Pass
document.createElement('devtools-widget')for@scope (devtools-widget)Light DOM Widgets:
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.
- Direct
DEFAULT_VIEWTests Hosting<devtools-split-view>orWrapperWidget:
When calling DEFAULT_VIEW(input, output, target) directly for views
that render <devtools-split-view>, UI.Widget.WrapperWidget, or
imperatively attached child widgets:
- Mount a root
UI.Widget.VBox(const container = renderElementIntoDOM(new UI.Widget.VBox()).contentElement;)
instead of a plain document.createElement('div'), otherwise
widgetCounterMap underflows during cleanTestDOM() and throws
Attempt to modify widget with native DOM method removeChild.
- Pass real child
UI.Widget.Widgetinstances (such as
new UI.Widget.VBox()) instead of
sinon.createStubInstance(MyWidget) (which stubs constraints()
to return undefined and throws on mount).
- Call
UI.Widget.Widget.get(container)?.detachChildWidgets()
before teardown when child widgets are attached imperatively.
- Implementation-Decoupled Helpers & Screenshot Baselines Before Replacing Legacy Widgets:
When scaffolding unit tests ahead of replacing a legacy widget engine
(TreeOutline, DataGrid, ListControl, ListWidget):
- Encapsulate DOM Inspection in Local Helpers: Route tree, row,
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.
- Mandatory Visual Regression Coverage: Always add
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.
- Wait for confirmation:
- Wait for an explicit confirmation from the user (or Parent Orchestrator Agent) before proceeding to the next step.
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)
- Detection: Triggered if the workspace path starts with
/google/cog/or
/google/src/.