Skip to content

Remove duplicated code from shared, core, backend and conformance - #521

Merged
vishnuv688 merged 1 commit into
mainfrom
refactor/library-duplicates
Nov 2, 2026
Merged

vishnuv688 merged 1 commit into
mainfrom
refactor/library-duplicates

Conversation

@vishnuv688

@vishnuv688 vishnuv688 commented Oct 30, 2026 •

Copy link
Copy Markdown
Member

What & why

Part of #528 and #494. Stacked on #520.

A duplicate-block scan found code repeated within and across the library packages. Each true duplicate now lives once, in the package the import rules allow; lookalikes with different purposes stay, with the reason below. No behaviour change.

Type of change

  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Polish (an improvement to an existing feature)
  • Breaking change (existing behavior changes for users)
  • Documentation
  • Internal (build, CI, dependencies, tooling)

Packages touched

  • shared (types and contracts)
  • core (framework-agnostic capture/reporting)
  • elements (published element/snapshot API — @wdio/elements)
  • service (WebdriverIO adapter)
  • nightwatch-devtools (Nightwatch adapter)
  • selenium-devtools (Selenium adapter)
  • selenium-devtools-py (Selenium Python adapter)
  • backend (server)
  • app (UI)
  • script (page-injected runtime)
  • trace (Trace mode)

Plus conformance, which the list does not include.

Capability matrix

  • packages/conformance/src/features.ts updated, and tables regenerated with pnpm docs:capabilities, if this adds or changes user-facing behaviour

Not needed: no behaviour change.

Notes for reviewers

Finding Decision
shared/element-scripts.ts: the accessibility-tree and elements page scripts each defined getAccessibleName's explicit-name steps Shared as source text, EXPLICIT_NAME_SCRIPT, the way they already share IS_VISIBLE_SCRIPT: each script is serialized and runs in the page on its own, so they cannot share a function. Each keeps its own fallbacks
core/locators: automationName…includes('uiautomator'), five times across two files One helper, isUiAutomatorDriver, not added to the locators index, so @wdio/elements' API is unchanged
Backend NIGHTWATCH_CONFIG_FILENAMES and Nightwatch CONFIG_FILENAMES Moved to shared/runner.ts with WDIO_CONFIG_FILENAMES; the backend's now-empty types.ts re-export is deleted
conformance/allowlist.ts: two entries listing the same six rules for one root cause Shared as SCRIPT_INJECTION_RULES; each entry keeps its own reason
core/locators/index.ts vs elements/locators/index.ts Kept. Not a duplicated module: elements already re-exports core. Its explicit export list is the gate on that published package's API; export * would publish every future core export
Backend and Nightwatch upward search for a config file Kept. They start from different places (a spec's folder, the working directory) and shared has no Node I/O

Scan for these packages: 6 blocks before, 3 after (the 3 kept above).

Why this touches an adapter: only to delete Nightwatch's copy of the config file list in favour of shared's; no adapter logic changes.

Testing

  • pnpm install --frozen-lockfile, pnpm build, pnpm test (3428 passed) and pnpm lint are green; no workspace import leaks in the elements, backend, service, Selenium or Nightwatch bundles.
  • New tests: 10 that run both page scripts in happy-dom over every naming source and the places they differ (they also pass on the code before this change, so they pin existing behaviour); isUiAutomatorDriver across drivers and case, and the Android vs iOS branch of getSuggestedLocators; the config file name lists.
  • @wdio/elements' .d.ts files are byte-identical to before, and its export list is unchanged.

Screenshots / recordings

Not applicable: no UI change.

🤖 Generated with Claude Code

A duplicate-block scan found code repeated within and across the library
packages. Each true duplicate now lives once, in the package the import
rules allow:

- The accessibility tree and elements page scripts each defined
  getAccessibleName's explicit-name steps; they share the source as
  EXPLICIT_NAME_SCRIPT, as they already share IS_VISIBLE_SCRIPT, since each
  script runs in the page on its own and cannot share a function.
- automationName's UiAutomator check appeared five times in core's locator
  code; it is now isUiAutomatorDriver.
- The backend and Nightwatch each listed the Nightwatch config file names;
  the list, with the WDIO one beside it, is now in shared.
- Two conformance allowlist entries repeated the same six rules for the
  same root cause; they share SCRIPT_INJECTION_RULES.

Kept: elements' locators index names core's exports one by one on purpose,
as the gate on that published package's API, and the backend and Nightwatch
each keep their own config-file search, which start from different places.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@vishnuv688
vishnuv688 force-pushed the refactor/app-style-duplicates branch from 1176e67 to d22a316 Compare October 30, 2026 10:13
@vishnuv688
vishnuv688 force-pushed the refactor/library-duplicates branch from aea93af to 7aa154b Compare October 30, 2026 10:13
@vishnuv688
vishnuv688 changed the base branch from refactor/app-style-duplicates to main November 2, 2026 10:12
@vishnuv688
vishnuv688 merged commit 1731def into main Nov 2, 2026
10 checks passed
@vishnuv688
vishnuv688 deleted the refactor/library-duplicates branch November 2, 2026 10:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant