-
Notifications
You must be signed in to change notification settings - Fork 14
Refactor component detection tests and update jest configuration for ESM compatibility (required to refactor to dynamically load dependency) #110
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…ESM compatibility (required to refactor to dynamically load dependency)
Tested here... looks ok in the real world: https://github.com/vulna-felickz/my-spring-log4j-vuln-sample/actions/runs/14938235047/job/41970518830 |
} | ||
}); | ||
}); | ||
return manifests; | ||
} | ||
|
||
private static getDependencyScope(pkg: ComponentDetectionPackage) { | ||
private static getDependencyScope(pkg: any) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Switching to any
type isn't a great idea. Please can you update to a specific type
@@ -65,11 +64,34 @@ export default class ComponentDetection { | |||
return parameters; | |||
} | |||
|
|||
public static async getManifestsFromResults(): Promise<Manifest[] | undefined> { | |||
public static async getManifestsFromResults(): Promise<any[] | undefined> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Switching to any
@@ -23,7 +14,7 @@ export default class ComponentDetection { | |||
public static outputPath = './output.json'; | |||
|
|||
// This is the default entry point for this class. | |||
static async scanAndGetManifests(path: string): Promise<Manifest[] | undefined> { | |||
static async scanAndGetManifests(path: string): Promise<any[] | undefined> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should return a manifest
import { | ||
PackageCache, | ||
BuildTarget, | ||
Package, | ||
Snapshot, | ||
Manifest, | ||
submitSnapshot | ||
} from '@github/dependency-submission-toolkit' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a reason to remove these imports?
await ComponentDetection.downloadLatestRelease(); | ||
await ComponentDetection.runComponentDetection("./test"); | ||
// Mock the CLI output file | ||
const mockOutput = JSON.stringify({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe this could be stored and ready from a file versus inline?
Too many nasty changes here, making a different PR for full compat |
PR Summary: Node 20 & ESM/Jest Compatibility Upgrade
Fixes #104 that was due to Node 20 upgrade
Overview
This PR upgrades the project to support Node.js 20 and resolves compatibility issues with ESM-only dependencies (
octokit
,@github/dependency-submission-toolkit
) and Jest. The changes are more extensive than a typical Node upgrade due to the ecosystem’s shift toward ESM and the limitations of Jest/ts-jest with ESM modules.Key Changes
Dynamic ESM Imports:
octokit
,@github/dependency-submission-toolkit
) with dynamicawait import()
calls.require
or staticimport
in a CommonJS context.Jest Configuration Updates:
jest.config.js
to remove ESM-specific options and mappings that caused conflicts.Test Refactoring:
Parses CLI output
test to decouple unit tests from the actual CLI binary and ESM runtime issues.Additional Logging:
TypeScript Adjustments:
any
or dynamic class definitions where necessary to satisfy both TypeScript and runtime requirements.Why These Changes Were Necessary
Node 20 & ESM:
Node 20 enforces stricter ESM/CJS boundaries. Many modern libraries (like
octokit
) are now ESM-only, which breaks static imports in CommonJS or mixed environments.Jest/ts-jest Limitations:
Jest (and ts-jest) do not fully support ESM, especially with dynamic imports and TypeScript. This required workarounds such as dynamic imports and test mocking.
Test Reliability:
By mocking CLI output, we ensure that unit tests remain reliable and fast, and are not dependent on external binaries or network calls.
Impact