Resources: registerResource
The resources module defines how Gherkin scenarios (Scenario:) are mapped into structured attributes recognized by test management systems (Jira, Zephyr, Azure DevOps, TestRail, or proprietary APIs).
Function Signatures
Section titled “Function Signatures”import { registerResource, ResourceTemplate } from '@fromeroc9/testform@beta';
// Register a new resource type or override an existing templatefunction registerResource(template: ResourceTemplate): void;Types & Interfaces
Section titled “Types & Interfaces”ResourceTemplate
Section titled “ResourceTemplate”Defines field mappings and execution comment generators for a resource type:
export interface ResourceTemplate { /** Unique resource type name (e.g., 'jira_testcase', 'azure_testrun', 'github_testcase') */ type: string;
/** List of fields extracted from the Gherkin scenario */ fields: ResourceField[];
/** Optional generator producing execution evidence and test comments */ comments?: ( scenario: any, context?: any ) => Array<{ identity: string; status: string; body: string; title: string; }>;}ResourceField
Section titled “ResourceField”Describes an individual attribute mapping:
export interface ResourceField { /** Field name expected by the remote provider or target schema */ name: string;
/** Static value or extractor function receiving the scenario and context */ value: ((scenario: any, context?: any) => string | string[]) | string | string[];
/** True if the value is generated remotely during apply (e.g., remote ID) */ knownAfterApply?: boolean;}Usage Patterns
Section titled “Usage Patterns”1. Registering a New Resource Type (registerResource)
Section titled “1. Registering a New Resource Type (registerResource)”Create .testform/resources/azure-devops.js:
module.exports = { type: 'azure_testcase', fields: [ { name: 'title', value: (scenario) => scenario.name, }, { name: 'description', value: (scenario) => scenario.description || 'No description provided', }, { name: 'priority', value: (scenario) => scenario.custom?.fields?.priority || '2', }, { name: 'steps_count', value: (scenario) => String(scenario.steps?.length || 0), }, { name: 'tags', value: (scenario) => scenario.tags.filter(t => !t.startsWith('@tc-')), }, { name: 'remote_work_item_id', value: () => '(known after apply)', knownAfterApply: true, } ], comments: (scenario, context) => [ { identity: scenario.custom?.identity || scenario.name, status: scenario.custom?.fields?.status || 'passed', title: `CI/CD Run #${context?.buildId || 'local'}`, body: `Automated test run dispatched on environment: ${context?.environment || 'staging'}` } ]};Runtime Inspection (resource)
Section titled “Runtime Inspection (resource)”The resource singleton enables querying registered templates:
import { resource } from '@fromeroc9/testform@beta';
// Get list of all registered resource type namesconst types = resource.getRegisteredTypes();// ['github_testcase', 'github_testrun', 'testcase', 'azure_testcase', ...]