Fixes ESLint to also incldue tests and fixes eslint errors in tests
This commit is contained in:
@@ -5,13 +5,13 @@ import * as Utils from '../src/utils'
|
|||||||
|
|
||||||
// GitHub Action inputs come in the form of environment variables
|
// GitHub Action inputs come in the form of environment variables
|
||||||
// with an INPUT prefix (e.g. INPUT_FAIL-ON-SEVERITY)
|
// with an INPUT prefix (e.g. INPUT_FAIL-ON-SEVERITY)
|
||||||
function setInput(input: string, value: string) {
|
function setInput(input: string, value: string): void {
|
||||||
process.env[`INPUT_${input.toUpperCase()}`] = value
|
process.env[`INPUT_${input.toUpperCase()}`] = value
|
||||||
}
|
}
|
||||||
|
|
||||||
// We want a clean ENV before each test. We use `delete`
|
// We want a clean ENV before each test. We use `delete`
|
||||||
// since we want `undefined` values and not empty strings.
|
// since we want `undefined` values and not empty strings.
|
||||||
function clearInputs() {
|
function clearInputs(): void {
|
||||||
const allowedOptions = [
|
const allowedOptions = [
|
||||||
'FAIL-ON-SEVERITY',
|
'FAIL-ON-SEVERITY',
|
||||||
'FAIL-ON-SCOPES',
|
'FAIL-ON-SCOPES',
|
||||||
@@ -26,6 +26,7 @@ function clearInputs() {
|
|||||||
'COMMENT-SUMMARY-IN-PR'
|
'COMMENT-SUMMARY-IN-PR'
|
||||||
]
|
]
|
||||||
|
|
||||||
|
// eslint-disable-next-line github/array-foreach
|
||||||
allowedOptions.forEach(option => {
|
allowedOptions.forEach(option => {
|
||||||
delete process.env[`INPUT_${option.toUpperCase()}`]
|
delete process.env[`INPUT_${option.toUpperCase()}`]
|
||||||
})
|
})
|
||||||
@@ -238,7 +239,7 @@ test('it supports comma-separated lists', async () => {
|
|||||||
'config-file',
|
'config-file',
|
||||||
'./__tests__/fixtures/inline-license-config-sample.yml'
|
'./__tests__/fixtures/inline-license-config-sample.yml'
|
||||||
)
|
)
|
||||||
let config = await readConfig()
|
const config = await readConfig()
|
||||||
|
|
||||||
expect(config.allow_licenses).toEqual(['MIT', 'GPL-2.0-only'])
|
expect(config.allow_licenses).toEqual(['MIT', 'GPL-2.0-only'])
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
import {expect, test} from '@jest/globals'
|
import {expect, test} from '@jest/globals'
|
||||||
import {Change, Changes} from '../src/schemas'
|
import {Change} from '../src/schemas'
|
||||||
import {
|
import {
|
||||||
filterChangesBySeverity,
|
filterChangesBySeverity,
|
||||||
filterChangesByScopes,
|
filterChangesByScopes,
|
||||||
filterAllowedAdvisories
|
filterAllowedAdvisories
|
||||||
} from '../src/filter'
|
} from '../src/filter'
|
||||||
|
|
||||||
let npmChange: Change = {
|
const npmChange: Change = {
|
||||||
manifest: 'package.json',
|
manifest: 'package.json',
|
||||||
change_type: 'added',
|
change_type: 'added',
|
||||||
ecosystem: 'npm',
|
ecosystem: 'npm',
|
||||||
@@ -26,7 +26,7 @@ let npmChange: Change = {
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
let rubyChange: Change = {
|
const rubyChange: Change = {
|
||||||
change_type: 'added',
|
change_type: 'added',
|
||||||
manifest: 'Gemfile.lock',
|
manifest: 'Gemfile.lock',
|
||||||
ecosystem: 'rubygems',
|
ecosystem: 'rubygems',
|
||||||
@@ -52,7 +52,7 @@ let rubyChange: Change = {
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
let noVulnNpmChange: Change = {
|
const noVulnNpmChange: Change = {
|
||||||
manifest: 'package.json',
|
manifest: 'package.json',
|
||||||
change_type: 'added',
|
change_type: 'added',
|
||||||
ecosystem: 'npm',
|
ecosystem: 'npm',
|
||||||
@@ -92,7 +92,7 @@ test('it properly filters changes by scope', async () => {
|
|||||||
|
|
||||||
test('it properly handles undefined advisory IDs', async () => {
|
test('it properly handles undefined advisory IDs', async () => {
|
||||||
const changes = [npmChange, rubyChange, noVulnNpmChange]
|
const changes = [npmChange, rubyChange, noVulnNpmChange]
|
||||||
let result = filterAllowedAdvisories(undefined, changes)
|
const result = filterAllowedAdvisories(undefined, changes)
|
||||||
expect(result).toEqual([npmChange, rubyChange, noVulnNpmChange])
|
expect(result).toEqual([npmChange, rubyChange, noVulnNpmChange])
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import {Change, Changes} from '../src/schemas'
|
|||||||
|
|
||||||
let getInvalidLicenseChanges: Function
|
let getInvalidLicenseChanges: Function
|
||||||
|
|
||||||
let npmChange: Change = {
|
const npmChange: Change = {
|
||||||
manifest: 'package.json',
|
manifest: 'package.json',
|
||||||
change_type: 'added',
|
change_type: 'added',
|
||||||
ecosystem: 'npm',
|
ecosystem: 'npm',
|
||||||
@@ -23,7 +23,7 @@ let npmChange: Change = {
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
let rubyChange: Change = {
|
const rubyChange: Change = {
|
||||||
change_type: 'added',
|
change_type: 'added',
|
||||||
manifest: 'Gemfile.lock',
|
manifest: 'Gemfile.lock',
|
||||||
ecosystem: 'rubygems',
|
ecosystem: 'rubygems',
|
||||||
@@ -63,6 +63,7 @@ const mockOctokit = {
|
|||||||
|
|
||||||
jest.mock('octokit', () => {
|
jest.mock('octokit', () => {
|
||||||
return {
|
return {
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-extraneous-class
|
||||||
Octokit: class {
|
Octokit: class {
|
||||||
constructor() {
|
constructor() {
|
||||||
return mockOctokit
|
return mockOctokit
|
||||||
@@ -78,6 +79,7 @@ beforeEach(async () => {
|
|||||||
// true for BSD, false for all others
|
// true for BSD, false for all others
|
||||||
return jest.fn((license: string, _: string): boolean => license === 'BSD')
|
return jest.fn((license: string, _: string): boolean => license === 'BSD')
|
||||||
})
|
})
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
||||||
;({getInvalidLicenseChanges} = require('../src/licenses'))
|
;({getInvalidLicenseChanges} = require('../src/licenses'))
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -140,6 +142,7 @@ test('it adds all licenses to unresolved if it is unable to determine the validi
|
|||||||
throw new Error('Some Error')
|
throw new Error('Some Error')
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
||||||
;({getInvalidLicenseChanges} = require('../src/licenses'))
|
;({getInvalidLicenseChanges} = require('../src/licenses'))
|
||||||
const changes: Changes = [npmChange, rubyChange]
|
const changes: Changes = [npmChange, rubyChange]
|
||||||
const invalidLicenses = await getInvalidLicenseChanges(changes, {
|
const invalidLicenses = await getInvalidLicenseChanges(changes, {
|
||||||
|
|||||||
+1
-1
@@ -5,7 +5,7 @@
|
|||||||
"description": "A GitHub Action for Dependency Review",
|
"description": "A GitHub Action for Dependency Review",
|
||||||
"main": "lib/main.js",
|
"main": "lib/main.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "tsc",
|
"build": "tsc -p tsconfig.build.json",
|
||||||
"format": "prettier --write '**/*.ts'",
|
"format": "prettier --write '**/*.ts'",
|
||||||
"format-check": "prettier --check '**/*.ts'",
|
"format-check": "prettier --check '**/*.ts'",
|
||||||
"lint": "eslint src/**/*.ts",
|
"lint": "eslint src/**/*.ts",
|
||||||
|
|||||||
@@ -0,0 +1,8 @@
|
|||||||
|
{
|
||||||
|
"extends": "./tsconfig.json",
|
||||||
|
"exclude": ["node_modules", "__tests__"],
|
||||||
|
"compilerOptions": {
|
||||||
|
"outDir": "./lib" /* Redirect output structure to the directory. */,
|
||||||
|
"rootDir": "./src" /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
|
||||||
|
}
|
||||||
|
}
|
||||||
+1
-2
@@ -3,10 +3,9 @@
|
|||||||
"target": "es6" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */,
|
"target": "es6" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */,
|
||||||
"module": "commonjs" /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */,
|
"module": "commonjs" /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */,
|
||||||
"outDir": "./lib" /* Redirect output structure to the directory. */,
|
"outDir": "./lib" /* Redirect output structure to the directory. */,
|
||||||
"rootDir": "./src" /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */,
|
|
||||||
"strict": true /* Enable all strict type-checking options. */,
|
"strict": true /* Enable all strict type-checking options. */,
|
||||||
"noImplicitAny": true /* Raise error on expressions and declarations with an implied 'any' type. */,
|
"noImplicitAny": true /* Raise error on expressions and declarations with an implied 'any' type. */,
|
||||||
"esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
|
"esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
|
||||||
},
|
},
|
||||||
"exclude": ["node_modules", "**/*.test.ts"]
|
"exclude": ["node_modules"]
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user