|
| 1 | +import { describe, it, expect } from 'vitest'; |
| 2 | +import { |
| 3 | + parseSwiftTestingResultLine, |
| 4 | + parseSwiftTestingIssueLine, |
| 5 | + parseSwiftTestingRunSummary, |
| 6 | + parseSwiftTestingContinuationLine, |
| 7 | + parseXcodebuildSwiftTestingLine, |
| 8 | +} from '../swift-testing-line-parsers.ts'; |
| 9 | + |
| 10 | +describe('Swift Testing line parsers', () => { |
| 11 | + describe('parseSwiftTestingResultLine', () => { |
| 12 | + it('should parse a passed test', () => { |
| 13 | + const result = parseSwiftTestingResultLine( |
| 14 | + '✔ Test "Basic math operations" passed after 0.001 seconds.', |
| 15 | + ); |
| 16 | + expect(result).toEqual({ |
| 17 | + status: 'passed', |
| 18 | + rawName: 'Basic math operations', |
| 19 | + testName: 'Basic math operations', |
| 20 | + durationText: '0.001s', |
| 21 | + }); |
| 22 | + }); |
| 23 | + |
| 24 | + it('should parse a failed test', () => { |
| 25 | + const result = parseSwiftTestingResultLine( |
| 26 | + '✘ Test "Expected failure" failed after 0.001 seconds with 1 issue.', |
| 27 | + ); |
| 28 | + expect(result).toEqual({ |
| 29 | + status: 'failed', |
| 30 | + rawName: 'Expected failure', |
| 31 | + testName: 'Expected failure', |
| 32 | + durationText: '0.001s', |
| 33 | + }); |
| 34 | + }); |
| 35 | + |
| 36 | + it('should parse a skipped test', () => { |
| 37 | + const result = parseSwiftTestingResultLine('◇ Test "Disabled test" skipped.'); |
| 38 | + expect(result).toEqual({ |
| 39 | + status: 'skipped', |
| 40 | + rawName: 'Disabled test', |
| 41 | + testName: 'Disabled test', |
| 42 | + }); |
| 43 | + }); |
| 44 | + |
| 45 | + it('should return null for non-matching lines', () => { |
| 46 | + expect(parseSwiftTestingResultLine('◇ Test "Foo" started.')).toBeNull(); |
| 47 | + expect(parseSwiftTestingResultLine('random text')).toBeNull(); |
| 48 | + }); |
| 49 | + }); |
| 50 | + |
| 51 | + describe('parseSwiftTestingIssueLine', () => { |
| 52 | + it('should parse an issue with location', () => { |
| 53 | + const result = parseSwiftTestingIssueLine( |
| 54 | + '✘ Test "Expected failure" recorded an issue at SimpleTests.swift:48:5: Expectation failed: true == false', |
| 55 | + ); |
| 56 | + expect(result).toEqual({ |
| 57 | + rawTestName: 'Expected failure', |
| 58 | + testName: 'Expected failure', |
| 59 | + location: 'SimpleTests.swift:48', |
| 60 | + message: 'Expectation failed: true == false', |
| 61 | + }); |
| 62 | + }); |
| 63 | + |
| 64 | + it('should parse an issue without location', () => { |
| 65 | + const result = parseSwiftTestingIssueLine( |
| 66 | + '✘ Test "Some test" recorded an issue: Something went wrong', |
| 67 | + ); |
| 68 | + expect(result).toEqual({ |
| 69 | + rawTestName: 'Some test', |
| 70 | + testName: 'Some test', |
| 71 | + message: 'Something went wrong', |
| 72 | + }); |
| 73 | + }); |
| 74 | + |
| 75 | + it('should return null for non-matching lines', () => { |
| 76 | + expect(parseSwiftTestingIssueLine('✘ Test "Foo" failed after 0.001 seconds')).toBeNull(); |
| 77 | + }); |
| 78 | + }); |
| 79 | + |
| 80 | + describe('parseSwiftTestingRunSummary', () => { |
| 81 | + it('should parse a failed run summary', () => { |
| 82 | + const result = parseSwiftTestingRunSummary( |
| 83 | + '✘ Test run with 6 tests in 0 suites failed after 0.001 seconds with 1 issue.', |
| 84 | + ); |
| 85 | + expect(result).toEqual({ |
| 86 | + executed: 6, |
| 87 | + failed: 1, |
| 88 | + durationText: '0.001s', |
| 89 | + }); |
| 90 | + }); |
| 91 | + |
| 92 | + it('should parse a passed run summary', () => { |
| 93 | + const result = parseSwiftTestingRunSummary( |
| 94 | + '✔ Test run with 5 tests in 2 suites passed after 0.003 seconds.', |
| 95 | + ); |
| 96 | + expect(result).toEqual({ |
| 97 | + executed: 5, |
| 98 | + failed: 0, |
| 99 | + durationText: '0.003s', |
| 100 | + }); |
| 101 | + }); |
| 102 | + |
| 103 | + it('should return null for non-matching lines', () => { |
| 104 | + expect(parseSwiftTestingRunSummary('random text')).toBeNull(); |
| 105 | + }); |
| 106 | + }); |
| 107 | + |
| 108 | + describe('parseSwiftTestingContinuationLine', () => { |
| 109 | + it('should parse a continuation line', () => { |
| 110 | + expect(parseSwiftTestingContinuationLine('↳ This test should fail')).toBe( |
| 111 | + 'This test should fail', |
| 112 | + ); |
| 113 | + }); |
| 114 | + |
| 115 | + it('should return null for non-continuation lines', () => { |
| 116 | + expect(parseSwiftTestingContinuationLine('regular line')).toBeNull(); |
| 117 | + }); |
| 118 | + }); |
| 119 | + |
| 120 | + describe('parseXcodebuildSwiftTestingLine', () => { |
| 121 | + it('should parse a passed test case', () => { |
| 122 | + const result = parseXcodebuildSwiftTestingLine( |
| 123 | + "Test case 'MCPTestTests/appNameIsCorrect()' passed on 'My Mac - MCPTest (78757)' (0.000 seconds)", |
| 124 | + ); |
| 125 | + expect(result).toEqual({ |
| 126 | + status: 'passed', |
| 127 | + rawName: 'MCPTestTests/appNameIsCorrect()', |
| 128 | + suiteName: 'MCPTestTests', |
| 129 | + testName: 'appNameIsCorrect()', |
| 130 | + durationText: '0.000s', |
| 131 | + }); |
| 132 | + }); |
| 133 | + |
| 134 | + it('should parse a failed test case', () => { |
| 135 | + const result = parseXcodebuildSwiftTestingLine( |
| 136 | + "Test case 'MCPTestTests/deliberateFailure()' failed on 'My Mac - MCPTest (78757)' (0.000 seconds)", |
| 137 | + ); |
| 138 | + expect(result).toEqual({ |
| 139 | + status: 'failed', |
| 140 | + rawName: 'MCPTestTests/deliberateFailure()', |
| 141 | + suiteName: 'MCPTestTests', |
| 142 | + testName: 'deliberateFailure()', |
| 143 | + durationText: '0.000s', |
| 144 | + }); |
| 145 | + }); |
| 146 | + |
| 147 | + it('should return null for XCTest format lines', () => { |
| 148 | + expect( |
| 149 | + parseXcodebuildSwiftTestingLine("Test Case '-[Suite test]' passed (0.001 seconds)."), |
| 150 | + ).toBeNull(); |
| 151 | + }); |
| 152 | + |
| 153 | + it('should return null for non-matching lines', () => { |
| 154 | + expect(parseXcodebuildSwiftTestingLine('random text')).toBeNull(); |
| 155 | + }); |
| 156 | + }); |
| 157 | +}); |
0 commit comments