( runtime, options, )
| 169 | }; |
| 170 | |
| 171 | export const getCommand: RuntimeCommand<GetCommandOptions, GetCommandResult> = async ( |
| 172 | runtime, |
| 173 | options, |
| 174 | ): Promise<GetCommandResult> => { |
| 175 | if (options.target.kind === 'ref') { |
| 176 | const capture = await requireSnapshotSession(runtime, options.session); |
| 177 | const resolved = resolveRefNode(capture.snapshot.nodes, options.target.ref, { |
| 178 | fallbackLabel: options.target.fallbackLabel ?? '', |
| 179 | invalidRefMessage: 'get text requires a ref like @e2', |
| 180 | notFoundMessage: `Ref ${options.target.ref} not found`, |
| 181 | }); |
| 182 | const selectorChain = buildSelectorChainForNode(resolved.node, runtime.backend.platform, { |
| 183 | action: 'get', |
| 184 | }); |
| 185 | const target = { kind: 'ref' as const, ref: `@${resolved.ref}` }; |
| 186 | if (options.property === 'attrs') { |
| 187 | return { kind: 'attrs', target, node: resolved.node, selectorChain }; |
| 188 | } |
| 189 | const text = await readText(runtime, capture, resolved.node); |
| 190 | return { kind: 'text', target, text, node: resolved.node, selectorChain }; |
| 191 | } |
| 192 | |
| 193 | const resolved = await resolveSelectorNode(runtime, options, options.session ?? 'default', { |
| 194 | selector: options.target.selector, |
| 195 | disambiguateAmbiguous: options.property === 'text', |
| 196 | }); |
| 197 | |
| 198 | const selectorChain = buildSelectorChainForNode(resolved.node, runtime.backend.platform, { |
| 199 | action: 'get', |
| 200 | }); |
| 201 | |
| 202 | if (options.property === 'attrs') { |
| 203 | return { |
| 204 | kind: 'attrs', |
| 205 | target: { kind: 'selector', selector: resolved.selector }, |
| 206 | node: resolved.node, |
| 207 | selectorChain, |
| 208 | }; |
| 209 | } |
| 210 | |
| 211 | const text = await readText(runtime, resolved.capture, resolved.node); |
| 212 | return { |
| 213 | kind: 'text', |
| 214 | target: { kind: 'selector', selector: resolved.selector }, |
| 215 | text, |
| 216 | node: resolved.node, |
| 217 | selectorChain, |
| 218 | }; |
| 219 | }; |
| 220 | |
| 221 | export const getTextCommand: RuntimeCommand< |
| 222 | GetTextCommandOptions, |
no test coverage detected