@fromeroc9/testform 1.1.0-beta.2 → 1.1.0-beta.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fromeroc9/testform",
3
- "version": "1.1.0-beta.2",
3
+ "version": "1.1.0-beta.4",
4
4
  "description": "Declarative Test-as-Code orchestration engine for Git: zero mandatory SaaS servers, zero test drift, and immutable quality management.",
5
5
  "author": "Flavio Romero <flavio.arc9@gmail.com>",
6
6
  "main": "dist/index.js",
@@ -47,7 +47,6 @@
47
47
  "@vercel/ncc": "0.38.4",
48
48
  "docx": "^9.14.0",
49
49
  "exceljs": "^4.4.0",
50
- "prettier": "^3.5.0",
51
50
  "tsx": "4.19.3",
52
51
  "typescript": "5.8.2",
53
52
  "vitest": "^5.0.5"
@@ -0,0 +1,25 @@
1
+ import { PolicyDefinition, PolicyRule, IScope, ParserScenario } from '@fromeroc9/testform';
2
+
3
+ export const {{POLICY_VAR}}: PolicyDefinition = {
4
+ id: "{{POLICY_ID}}",
5
+ description: "Custom quality policy {{POLICY_ID}}",
6
+ scope: ["testcase"],
7
+ severity: "error",
8
+ action: (scenarios: ParserScenario[], rules: PolicyRule[], scope: IScope) => {
9
+ for (const scenario of scenarios) {
10
+ // Implement custom quality rules and validations
11
+ // Push diagnostic violations to rules array:
12
+ // rules.push({
13
+ // id: "{{POLICY_ID}}",
14
+ // type: 'error', // 'error' | 'warning' | 'advisory'
15
+ // title: "Rule violated summary",
16
+ // detail: "Specific explanation and actionable suggestion",
17
+ // uri: scenario.uri,
18
+ // scenario: scenario.name,
19
+ // line: scenario.location
20
+ // });
21
+ }
22
+ }
23
+ };
24
+
25
+ export default {{POLICY_VAR}};
@@ -0,0 +1,60 @@
1
+ import { IProvider, IProviderResourceHandler } from '@fromeroc9/testform';
2
+
3
+ export interface ICustomProviderConfig {
4
+ baseUrl?: string;
5
+ token?: string;
6
+ tokenEnv?: string;
7
+ [key: string]: any;
8
+ }
9
+
10
+ export default class CustomProvider implements IProvider {
11
+ public name = 'custom-provider';
12
+
13
+ /**
14
+ * Formats remote identifiers for terminal displays and state ledger.
15
+ * Examples: '#101', 'QA-504', 'GL#203', 'REMOTE:42'
16
+ */
17
+ formatRemoteId(id: number | string): string {
18
+ return `#${id}`;
19
+ }
20
+
21
+ /**
22
+ * Agnostic resource bus exposing standard CRUD lifecycle methods and REST aliases.
23
+ * Define any entity your provider manages (e.g. testcase, defect, testrun, badge).
24
+ */
25
+ public resources: Record<string, IProviderResourceHandler> = {
26
+ testcase: {
27
+ create: async (attributes: any, context?: any) => {
28
+ // Perform remote API creation (e.g. POST /api/v1/testcases)
29
+ return {
30
+ id: Date.now(),
31
+ number: Math.floor(Math.random() * 1000),
32
+ ...attributes
33
+ };
34
+ },
35
+ read: async (id: number | string, context?: any) => {
36
+ // Perform remote lookup (e.g. GET /api/v1/testcases/:id)
37
+ return null;
38
+ },
39
+ update: async (id: number | string, attributes: any, context?: any) => {
40
+ // Perform remote update (e.g. PUT/PATCH /api/v1/testcases/:id)
41
+ return {
42
+ id,
43
+ ...attributes
44
+ };
45
+ },
46
+ delete: async (id: number | string, context?: any) => {
47
+ // Perform remote deletion (e.g. DELETE /api/v1/testcases/:id)
48
+ }
49
+ }
50
+ };
51
+
52
+ /**
53
+ * Backward compatibility alias for resources.
54
+ */
55
+ public get apis(): Record<string, IProviderResourceHandler> {
56
+ return this.resources;
57
+ }
58
+
59
+ constructor(public config: ICustomProviderConfig = {}) {}
60
+ }
@@ -0,0 +1,53 @@
1
+ import { ResourceTemplate, ParserScenario } from '@fromeroc9/testform';
2
+
3
+ export const {{RESOURCE_VAR}}Resource: ResourceTemplate = {
4
+ // Unique resource type identifier (e.g. "provider_entity", "pokedex_register-pokemon")
5
+ type: "{{RESOURCE_TYPE}}",
6
+
7
+ /**
8
+ * Canonical attributes evaluated from the Gherkin scenario.
9
+ * These attributes map directly to the provider's resource handler payload (IProviderResourceHandler).
10
+ */
11
+ attributes: (scenario: ParserScenario, context?: any) => ({
12
+ title: scenario.name,
13
+ description: scenario.description,
14
+ tags: scenario.tags,
15
+ // Map custom fields declared in scenario:
16
+ ...scenario.custom?.fields
17
+ }),
18
+
19
+ /**
20
+ * Internal state attributes stored directly in the state ledger (.testform/state.json).
21
+ */
22
+ state: {
23
+ status: (scenario: ParserScenario) => scenario.custom?.fields?.status || 'active',
24
+ synced_at: () => new Date().toISOString()
25
+ },
26
+
27
+ /**
28
+ * Optional lifecycle hooks to orchestrate provider actions before/after CRUD events.
29
+ */
30
+ lifecycle: {
31
+ beforeCreate: async ({ attributes, scenario, context }) => {
32
+ // Optional pre-validation logic before remote creation
33
+ },
34
+ afterCreate: async ({ id, attributes, provider, scenario, context }) => {
35
+ // Runs after remote creation; receives remote ID and live provider instance
36
+ // e.g. await provider.subirFoto?.(id, './assets/foto.png');
37
+ },
38
+ beforeUpdate: async ({ id, attributes, provider, scenario, context }) => {
39
+ // Runs before remote update
40
+ },
41
+ afterUpdate: async ({ id, attributes, diff, provider, scenario, context }) => {
42
+ // Runs after remote update
43
+ },
44
+ beforeDelete: async ({ id, provider, context }) => {
45
+ // Runs before remote deletion
46
+ },
47
+ afterDelete: async ({ id, provider, context }) => {
48
+ // Runs after remote deletion
49
+ }
50
+ }
51
+ };
52
+
53
+ export default {{RESOURCE_VAR}}Resource;
@@ -0,0 +1,31 @@
1
+ # Testform Provider: Starter
2
+
3
+ Custom provider template implementing the agnostic Testform `IProvider` specification.
4
+
5
+ ## Usage in Testform Projects
6
+
7
+ Add this provider to your project's `main.yml`:
8
+
9
+ ```yaml
10
+ testform:
11
+ required_providers:
12
+ starter-provider: "git::https://github.com/my-org/testform-provider-starter.git?ref=v1.0.0"
13
+
14
+ provider:
15
+ starter-provider:
16
+ baseUrl: "https://api.myplatform.com"
17
+ tokenEnv: "STARTER_API_TOKEN"
18
+ ```
19
+
20
+ ## Development
21
+
22
+ ```bash
23
+ # Install dependencies
24
+ npm install
25
+
26
+ # Run unit tests
27
+ npm test
28
+
29
+ # Build distribution bundle
30
+ npm run build
31
+ ```
@@ -0,0 +1,19 @@
1
+ {
2
+ "name": "testform-provider-starter",
3
+ "version": "1.0.0",
4
+ "description": "Enterprise quality management provider for Testform",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "license": "MIT",
8
+ "scripts": {
9
+ "build": "tsc",
10
+ "test": "vitest run"
11
+ },
12
+ "dependencies": {
13
+ "@fromeroc9/testform": "1.1.0-beta.4"
14
+ },
15
+ "devDependencies": {
16
+ "typescript": "^5.8.0",
17
+ "vitest": "^3.0.0"
18
+ }
19
+ }
@@ -0,0 +1,37 @@
1
+ import { IStarterProviderConfig, IRemoteResourceAttributes, IRemoteResourceResult } from './types';
2
+
3
+ export class StarterApiClient {
4
+ private baseUrl: string;
5
+ private token?: string;
6
+
7
+ constructor(config: IStarterProviderConfig) {
8
+ this.baseUrl = config.baseUrl || 'https://api.example.com';
9
+ this.token = config.token || (config.tokenEnv ? process.env[config.tokenEnv] : undefined);
10
+ }
11
+
12
+ async createResource(attrs: IRemoteResourceAttributes): Promise<IRemoteResourceResult> {
13
+ // Replace with real HTTP API call (e.g. fetch or axios)
14
+ return {
15
+ id: Date.now(),
16
+ number: Math.floor(Math.random() * 1000),
17
+ ...attrs
18
+ };
19
+ }
20
+
21
+ async getResource(id: string | number): Promise<IRemoteResourceResult | null> {
22
+ // Replace with real HTTP GET lookup
23
+ return null;
24
+ }
25
+
26
+ async updateResource(id: string | number, attrs: Partial<IRemoteResourceAttributes>): Promise<IRemoteResourceResult> {
27
+ // Replace with real HTTP PUT/PATCH call
28
+ return {
29
+ id,
30
+ ...attrs
31
+ };
32
+ }
33
+
34
+ async deleteResource(id: string | number): Promise<void> {
35
+ // Replace with real HTTP DELETE call
36
+ }
37
+ }
@@ -0,0 +1,46 @@
1
+ import { IProvider, IProviderResourceHandler } from '@fromeroc9/testform';
2
+ import { StarterApiClient } from './client';
3
+ import { IStarterProviderConfig } from './types';
4
+
5
+ export class StarterProvider implements IProvider {
6
+ public name = 'starter-provider';
7
+ private client: StarterApiClient;
8
+
9
+ constructor(public config: IStarterProviderConfig = {}) {
10
+ this.client = new StarterApiClient(config);
11
+ }
12
+
13
+ /**
14
+ * Formats the remote identifier shown in CLI output and state file.
15
+ * Examples: 'REMOTE#105', '#105', 'QA-402'
16
+ */
17
+ formatRemoteId(id: number | string): string {
18
+ return `REMOTE#${id}`;
19
+ }
20
+
21
+ /**
22
+ * Multi-resource CRUD handler bus.
23
+ */
24
+ public resources: Record<string, IProviderResourceHandler> = {
25
+ testcase: {
26
+ create: async (attrs, context) => this.client.createResource(attrs),
27
+ read: async (id, context) => this.client.getResource(id),
28
+ update: async (id, attrs, context) => this.client.updateResource(id, attrs),
29
+ delete: async (id, context) => this.client.deleteResource(id),
30
+ // REST aliases
31
+ post: async (attrs, context) => this.client.createResource(attrs),
32
+ get: async (id, context) => this.client.getResource(id),
33
+ patch: async (id, attrs, context) => this.client.updateResource(id, attrs),
34
+ put: async (id, attrs, context) => this.client.updateResource(id, attrs)
35
+ }
36
+ };
37
+
38
+ /**
39
+ * Backward compatibility alias for resources.
40
+ */
41
+ public get apis(): Record<string, IProviderResourceHandler> {
42
+ return this.resources;
43
+ }
44
+ }
45
+
46
+ export default StarterProvider;
@@ -0,0 +1,20 @@
1
+ export interface IStarterProviderConfig {
2
+ baseUrl?: string;
3
+ token?: string;
4
+ tokenEnv?: string;
5
+ [key: string]: any;
6
+ }
7
+
8
+ export interface IRemoteResourceAttributes {
9
+ title: string;
10
+ description?: string;
11
+ labels?: string[];
12
+ [key: string]: any;
13
+ }
14
+
15
+ export interface IRemoteResourceResult {
16
+ id: string | number;
17
+ number?: number;
18
+ title?: string;
19
+ [key: string]: any;
20
+ }
@@ -0,0 +1,21 @@
1
+ import { describe, it, expect } from 'vitest';
2
+ import { StarterProvider } from '../src/index';
3
+
4
+ describe('StarterProvider', () => {
5
+ it('instantiates and formats remote id', () => {
6
+ const provider = new StarterProvider({ baseUrl: 'https://api.test' });
7
+ expect(provider.name).toBe('starter-provider');
8
+ expect(provider.formatRemoteId(101)).toBe('REMOTE#101');
9
+ });
10
+
11
+ it('exposes CRUD handlers on resources.testcase', async () => {
12
+ const provider = new StarterProvider();
13
+ const handler = provider.resources.testcase;
14
+ expect(handler).toBeDefined();
15
+
16
+ const created = await handler.create!({ title: 'Sample Test Case' });
17
+ expect(created).toBeDefined();
18
+ expect(created.title).toBe('Sample Test Case');
19
+ expect(created.id).toBeDefined();
20
+ });
21
+ });
@@ -0,0 +1,14 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2022",
4
+ "module": "NodeNext",
5
+ "moduleResolution": "NodeNext",
6
+ "declaration": true,
7
+ "outDir": "./dist",
8
+ "rootDir": "./src",
9
+ "strict": true,
10
+ "esModuleInterop": true,
11
+ "skipLibCheck": true
12
+ },
13
+ "include": ["src/**/*"]
14
+ }