Skip to content

Commit

Permalink
WIP: summary test
Browse files Browse the repository at this point in the history
  • Loading branch information
elireisman committed Jun 4, 2024
1 parent f7aca4f commit 5460632
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 4 deletions.
34 changes: 33 additions & 1 deletion __tests__/summary.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {expect, jest, test} from '@jest/globals'
import {Changes, ConfigurationOptions, Scorecard} from '../src/schemas'
import {Change, Changes, ConfigurationOptions, Scorecard} from '../src/schemas'
import * as summary from '../src/summary'
import * as core from '@actions/core'
import {createTestChange} from './fixtures/create-test-change'
Expand Down Expand Up @@ -109,6 +109,38 @@ test('prints headline as h1', () => {
expect(text).toContain('<h1>Dependency Review</h1>')
})

test('returns minimal summary in case the core.summary is too large for a PR comment', () => {
let changes: Changes = [
createTestChange({name: 'lodash', version: '1.2.3'}),
createTestChange({name: 'colors', version: '2.3.4'}),
createTestChange({name: '@foo/bar', version: '*'}),
]

let minSummary: string = summary.addSummaryToSummary(
changes,
emptyInvalidLicenseChanges,
emptyChanges,
scorecard,
defaultConfig
)

// side effect DR report into core.summary as happens in main.ts
summary.addScannedDependencies(changes)
const text = core.summary.stringify()

expect(text).toContain('<h1>Dependency Review</h1>')
expect(minSummary).toContain('# Dependency Review')

expect(text).toContain('lodash')
expect(text).toContain('colors')
expect(text).toContain('@foo/bar')
expect(minSummary).not.toContain('lodash')
expect(minSummary).not.toContain('colors')
expect(minSummary).not.toContain('@foo/bar')

expect(text.length).toBeGreaterThan(minSummary.length)
})

test('only includes "No vulnerabilities or license issues found"-message if both are configured and nothing was found', () => {
summary.addSummaryToSummary(
emptyChanges,
Expand Down
6 changes: 3 additions & 3 deletions src/summary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ const icons = {
warning: '⚠️'
}

// generates the initial DR summmary and applies to the Action's core.summary
// returns a string array of all the formatted values in the event we need
// to replace them in the PR comment due to length restrictions
// generates the DR report summmary and caches it to the Action's core.summary.
// returns the DR summary string, ready to be posted as a PR comment if the
// final DR report is too large
export function addSummaryToSummary(
vulnerableChanges: Changes,
invalidLicenseChanges: InvalidLicenseChanges,
Expand Down

0 comments on commit 5460632

Please sign in to comment.