Fixing failing tests

This commit is contained in:
Federico Builes
2022-06-06 17:31:33 +02:00
parent bccacf9708
commit 06297bf229
4 changed files with 32 additions and 8 deletions

13
.vscode/launch.json vendored Normal file
View File

@@ -0,0 +1,13 @@
{
"version": "0.1.0",
"configurations": [
{
"name": "Debug Jest Tests",
"type": "node",
"request": "launch",
"runtimeArgs": ["--inspect-brk", "${workspaceRoot}/node_modules/.bin/jest", "--runInBand", "--coverage", "false"],
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen"
}
]
}

View File

@@ -49,5 +49,5 @@ let rubyChange: Change = {
test('hasInvalidLicenses fails if an unallowed license is found', async () => {
const changes: Changes = [npmChange, rubyChange]
const result = hasInvalidLicenses(changes, ['BSD'], [])
expect(result.length).toBe(1)
expect(result[0]).toBe(npmChange)
})

View File

@@ -1,3 +1,4 @@
import * as core from '@actions/core'
import {Change, ChangeSchema} from './schemas'
export function hasInvalidLicenses(
@@ -21,14 +22,10 @@ export function hasInvalidLicenses(
continue
}
if (allowLicenses.includes(license)) {
if (!allowLicenses.includes(license)) {
disallowed.push(change)
}
}
return disallowed
}
export function printLicensesError(changes: Array<Change>): void {
return
}

View File

@@ -6,7 +6,7 @@ import {RequestError} from '@octokit/request-error'
import {Change, PullRequestSchema, Severity} from './schemas'
import {readConfigFile} from '../src/config'
import {filterChangesBySeverity} from '../src/filter'
import {hasInvalidLicenses, printLicensesError} from './licenses'
import {hasInvalidLicenses} from './licenses'
async function run(): Promise<void> {
try {
@@ -43,7 +43,7 @@ async function run(): Promise<void> {
)
if (licenseErrors.length > 0) {
printLicensesError(licenseErrors)
printLicensesError(licenseErrors, config.allow_licenses!)
throw new Error('Dependency review detected incompatible licenses.')
}
@@ -111,4 +111,18 @@ function renderSeverity(
return `${styles.color[color].open}(${severity} severity)${styles.color[color].close}`
}
function printLicensesError(
changes: Array<Change>,
allowLicenses: Array<string>
): void {
core.info('Dependency review detected incompatible licenses.')
core.info('\nAllowed licenses: ' + allowLicenses.join(', ') + '\n')
core.info('The following dependencies have incompatible licenses:')
for (const change of changes) {
core.info(
`${styles.bold.open}${change.manifest} » ${change.name}@${change.version}${styles.bold.close} ${change.license}`
)
}
}
run()