|
1 | 1 | import { vol } from 'memfs';
|
2 | 2 | import { afterEach, describe, expect, it, vi } from 'vitest';
|
3 |
| -import { CategoryRef, IssueSeverity, PluginReport } from '@code-pushup/models'; |
| 3 | +import { |
| 4 | + CategoryRef, |
| 5 | + Issue, |
| 6 | + IssueSeverity, |
| 7 | + PluginReport, |
| 8 | +} from '@code-pushup/models'; |
4 | 9 | import { MEMFS_VOLUME, report } from '@code-pushup/models/testing';
|
5 | 10 | import {
|
6 | 11 | calcDuration,
|
7 | 12 | compareIssueSeverity,
|
8 | 13 | countWeightedRefs,
|
9 | 14 | getPluginNameFromSlug,
|
10 | 15 | loadReport,
|
| 16 | + sortAuditIssues, |
11 | 17 | sortAudits,
|
12 | 18 | sortCategoryAudits,
|
13 | 19 | } from './report';
|
@@ -223,3 +229,37 @@ describe('getPluginNameFromSlug', () => {
|
223 | 229 | expect(getPluginNameFromSlug('plugin-b', plugins)).toBe('Plugin B');
|
224 | 230 | });
|
225 | 231 | });
|
| 232 | + |
| 233 | +describe('sortAuditIssues', () => { |
| 234 | + it('should sort issues by severity and source file', () => { |
| 235 | + const mockIssues = [ |
| 236 | + { severity: 'warning', source: { file: 'b' } }, |
| 237 | + { severity: 'error', source: { file: 'c' } }, |
| 238 | + { severity: 'error', source: { file: 'a' } }, |
| 239 | + { severity: 'info', source: { file: 'b' } }, |
| 240 | + ] as Issue[]; |
| 241 | + const sortedIssues = [...mockIssues].sort(sortAuditIssues); |
| 242 | + expect(sortedIssues).toEqual([ |
| 243 | + { severity: 'error', source: { file: 'a' } }, |
| 244 | + { severity: 'error', source: { file: 'c' } }, |
| 245 | + { severity: 'warning', source: { file: 'b' } }, |
| 246 | + { severity: 'info', source: { file: 'b' } }, |
| 247 | + ]); |
| 248 | + }); |
| 249 | + |
| 250 | + it('should sort issues by source file and source start line', () => { |
| 251 | + const mockIssues = [ |
| 252 | + { severity: 'info', source: { file: 'b', position: { startLine: 2 } } }, |
| 253 | + { severity: 'info', source: { file: 'c', position: { startLine: 1 } } }, |
| 254 | + { severity: 'info', source: { file: 'a', position: { startLine: 2 } } }, |
| 255 | + { severity: 'info', source: { file: 'b', position: { startLine: 1 } } }, |
| 256 | + ] as Issue[]; |
| 257 | + const sortedIssues = [...mockIssues].sort(sortAuditIssues); |
| 258 | + expect(sortedIssues).toEqual([ |
| 259 | + { severity: 'info', source: { file: 'a', position: { startLine: 2 } } }, |
| 260 | + { severity: 'info', source: { file: 'b', position: { startLine: 1 } } }, |
| 261 | + { severity: 'info', source: { file: 'b', position: { startLine: 2 } } }, |
| 262 | + { severity: 'info', source: { file: 'c', position: { startLine: 1 } } }, |
| 263 | + ]); |
| 264 | + }); |
| 265 | +}); |
0 commit comments