Skip to content

Test Mapping ​

SpecLore's acceptance verification (speclore verify) needs to map test results back to .feature scenarios. Three mapping methods are supported, listed by priority.


Mapping Priority ​

Mapping file (auto) → Explicit markers (manual) → unmapped

When generating test code, the AI automatically generates mapping files at .speclore/mappings/{module}/{feature}.json:

json
{
  "feature": "specs/order/create.feature",
  "generatedAt": "2024-01-15T10:30:00Z",
  "scenarios": {
    "Create order with valid items": {
      "testFile": "tests/order/create.test.ts",
      "testMethod": "should create order with valid items"
    },
    "Reject when inventory is insufficient": {
      "testFile": "tests/order/create.test.ts",
      "testMethod": "should reject when inventory is insufficient"
    }
  }
}

Mapping files are auto-generated by speclore code and auto-read when running speclore verify.


Method 2: Explicit Markers (Fallback) ​

Add @speclore-scenario comment markers in test files:

typescript
// @speclore-scenario: Create order with valid items
it('should create order with valid items', () => { ... });

// @speclore-scenario: Reject when inventory is insufficient
it('should reject when inventory is insufficient', () => { ... });

Method 3: Pattern Matching ​

Auto-match by path patterns configured in config.yaml verify.mapping.patterns:

yaml
verify:
  mapping:
    patterns:
      - feature: "specs/{module}/{name}.feature"
        test: "tests/{module}/{name}.test.*"

For example:

  • specs/order/create.feature → tests/order/create.test.ts
  • specs/patient/register.feature → tests/patient/register.test.ts

Unmapped Scenarios ​

Scenarios that cannot be mapped are flagged as unmapped and listed separately in the acceptance report:

json
{
  "summary": "3/5 scenarios passed (60%)",
  "passed": 3,
  "failed": 0,
  "unmapped": 2,
  "details": [
    {
      "feature": "specs/order/create.feature",
      "scenarios": [
        { "name": "Create order with valid items", "status": "passed", "testMethod": "should create order..." },
        { "name": "Reject when inventory is insufficient", "status": "unmapped", "reason": "No matching test found" }
      ]
    }
  ]
}

Unmapped scenarios do not block acceptance from passing, but are flagged in the report as a reminder.

Released under the MIT License.