1+ // import { MatlabTestStatus, getTestResults, writeSummary } from './testResultsSummary';
2+ // import * as core from '@actions/core';
3+ // import { existsSync, writeFileSync, unlinkSync } from 'fs';
4+ // import * as path from 'path';
5+
6+ // describe('Test Results Summary', () => {
7+ // const mockTestData = {
8+ // BaseFolder: '/test/path',
9+ // TestResult: {
10+ // Name: 'TestFile/TestCase1',
11+ // Duration: 1.234,
12+ // Failed: false,
13+ // Passed: true,
14+ // Incomplete: false,
15+ // Details: {
16+ // DiagnosticRecord: {
17+ // Event: 'Passed',
18+ // Report: 'Test passed successfully'
19+ // }
20+ // }
21+ // }
22+ // };
23+
24+ // beforeEach(() => {
25+ // jest.spyOn(core.summary, 'addHeading').mockReturnThis();
26+ // jest.spyOn(core.summary, 'addRaw').mockReturnThis();
27+ // // jest.spyOn(core.summary, 'write').mockResolvedValue(true);
28+ // });
29+
30+ // afterEach(() => {
31+ // jest.clearAllMocks();
32+ // });
33+
34+ // test('writeSummary generates correct summary format', () => {
35+ // const testResults = [[{
36+ // name: 'TestFile',
37+ // path: '/test/path/TestFile',
38+ // testCases: [{
39+ // name: 'TestCase1',
40+ // duration: 1.234,
41+ // status: MatlabTestStatus.PASSED,
42+ // diagnostics: [{
43+ // event: 'Passed',
44+ // report: 'Test passed successfully'
45+ // }]
46+ // }],
47+ // duration: 1.234,
48+ // status: MatlabTestStatus.PASSED
49+ // }]];
50+
51+ // const counts = {
52+ // total: 1,
53+ // passed: 1,
54+ // failed: 0,
55+ // incomplete: 0,
56+ // notRun: 0
57+ // };
58+
59+ // writeSummary(testResults, counts);
60+
61+ // expect(core.summary.addHeading).toHaveBeenCalledWith('MATLAB Test Results');
62+ // expect(core.summary.addRaw).toHaveBeenCalledTimes(3);
63+ // expect(core.summary.write).toHaveBeenCalled();
64+ // });
65+
66+ // test('getTestResults processes test data correctly', () => {
67+ // process.env.RUNNER_TEMP = '/tmp';
68+ // process.env.GITHUB_RUN_ID = '12345';
69+
70+ // const resultsPath = path.join(process.env.RUNNER_TEMP, `matlabTestResults${process.env.GITHUB_RUN_ID}.json`);
71+ // writeFileSync(resultsPath, JSON.stringify([mockTestData]));
72+
73+ // const { testResults, counts } = getTestResults('');
74+
75+ // expect(counts.total).toBe(1);
76+ // expect(counts.passed).toBe(1);
77+ // expect(testResults).toHaveLength(1);
78+ // expect(testResults[0][0].testCases).toHaveLength(1);
79+ // expect(testResults[0][0].status).toBe(MatlabTestStatus.PASSED);
80+
81+ // if (existsSync(resultsPath)) {
82+ // unlinkSync(resultsPath);
83+ // }
84+ // });
85+
86+ // test('handles failed tests correctly', () => {
87+ // const failedTestData = {
88+ // ...mockTestData,
89+ // TestResult: {
90+ // ...mockTestData.TestResult,
91+ // Failed: true,
92+ // Passed: false,
93+ // Details: {
94+ // DiagnosticRecord: {
95+ // Event: 'Failed',
96+ // Report: 'Test failed with error'
97+ // }
98+ // }
99+ // }
100+ // };
101+
102+ // process.env.RUNNER_TEMP = '/tmp';
103+ // process.env.GITHUB_RUN_ID = '12345';
104+
105+ // const resultsPath = path.join(process.env.RUNNER_TEMP, `matlabTestResults${process.env.GITHUB_RUN_ID}.json`);
106+ // writeFileSync(resultsPath, JSON.stringify([failedTestData]));
107+
108+ // const { testResults, counts } = getTestResults('');
109+
110+ // expect(counts.failed).toBe(1);
111+ // expect(testResults[0][0].status).toBe(MatlabTestStatus.FAILED);
112+
113+ // if (existsSync(resultsPath)) {
114+ // unlinkSync(resultsPath);
115+ // }
116+ // });
117+ // });
0 commit comments