Skip to content

Commit e3c0f4d

Browse files
committed
Cleanup test output for generate-report
1 parent 81d09a1 commit e3c0f4d

File tree

3 files changed

+27
-25
lines changed

3 files changed

+27
-25
lines changed

src/commands/scan/generate-report.test.ts

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ describe('generate-report', () => {
6666
}
6767
`)
6868
expect(result.healthy).toBe(true)
69-
expect(result.alerts.size).toBe(0)
69+
expect(result['alerts']?.size).toBe(0)
7070
})
7171

7272
it('should return a sick report with alert when an alert violates at error', () => {
@@ -130,7 +130,7 @@ describe('generate-report', () => {
130130
}
131131
`)
132132
expect(result.healthy).toBe(false)
133-
expect(result.alerts.size).toBe(1)
133+
expect(result['alerts']?.size).toBe(1)
134134
})
135135

136136
it('should return a healthy report with alert when an alert violates at warn', () => {
@@ -194,7 +194,7 @@ describe('generate-report', () => {
194194
}
195195
`)
196196
expect(result.healthy).toBe(true)
197-
expect(result.alerts.size).toBe(1)
197+
expect(result['alerts']?.size).toBe(1)
198198
})
199199

200200
it('should return a healthy report without alerts when an alert violates at monitor', () => {
@@ -233,7 +233,7 @@ describe('generate-report', () => {
233233
}
234234
`)
235235
expect(result.healthy).toBe(true)
236-
expect(result.alerts.size).toBe(0)
236+
expect(result['alerts']?.size).toBe(0)
237237
})
238238

239239
it('should return a healthy report without alerts when an alert violates at ignore', () => {
@@ -272,7 +272,7 @@ describe('generate-report', () => {
272272
}
273273
`)
274274
expect(result.healthy).toBe(true)
275-
expect(result.alerts.size).toBe(0)
275+
expect(result['alerts']?.size).toBe(0)
276276
})
277277

278278
it('should return a healthy report without alerts when an alert violates at defer', () => {
@@ -311,7 +311,7 @@ describe('generate-report', () => {
311311
}
312312
`)
313313
expect(result.healthy).toBe(true)
314-
expect(result.alerts.size).toBe(0)
314+
expect(result['alerts']?.size).toBe(0)
315315
})
316316

317317
it('should return a healthy report without alerts when an alert has no policy value', () => {
@@ -348,7 +348,7 @@ describe('generate-report', () => {
348348
}
349349
`)
350350
expect(result.healthy).toBe(true)
351-
expect(result.alerts.size).toBe(0)
351+
expect(result['alerts']?.size).toBe(0)
352352
})
353353

354354
it('should return a healthy report without alerts when an alert has no policy entry', () => {
@@ -383,7 +383,7 @@ describe('generate-report', () => {
383383
}
384384
`)
385385
expect(result.healthy).toBe(true)
386-
expect(result.alerts.size).toBe(0)
386+
expect(result['alerts']?.size).toBe(0)
387387
})
388388
})
389389

@@ -424,7 +424,7 @@ describe('generate-report', () => {
424424
}
425425
`)
426426
expect(result.healthy).toBe(true)
427-
expect(result.alerts.size).toBe(0)
427+
expect(result['alerts']?.size).toBe(0)
428428
})
429429

430430
it('should return a sick report with alert when an alert violates at error', () => {
@@ -488,7 +488,7 @@ describe('generate-report', () => {
488488
}
489489
`)
490490
expect(result.healthy).toBe(false)
491-
expect(result.alerts.size).toBe(1)
491+
expect(result['alerts']?.size).toBe(1)
492492
})
493493

