|
1 | 1 | import {expect, jest, test} from '@jest/globals' |
2 | | -import {Changes, ConfigurationOptions, Scorecard} from '../src/schemas' |
| 2 | +import {Change, Changes, ConfigurationOptions, Scorecard} from '../src/schemas' |
3 | 3 | import * as summary from '../src/summary' |
4 | 4 | import * as core from '@actions/core' |
5 | 5 | import {createTestChange} from './fixtures/create-test-change' |
@@ -109,6 +109,80 @@ test('prints headline as h1', () => { |
109 | 109 | expect(text).toContain('<h1>Dependency Review</h1>') |
110 | 110 | }) |
111 | 111 |
|
| 112 | +test('returns minimal summary in case the core.summary is too large for a PR comment', () => { |
| 113 | + let changes: Changes = [ |
| 114 | + createTestChange({name: 'lodash', version: '1.2.3'}), |
| 115 | + createTestChange({name: 'colors', version: '2.3.4'}), |
| 116 | + createTestChange({name: '@foo/bar', version: '*'}) |
| 117 | + ] |
| 118 | + |
| 119 | + let minSummary: string = summary.addSummaryToSummary( |
| 120 | + changes, |
| 121 | + emptyInvalidLicenseChanges, |
| 122 | + emptyChanges, |
| 123 | + scorecard, |
| 124 | + defaultConfig |
| 125 | + ) |
| 126 | + |
| 127 | + // side effect DR report into core.summary as happens in main.ts |
| 128 | + summary.addScannedDependencies(changes) |
| 129 | + const text = core.summary.stringify() |
| 130 | + |
| 131 | + expect(text).toContain('<h1>Dependency Review</h1>') |
| 132 | + expect(minSummary).toContain('# Dependency Review') |
| 133 | + |
| 134 | + expect(text).toContain('❌ 3 vulnerable package(s)') |
| 135 | + expect(text).not.toContain('* ❌ 3 vulnerable package(s)') |
| 136 | + expect(text).toContain('lodash') |
| 137 | + expect(text).toContain('colors') |
| 138 | + expect(text).toContain('@foo/bar') |
| 139 | + |
| 140 | + expect(minSummary).toContain('* ❌ 3 vulnerable package(s)') |
| 141 | + expect(minSummary).not.toContain('lodash') |
| 142 | + expect(minSummary).not.toContain('colors') |
| 143 | + expect(minSummary).not.toContain('@foo/bar') |
| 144 | + |
| 145 | + expect(text.length).toBeGreaterThan(minSummary.length) |
| 146 | +}) |
| 147 | + |
| 148 | +test('returns minimal summary formatted for posting as a PR comment', () => { |
| 149 | + const OLD_ENV = process.env |
| 150 | + |
| 151 | + let changes: Changes = [ |
| 152 | + createTestChange({name: 'lodash', version: '1.2.3'}), |
| 153 | + createTestChange({name: 'colors', version: '2.3.4'}), |
| 154 | + createTestChange({name: '@foo/bar', version: '*'}) |
| 155 | + ] |
| 156 | + |
| 157 | + process.env.GITHUB_SERVER_URL = 'https://github.com' |
| 158 | + process.env.GITHUB_REPOSITORY = 'owner/repo' |
| 159 | + process.env.GITHUB_RUN_ID = 'abc-123-xyz' |
| 160 | + |
| 161 | + let minSummary: string = summary.addSummaryToSummary( |
| 162 | + changes, |
| 163 | + emptyInvalidLicenseChanges, |
| 164 | + emptyChanges, |
| 165 | + scorecard, |
| 166 | + defaultConfig |
| 167 | + ) |
| 168 | + |
| 169 | + process.env = OLD_ENV |
| 170 | + |
| 171 | + // note: no Actions context values in unit test env |
| 172 | + const expected = ` |
| 173 | +# Dependency Review |
| 174 | +The following issues were found: |
| 175 | +* ❌ 3 vulnerable package(s) |
| 176 | +* ✅ 0 package(s) with incompatible licenses |
| 177 | +* ✅ 0 package(s) with invalid SPDX license definitions |
| 178 | +* ✅ 0 package(s) with unknown licenses. |
| 179 | +
|
| 180 | +[View full job summary](https://github.com/owner/repo/actions/runs/abc-123-xyz) |
| 181 | + `.trim() |
| 182 | + |
| 183 | + expect(minSummary).toEqual(expected) |
| 184 | +}) |
| 185 | + |
112 | 186 | test('only includes "No vulnerabilities or license issues found"-message if both are configured and nothing was found', () => { |
113 | 187 | summary.addSummaryToSummary( |
114 | 188 | emptyChanges, |
|
0 commit comments