UNPKG

userface

Version:

Universal Data-Driven UI Engine with live data, validation, and multi-platform support

145 lines (144 loc) 4.56 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.testingInfrastructure = exports.TestingInfrastructure = void 0; const logger_1 = require("./engine/logger"); class TestingInfrastructure { constructor() { Object.defineProperty(this, "testSuites", { enumerable: true, configurable: true, writable: true, value: [] }); Object.defineProperty(this, "results", { enumerable: true, configurable: true, writable: true, value: [] }); Object.defineProperty(this, "environment", { enumerable: true, configurable: true, writable: true, value: { registry: null, mockComponents: [] } }); Object.defineProperty(this, "mockComponents", { enumerable: true, configurable: true, writable: true, value: new Map() }); } async runTest(testName, testFn) { const startTime = Date.now(); let passed = false; let error; try { await testFn(); passed = true; } catch (err) { error = err instanceof Error ? err.message : String(err); } const duration = Date.now() - startTime; const result = { name: testName, passed, error, duration }; this.results.push(result); return result; } async runTestSuite(suiteName, tests) { logger_1.logger.info(`Running test suite: ${suiteName}`); const results = []; for (const testCase of tests) { const result = await this.runTest(testCase.name, testCase.test); results.push(result); } return results; } createMockComponent(name, schema, renderFn) { const mockComponent = { name, schema, render: renderFn || ((props) => ({ type: 'div', props })) }; this.mockComponents.set(name, mockComponent); return mockComponent; } getMockComponent(name) { return this.mockComponents.get(name); } getAllMockComponents() { return Array.from(this.mockComponents.values()); } generateTestData(schema) { const testData = { component: schema.name }; // Генерируем тестовые пропы for (const prop of schema.props) { switch (prop.type) { case 'text': testData[prop.name] = `Test ${prop.name}`; break; case 'number': testData[prop.name] = 42; break; case 'boolean': testData[prop.name] = true; break; case 'array': testData[prop.name] = []; break; case 'object': testData[prop.name] = {}; break; default: testData[prop.name] = null; } } return testData; } getTestResults() { return [...this.results]; } clearTestResults() { this.results = []; } getTestSummary() { const total = this.results.length; const passed = this.results.filter(r => r.passed).length; const failed = total - passed; const duration = this.results.reduce((sum, r) => sum + r.duration, 0); return { total, passed, failed, duration }; } // === НОВЫЕ МЕТОДЫ ИЗ .D.TS === addTestSuite(suite) { this.testSuites.push(suite); } createTestCase(name, test, options) { return { name, test: test, ...options }; } async runAllTests() { const allResults = []; for (const suite of this.testSuites) { const suiteResults = await this.runTestSuite(suite.name, suite.tests); allResults.push(...suiteResults); } return allResults; } generateRandomUserFace(schema) { return this.generateTestData(schema); } mockComponent(name, schema, render) { this.createMockComponent(name, schema, render); } } exports.TestingInfrastructure = TestingInfrastructure; // Создаем глобальный экземпляр exports.testingInfrastructure = new TestingInfrastructure();