@@ -2,11 +2,13 @@ import ComponentDetection, { DependencyGraphs } from "./componentDetection";
22import fs from "fs" ;
33
44test ( "Downloads CLI" , async ( ) => {
5+ console . log ( "Downloads CLI" )
56 await ComponentDetection . downloadLatestRelease ( ) ;
67 expect ( fs . existsSync ( ComponentDetection . componentDetectionPath ) ) ;
78} ) ;
89
910test ( "Runs CLI" , async ( ) => {
11+ console . log ( "Runs CLI" )
1012 await ComponentDetection . downloadLatestRelease ( ) ;
1113 await ComponentDetection . runComponentDetection ( "./test" ) ;
1214 expect ( fs . existsSync ( ComponentDetection . outputPath ) ) ;
@@ -21,6 +23,7 @@ test("Parses CLI output", async () => {
2123
2224describe ( "ComponentDetection.makePackageUrl" , ( ) => {
2325 test ( "returns a valid package url from saturated object" , ( ) => {
26+ console . log ( "ComponentDetection.makePackageUrl" )
2427 const packageUrl = ComponentDetection . makePackageUrl ( {
2528 Scheme : "pkg" ,
2629 Type : "npm" ,
@@ -38,6 +41,7 @@ describe("ComponentDetection.makePackageUrl", () => {
3841 } ) ;
3942
4043 test ( "returns valid package url without dangling ? with empty qualifers" , ( ) => {
44+ console . log ( "returns valid package url without dangling ? with empty qualifers" )
4145 const packageUrl = ComponentDetection . makePackageUrl ( {
4246 Scheme : "pkg" ,
4347 Type : "npm" ,
@@ -214,16 +218,63 @@ describe('normalizeDependencyGraphPaths with real output.json', () => {
214218 }
215219 } ) ;
216220
217- test ( 'creates manifests without leading slashes using real output.json' , ( ) => {
218- const output = JSON . parse ( fs . readFileSync ( './output.json' , 'utf8' ) ) ;
219- const dependencyGraphs = output . dependencyGraphs ;
220- const normalized = ComponentDetection . normalizeDependencyGraphPaths ( dependencyGraphs , 'test' ) ;
221+ test ( 'full action scan creates manifests with correct names and file source locations' , async ( ) => {
222+ // Run the full action flow
223+ const manifests = await ComponentDetection . scanAndGetManifests ( './test' ) ;
221224
222- console . log ( output )
223- // Test manifest creation with real data to ensure no leading slashes in manifest names
224- const manifests = ComponentDetection . processComponentsToManifests ( output . componentsFound , normalized ) ;
225- for ( const manifest of manifests ) {
226- expect ( manifest . name . startsWith ( '/' ) ) . toBe ( false ) ; // No leading slashes in manifest names
225+ expect ( manifests ) . toBeDefined ( ) ;
226+ expect ( manifests ! . length ) . toBeGreaterThan ( 0 ) ;
227+
228+ // Ensure no manifest names have leading slashes
229+ for ( const manifest of manifests ! ) {
230+ expect ( manifest . name . startsWith ( '/' ) ) . toBe ( false ) ;
227231 }
228- } ) ;
232+
233+ // Expected manifest names based on test data files
234+ const expectedManifestNames = [
235+ 'package.json' ,
236+ 'package-lock.json' ,
237+ 'nested/package.json' ,
238+ 'nested/package-lock.json' ,
239+ 'environment.yaml'
240+ ] ;
241+
242+ // Create a lookup for manifests by name
243+ const manifestsByName = manifests ! . reduce ( ( acc , manifest ) => {
244+ acc [ manifest . name ] = manifest ;
245+ return acc ;
246+ } , { } as Record < string , any > ) ;
247+
248+ console . log ( 'Found manifests:' , Object . keys ( manifestsByName ) ) ;
249+
250+ // Check each expected manifest if it exists
251+ for ( const expectedName of expectedManifestNames ) {
252+ const manifest = manifestsByName [ expectedName ] ;
253+ if ( manifest ) {
254+ // Check manifest name is correct
255+ expect ( manifest . name ) . toBe ( expectedName ) ;
256+
257+ // Check file source location matches the manifest name
258+ expect ( manifest . file ?. source_location ) . toBe ( expectedName ) ;
259+
260+ console . log ( `✓ Verified manifest: ${ expectedName } ` ) ;
261+ }
262+ }
263+
264+ // Verify specific expected manifests exist with correct properties
265+ if ( manifestsByName [ 'package.json' ] ) {
266+ expect ( manifestsByName [ 'package.json' ] . name ) . toBe ( 'package.json' ) ;
267+ expect ( manifestsByName [ 'package.json' ] . file ?. source_location ) . toBe ( 'package.json' ) ;
268+ }
269+
270+ if ( manifestsByName [ 'nested/package.json' ] ) {
271+ expect ( manifestsByName [ 'nested/package.json' ] . name ) . toBe ( 'nested/package.json' ) ;
272+ expect ( manifestsByName [ 'nested/package.json' ] . file ?. source_location ) . toBe ( 'nested/package.json' ) ;
273+ }
274+
275+ if ( manifestsByName [ 'environment.yaml' ] ) {
276+ expect ( manifestsByName [ 'environment.yaml' ] . name ) . toBe ( 'environment.yaml' ) ;
277+ expect ( manifestsByName [ 'environment.yaml' ] . file ?. source_location ) . toBe ( 'environment.yaml' ) ;
278+ }
279+ } , 15000 ) ;
229280} ) ;
0 commit comments