494494
it('should return a healthy report with alert when an alert violates at warn', () => {
@@ -552,7 +552,7 @@ describe('generate-report', () => {
552552
}
553553
`)
554554
expect(result.healthy).toBe(true)
555-
expect(result.alerts.size).toBe(1)
555+
expect(result['alerts']?.size).toBe(1)
556556
})
557557

558558
it('should return a healthy report with alert when an alert violates at monitor', () => {
@@ -616,7 +616,7 @@ describe('generate-report', () => {
616616
}
617617
`)
618618
expect(result.healthy).toBe(true)
619-
expect(result.alerts.size).toBe(1)
619+
expect(result['alerts']?.size).toBe(1)
620620
})
621621

622622
it('should return a healthy report with alert when an alert violates at ignore', () => {
@@ -680,7 +680,7 @@ describe('generate-report', () => {
680680
}
681681
`)
682682
expect(result.healthy).toBe(true)
683-
expect(result.alerts.size).toBe(1)
683+
expect(result['alerts']?.size).toBe(1)
684684
})
685685

686686
it('should return a healthy report without alerts when an alert violates at defer', () => {
@@ -719,7 +719,7 @@ describe('generate-report', () => {
719719
}
720720
`)
721721
expect(result.healthy).toBe(true)
722-
expect(result.alerts.size).toBe(0)
722+
expect(result['alerts']?.size).toBe(0)
723723
})
724724

725725
it('should return a healthy report without alerts when an alert has no policy value', () => {
@@ -756,7 +756,7 @@ describe('generate-report', () => {
756756
}
757757
`)
758758
expect(result.healthy).toBe(true)
759-
expect(result.alerts.size).toBe(0)
759+
expect(result['alerts']?.size).toBe(0)
760760
})
761761

762762
it('should return a healthy report without alerts when an alert has no policy entry', () => {
@@ -791,7 +791,7 @@ describe('generate-report', () => {
791791
}
792792
`)
793793
expect(result.healthy).toBe(true)
794-
expect(result.alerts.size).toBe(0)
794+
expect(result['alerts']?.size).toBe(0)
795795
})
796796
})
797797
})

src/commands/scan/generate-report.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import constants from '../../constants'
2-
1+
import type { Spinner } from '@socketsecurity/registry/lib/spinner'
32
import type { SocketSdkReturnType } from '@socketsecurity/sdk'
43
import type { components } from '@socketsecurity/sdk/types/api'
54

@@ -39,20 +38,20 @@ export function generateReport(
3938
orgSlug,
4039
reportLevel,
4140
scanId,
42-
short
41+
short,
42+
spinner
4343
}: {
4444
fold: 'pkg' | 'version' | 'file' | 'none'
4545
orgSlug: string
4646
reportLevel: 'defer' | 'ignore' | 'monitor' | 'warn' | 'error'
4747
scanId: string
48-
short: boolean
48+
short?: boolean | undefined
49+
spinner?: Spinner | undefined
4950
}
5051
): ScanReport | ShortScanReport {
5152
const now = Date.now()
5253

53-
// Lazily access constants.spinner.
54-
const { spinner } = constants
55-
spinner.start('Generating report...')
54+
spinner?.start('Generating report...')
5655

5756
// Create an object that includes:
5857
// healthy: boolean
@@ -192,7 +191,7 @@ export function generateReport(
192191
})
193192
}
194193

195-
spinner.successAndStop(`Generated reported in ${Date.now() - now} ms`)
194+
spinner?.successAndStop(`Generated reported in ${Date.now() - now} ms`)
196195

197196
const report = short
198197
? { healthy }

src/commands/scan/output-scan-report.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import fs from 'node:fs/promises'
33
import { logger } from '@socketsecurity/registry/lib/logger'
44

55
import { generateReport } from './generate-report'
6+
import constants from '../../constants'
67
import { mapToObject } from '../../utils/map-to-object'
78
import { mdTable } from '../../utils/markdown'
89
import { walkNestedMap } from '../../utils/walk-nested-map'
@@ -51,7 +52,9 @@ export async function outputScanReport(
5152
scanId,
5253
fold,
5354
reportLevel,
54-
short
55+
short,
56+
// Lazily access constants.spinner.
57+
spinner: constants.spinner
5558
}
5659
)
5760

0 commit comments

Comments
 (0)