From 1b9faef957e3f6a37b9ebcb48220b2addd17fb59 Mon Sep 17 00:00:00 2001 From: David Losert Date: Mon, 27 Feb 2023 16:05:03 +0000 Subject: [PATCH] Fixes ESLint to also incldue tests and fixes eslint errors in tests --- __tests__/config.test.ts | 7 ++++--- ...ency-graph.int.test.ts => dependency-graph.test.ts} | 0 __tests__/filter.test.ts | 10 +++++----- __tests__/licenses.test.ts | 7 +++++-- package.json | 2 +- tsconfig.build.json | 8 ++++++++ tsconfig.json | 3 +-- 7 files changed, 24 insertions(+), 13 deletions(-) rename __tests__/{dependency-graph.int.test.ts => dependency-graph.test.ts} (100%) create mode 100644 tsconfig.build.json diff --git a/__tests__/config.test.ts b/__tests__/config.test.ts index 18506c4..f41165d 100644 --- a/__tests__/config.test.ts +++ b/__tests__/config.test.ts @@ -5,13 +5,13 @@ import * as Utils from '../src/utils' // GitHub Action inputs come in the form of environment variables // 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 } // We want a clean ENV before each test. We use `delete` // since we want `undefined` values and not empty strings. -function clearInputs() { +function clearInputs(): void { const allowedOptions = [ 'FAIL-ON-SEVERITY', 'FAIL-ON-SCOPES', @@ -26,6 +26,7 @@ function clearInputs() { 'COMMENT-SUMMARY-IN-PR' ] + // eslint-disable-next-line github/array-foreach allowedOptions.forEach(option => { delete process.env[`INPUT_${option.toUpperCase()}`] }) @@ -238,7 +239,7 @@ test('it supports comma-separated lists', async () => { 'config-file', './__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']) }) diff --git a/__tests__/dependency-graph.int.test.ts b/__tests__/dependency-graph.test.ts similarity index 100% rename from __tests__/dependency-graph.int.test.ts rename to __tests__/dependency-graph.test.ts diff --git a/__tests__/filter.test.ts b/__tests__/filter.test.ts index 4596148..8caab40 100644 --- a/__tests__/filter.test.ts +++ b/__tests__/filter.test.ts @@ -1,12 +1,12 @@ import {expect, test} from '@jest/globals' -import {Change, Changes} from '../src/schemas' +import {Change} from '../src/schemas' import { filterChangesBySeverity, filterChangesByScopes, filterAllowedAdvisories } from '../src/filter' -let npmChange: Change = { +const npmChange: Change = { manifest: 'package.json', change_type: 'added', ecosystem: 'npm', @@ -26,7 +26,7 @@ let npmChange: Change = { ] } -let rubyChange: Change = { +const rubyChange: Change = { change_type: 'added', manifest: 'Gemfile.lock', ecosystem: 'rubygems', @@ -52,7 +52,7 @@ let rubyChange: Change = { ] } -let noVulnNpmChange: Change = { +const noVulnNpmChange: Change = { manifest: 'package.json', change_type: 'added', ecosystem: 'npm', @@ -92,7 +92,7 @@ test('it properly filters changes by scope', async () => { test('it properly handles undefined advisory IDs', async () => { const changes = [npmChange, rubyChange, noVulnNpmChange] - let result = filterAllowedAdvisories(undefined, changes) + const result = filterAllowedAdvisories(undefined, changes) expect(result).toEqual([npmChange, rubyChange, noVulnNpmChange]) }) diff --git a/__tests__/licenses.test.ts b/__tests__/licenses.test.ts index 9cc2cae..66c7cc1 100644 --- a/__tests__/licenses.test.ts +++ b/__tests__/licenses.test.ts @@ -3,7 +3,7 @@ import {Change, Changes} from '../src/schemas' let getInvalidLicenseChanges: Function -let npmChange: Change = { +const npmChange: Change = { manifest: 'package.json', change_type: 'added', ecosystem: 'npm', @@ -23,7 +23,7 @@ let npmChange: Change = { ] } -let rubyChange: Change = { +const rubyChange: Change = { change_type: 'added', manifest: 'Gemfile.lock', ecosystem: 'rubygems', @@ -63,6 +63,7 @@ const mockOctokit = { jest.mock('octokit', () => { return { + // eslint-disable-next-line @typescript-eslint/no-extraneous-class Octokit: class { constructor() { return mockOctokit @@ -78,6 +79,7 @@ beforeEach(async () => { // true for BSD, false for all others return jest.fn((license: string, _: string): boolean => license === 'BSD') }) + // eslint-disable-next-line @typescript-eslint/no-require-imports ;({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') }) }) + // eslint-disable-next-line @typescript-eslint/no-require-imports ;({getInvalidLicenseChanges} = require('../src/licenses')) const changes: Changes = [npmChange, rubyChange] const invalidLicenses = await getInvalidLicenseChanges(changes, { diff --git a/package.json b/package.json index 95f670c..8ab36be 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "description": "A GitHub Action for Dependency Review", "main": "lib/main.js", "scripts": { - "build": "tsc", + "build": "tsc -p tsconfig.build.json", "format": "prettier --write '**/*.ts'", "format-check": "prettier --check '**/*.ts'", "lint": "eslint src/**/*.ts", diff --git a/tsconfig.build.json b/tsconfig.build.json new file mode 100644 index 0000000..a54c6bb --- /dev/null +++ b/tsconfig.build.json @@ -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. */ + } +} diff --git a/tsconfig.json b/tsconfig.json index 4a6c661..a569bdc 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -3,10 +3,9 @@ "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'. */, "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. */, "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'. */ }, - "exclude": ["node_modules", "**/*.test.ts"] + "exclude": ["node_modules"] }