DevelopOther
@holtkeeper/testids
The testids analyzer and analysis kind: lists the test attributes (data-test-id, data-test-state, data-qa, …) a checkout’s frontend templates (JSX/TSX, Vue, Svelte, HTML and Angular templates) expose, per component, so end-to-end tests can be written against them. Static: nothing is built or run.
Recommending test ids on new code is the job of the testids check (testIdsCheck), which the merge request review runs by default and hands to its agent, and of the MCP tool test_ids (existing ids, and suggestions for a file’s text). The analysis itself only catalogs what exists; the conventions those use are learned from the catalog (learnTestIdOptions), with the team’s overrides from the analyzers.testids setting on top. People see them in the Guide’s Test ids section, where the setting is edited too; there is no page of its own.
Public API
Section titled “Public API”testIdsAnalyzer—Analyzer<TestIdsData, TestIdsOptions>, kindtestids, scoperepo, needscheckout;appliesToruns it only on repositories with a file one of its sources reads (.jsx,.tsx,.js,.mjs,.vue,.svelte,.html) anywhere in the tree, so a Go service with its UI templates inweb/is analyzed and a Go service without one is skipped. Options (testIdsOptionsSchema; lists also accept a comma-separated string, as the flags pass them):attributes: string[](--attributes) — test attribute names, case-insensitive; each also covers names extending it with-, sodata-testcoversdata-test-idanddata-test-state. A dashed name also matches its camel-case prop forms, which components pass on:data-testcoversdataTest,dataTestIdanddataTestSpot. DefaultdefaultAttributes:data-testid,data-test,data-qa,data-cy,testID,testId. Set in theanalyzers.testidssetting, it also picks the attribute new ids use: the listed name the repository uses most (literal values first), or the first item when the repository uses none of them; order does not matter otherwise.sources: string[](--sources) — template sources by name frombuiltinSources:jsx,vue,svelte,html.exclude: string[](--exclude) — glob patterns of files to skip.elements?: string[]— native tags that need a test id, for the check and the suggestions oftest_ids; unset, learned from the catalog. The catalog ignores it.presets—testIdPresets:testing-library(data-testid),cypress(data-cy,data-test,data-testid),react-native(testID).
testIdsAnalysis— theAnalysisKind(schema: testIdsDataSchema,summarize,toReport); the report holds the headline numbers and the learned convention only.analyzeTestIds({ dir, sources?, attributes?, exclude?, signal? }): Promise<TestIdsData>— the catalog.testIdsCheck(options?)— aQualityChecknamedtestids(TESTIDS_TOOL): interactive elements without a test attribute asmissing-test-idissues (categorytests, severitywarning). It skips itself when the project uses no test attributes at all. Otherwise it learns the convention from the checkout’s catalog, appliesoptions.overrides(TestIdOverrides) and runsfindUntaggedwith the learned attributes, element kinds and naming. Each issue’shelpnames the id attribute the component (or else the project) uses most, never a name merely extending it, with example values, and an id suggested in the project’s style (suggested: \data-qa=“cart-row-remove-button”`). Other options are those offindUntaggedwithoutdirandnaming`.- Learned conventions (
learn.ts):learnTestIdOptions(data): LearnedTestIdOptions | undefined— from a catalog:attribute(idAttribute: the most used configured or well-known id name —data-testid,data-test-id,data-test,data-qa,data-cy,testID/testId— preferring one with literal values; a name merely extending one, likedata-test-state, wins only when no id name is in use),attributes(every name in use),elements(native tags ofdefaultTagsthat carry ids; only from 20 tagged elements on, before that the defaults apply),naming(TestIdNaming:separator-/_/./'',caselower/camel/pascal,prefixnone,componentin the same style ornameas written, each by majority vote),examplesandtagged. Deterministic, no LLM.testIdOverridesSchema/testIdOverridesOf(value)— the team’sattributes(new ids use the one the repository uses most, else the first),elementsandexcludefrom a rawanalyzers.testidsvalue; anything invalid reads as no override.testIdConvention(learned, overrides?)— the rules that apply, overrides winning field by field, withoverriddenlisting what the team set;undefinedwithout any attribute.renderTestIdConvention(convention)writes it as Markdown bullets.suggestTestId(element, component, naming)— an id from the component name (perprefix), what the element is for (itsname,aria-label,placeholder,title,alt,labelorid, else the function its handler calls withouthandle/on, else a component tag’s own name) and its kind (linkfora):cart-row-remove-button. The same input always gives the same id.
findUntagged({ dir, sources?, attributes?, exclude?, components?, factories?, aliases?, ignore?, tags?, events?, roles?, markers?, naming?, signal? }): Promise<UntaggedElement[]>— interactive elements without a test attribute (see below); withnamingeach one carries asuggestion.findUntaggedInText({ file, text, ...rules })— the same for one file’s text (unsaved content): styled components defined in the file are followed, imports are not; empty when no source reads the file.components: Record<string, string>— component name or*pattern → native tag it renders, e.g.{ "Button": "button", "*Link": "a", "el-button": "button" }. Checked before anything else; matches the whole name or its last.segment.factories: string[]— names whose.tag,('tag')and(Component)results are styled tags. DefaultdefaultFactories:styled,tw,chakra,motion.aliases: Record<string, string>— import prefix → folder, on top ofcompilerOptions.pathsof the roottsconfig.json/jsconfig.json, e.g.{ "@/": "src/" }.ignore: string[]— tag or component names (*patterns) never reported, e.g.Trans.tags,events,roles,markers— what counts as interactive; defaultsdefaultTags,defaultEvents,defaultRoles,defaultMarkers.
- Extension points:
TemplateSource—{ name, matches(file), scan(text, file) }; pass your own insourcesto read another template format. Built in:jsxSource,vueSource,svelteSource,htmlSource.scanTags(text, 'jsx' | 'html')— the tolerant tag scanner sources build on; attributes keep their literalvalueor theirexpressionas written.onlyTemplate(text)andblankBlocks(text, names)cut SFC blocks while keeping line numbers.createResolver(options)andparseModule(text, factories)— component → native tag resolution.createClassifier(rules),createAttributeMatcher(attributes),eventOf(name),bareName(name)— what is interactive and what is a test attribute.
- Helpers:
attributeUsage(components),componentName(file),tsconfigAliases(dir).
How the catalog is built
Section titled “How the catalog is built”- Files — every file
listFileslists (dependency, build and hidden folders skipped) that a source matches, except tests, stories, mocks, fixtures andexcludematches.jsxreads.jsx,.tsxand.js/.mjsfiles that contain JSX;vuethe outer<template>;svelteandhtmlthe markup outside<script>and<style>. - Tags — a scanner, not a parser: in JSX
<opens a tag only where an expression can start (not after an identifier,)or], except afterreturn,yieldand similar), so comparisons and type arguments are skipped; tags inside{…}attribute expressions are found too, as are lithtml\…`templates. Attributes keep their written names (:data-test-state,[attr.data-cy]`). - Component — one per template file, named after the file (
LoginForm.tsx→LoginForm,user.component.html→user);index.*and SvelteKit+page.*files take their folder’s name. - Attributes — every element with at least one test attribute, with each test attribute’s bare name and value: quoted values and string literals (
{"save"},:data-test="'save'",`save`) are static; bindings and templates with placeholders aredynamicand keep the expression as written (status,`row-${id}`).
How untagged elements are found
Section titled “How untagged elements are found”Used by findUntagged and the check, not by the catalog.
- Native tag — lower-case names are native. Other names go through
components, then<factory>.tagmembers (<motion.button>), then styled definitions:const X = styled.button,styled('a'),styled(Other)(linaria, styled-components, emotion, MUI, chakra, tailwind-styled-components), followed across named, default and namespace imports (<S.Submit>),export { … } from,export * frombarrels, relative paths and aliases. Components it cannot see through (a design system’sButton, a Vue SFC) stay unresolved. - Interactive — a native tag in
tags(a,button,inputexcepttype="hidden",select,textarea,summary); any element or component with a handler for one ofevents(click,press,change,input,submit, …, in any binding syntax), a widgetrole,contenteditableor a non-negativetabindex; and an unresolved component (ora) with one ofmarkers(href,to,routerLink,v-model,bind:value, …).onCloseon aModaldoes not count; map such components incomponentswhen they render a control. - Verdict — tagged when any attribute matches
attributes; otherwiseunverifiedwhen the element spreads props (its caller may pass a test id) andmissingwhen not. The check reports onlymissing.
interface TestIdsData { attributes: string[] // configured names; each also covers `<name>-…` components: { name: string // LoginForm file: string source: string // jsx, vue, svelte, html total: number // elements with test attributes elements: { // in line order, at most 500 per file line: number tag: string // as written: S.Submit attributes: { name: string; value: string; dynamic?: boolean }[] }[] }[]}Only files with at least one test attribute are kept. Analyses stored before the catalog read as empty.
Report
Section titled “Report”- Metrics — components with test attributes, elements with test attributes, attribute names in use.
- Convention — the learned convention (
renderTestIdConvention).
It runs in the default tests-weekly schedule (Wednesday nights). Records stored before the catalog read as empty.
Limitations
Section titled “Limitations”- The scanner is heuristic: a JSX tag right after an identifier other than the listed keywords is missed, and
<comparisons written without spaces afterreturnread as tags. - A component is a file: files that define several components list them together, and attributes passed down to a wrapper show up where they are written, not where they end up in the DOM.
- Wrapper components written by hand (
const Button = (props) => <button {...props} />) are not resolved when looking for untagged elements; their own<button {...props}>isunverified, and their callers count only by handlers and markers. Map them incomponents. - Styled definitions are recognized only as
const/let/vardeclarations orexport default; object members (S = { Button: styled.button }) are not. Bare package imports (@company/ui) are not followed.