diff --git a/sasjs-tests/src/components/TestSuite.ts b/sasjs-tests/src/components/TestSuite.ts index 3403d6e..3b484b0 100644 --- a/sasjs-tests/src/components/TestSuite.ts +++ b/sasjs-tests/src/components/TestSuite.ts @@ -32,6 +32,40 @@ export class TestSuiteElement extends HTMLElement { return this._suiteIndex } + updateTest(testIndex: number, testData: any) { + if (!this._suiteData) return + + // Update the data + this._suiteData.completedTests[testIndex] = testData + + // Update stats + this.updateStats() + + // Update the specific test card + const testsContainer = this.shadow.getElementById('tests-container') + if (testsContainer) { + const cards = testsContainer.querySelectorAll('test-card') + const card = cards[testIndex] as TestCard + if (card) { + card.testData = testData + } + } + } + + updateStats() { + if (!this._suiteData) return + + const { completedTests } = this._suiteData + const passed = completedTests.filter((t) => t.status === 'passed').length + const failed = completedTests.filter((t) => t.status === 'failed').length + const running = completedTests.filter((t) => t.status === 'running').length + + const statsEl = this.shadow.querySelector('.stats') + if (statsEl) { + statsEl.textContent = `Passed: ${passed} | Failed: ${failed} | Running: ${running}` + } + } + render() { if (!this._suiteData) return diff --git a/sasjs-tests/src/components/TestsView.ts b/sasjs-tests/src/components/TestsView.ts index 58bf2d1..63f9570 100644 --- a/sasjs-tests/src/components/TestsView.ts +++ b/sasjs-tests/src/components/TestsView.ts @@ -146,8 +146,12 @@ export class TestsView extends HTMLElement { await this.testRunner.rerunTest( suiteIndex, testIndex, - (completedSuites) => { - this.renderResults(container, completedSuites) + (suiteIdx, testIdx, testData) => { + const suites = container.querySelectorAll('test-suite') + const suiteElement = suites[suiteIdx] as TestSuiteElement + if (suiteElement && suiteElement.updateTest) { + suiteElement.updateTest(testIdx, testData) + } } ) } diff --git a/sasjs-tests/src/core/TestRunner.ts b/sasjs-tests/src/core/TestRunner.ts index 0adbefe..1fcc583 100644 --- a/sasjs-tests/src/core/TestRunner.ts +++ b/sasjs-tests/src/core/TestRunner.ts @@ -117,7 +117,11 @@ export class TestRunner { async rerunTest( suiteIndex: number, testIndex: number, - onUpdate?: (completedSuites: CompletedTestSuite[]) => void + onUpdate?: ( + suiteIndex: number, + testIndex: number, + testData: CompletedTest + ) => void ): Promise { const suite = this.testSuites[suiteIndex] const test = suite.tests[testIndex] @@ -131,7 +135,11 @@ export class TestRunner { this.completedTestSuites[suiteIndex].completedTests[testIndex].status = 'running' if (onUpdate) { - onUpdate([...this.completedTestSuites]) + onUpdate( + suiteIndex, + testIndex, + this.completedTestSuites[suiteIndex].completedTests[testIndex] + ) } // Execute test @@ -147,7 +155,11 @@ export class TestRunner { } if (onUpdate) { - onUpdate([...this.completedTestSuites]) + onUpdate( + suiteIndex, + testIndex, + this.completedTestSuites[suiteIndex].completedTests[testIndex] + ) } }