Skip to content

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).


import { registerResource, ResourceTemplate } from '@fromeroc9/testform@beta';
// Register a new resource type or override an existing template
function registerResource(template: ResourceTemplate): void;

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;
}>;
}

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;
}

1. Registering a New Resource Type (registerResource)

Section titled “1. Registering a New Resource Type (registerResource)”

Create .testform/resources/azure-devops.js:

.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'}`
}
]
};

The resource singleton enables querying registered templates:

import { resource } from '@fromeroc9/testform@beta';
// Get list of all registered resource type names
const types = resource.getRegisteredTypes();
// ['github_testcase', 'github_testrun', 'testcase', 'azure_testcase', ...]