@@ -3,28 +3,62 @@ import { PlatformProviderFactory, Platform } from "./src/providers";
3
3
import fs from "fs" ;
4
4
5
5
// Setup platform provider for tests
6
- beforeAll ( ( ) => {
6
+ beforeAll ( async ( ) => {
7
7
process . env . GITHUB_ACTIONS = 'true' ; // Simulate GitHub Actions environment
8
8
const platform = PlatformProviderFactory . create ( Platform . GitHubActions ) ;
9
9
ComponentDetection . setPlatformProvider ( platform ) ;
10
- } ) ;
11
10
12
- test ( "Downloads CLI" , async ( ) => {
11
+ // Download the binary once for all tests
13
12
await ComponentDetection . downloadLatestRelease ( ) ;
14
- expect ( fs . existsSync ( ComponentDetection . componentDetectionPath ) ) ;
13
+ } , 30000 ) ; // Increased timeout for the download
14
+
15
+ test ( "Downloads CLI to proper path" , async ( ) => {
16
+ expect ( fs . existsSync ( ComponentDetection . componentDetectionPath ) ) . toBe ( true ) ;
15
17
} ) ;
16
18
17
- test ( "Runs CLI" , async ( ) => {
18
- await ComponentDetection . downloadLatestRelease ( ) ;
19
- await ComponentDetection . runComponentDetection ( "./test" ) ;
20
- expect ( fs . existsSync ( ComponentDetection . outputPath ) ) ;
21
- } , 10000 ) ;
19
+ // Group tests that use the CLI to prevent file contention
20
+ describe ( "ComponentDetection CLI execution" , ( ) => {
21
+ test ( "Runs CLI" , async ( ) => {
22
+ await ComponentDetection . runComponentDetection ( "./test" ) ;
23
+ expect ( fs . existsSync ( ComponentDetection . outputPath ) ) . toBe ( true ) ;
24
+ } , 30000 ) ; // Increased timeout
22
25
23
- test ( "Parses CLI output" , async ( ) => {
24
- await ComponentDetection . downloadLatestRelease ( ) ;
25
- await ComponentDetection . runComponentDetection ( "./test" ) ;
26
- var manifests = await ComponentDetection . getManifestsFromResults ( ) ;
27
- expect ( manifests ?. length == 2 ) ;
26
+ test ( "Parses CLI output" , async ( ) => {
27
+ await ComponentDetection . runComponentDetection ( "./test" ) ;
28
+ var manifests = await ComponentDetection . getManifestsFromResults ( ) ;
29
+ expect ( manifests ?. length == 2 ) ;
30
+ } , 30000 ) ; // Increased timeout
31
+
32
+ test ( 'full action scan creates manifests with correct names and file source locations' , async ( ) => {
33
+ const manifests = await ComponentDetection . scanAndGetManifests ( './test' ) ;
34
+
35
+ expect ( manifests ) . toBeDefined ( ) ;
36
+ expect ( manifests ! . length ) . toBeGreaterThan ( 0 ) ;
37
+
38
+ for ( const manifest of manifests ! ) {
39
+ expect ( manifest . name . startsWith ( '/' ) ) . toBe ( false ) ;
40
+ expect ( manifest . file ?. source_location ?. startsWith ( '/' ) ) . toBe ( false ) ;
41
+ }
42
+
43
+ const expectedManifestNames = [
44
+ 'package.json' ,
45
+ 'package-lock.json' ,
46
+ 'nested/package.json' ,
47
+ 'nested/package-lock.json' ,
48
+ ] ;
49
+
50
+ const manifestsByName = manifests ! . reduce ( ( acc , manifest ) => {
51
+ acc [ manifest . name ] = manifest ;
52
+ return acc ;
53
+ } , { } as Record < string , any > ) ;
54
+
55
+ for ( const expectedName of expectedManifestNames ) {
56
+ const manifest = manifestsByName [ expectedName ] ;
57
+ expect ( manifest ) . toBeDefined ( ) ;
58
+ expect ( manifest . name ) . toBe ( expectedName ) ;
59
+ expect ( manifest . file ?. source_location ) . toBe ( expectedName ) ;
60
+ }
61
+ } , 30000 ) ; // Increased timeout
28
62
} ) ;
29
63
30
64
describe ( "ComponentDetection.makePackageUrl" , ( ) => {
@@ -221,34 +255,3 @@ describe('normalizeDependencyGraphPaths with real output.json', () => {
221
255
}
222
256
} ) ;
223
257
} ) ;
224
-
225
- test ( 'full action scan creates manifests with correct names and file source locations' , async ( ) => {
226
- await ComponentDetection . downloadLatestRelease ( ) ;
227
- const manifests = await ComponentDetection . scanAndGetManifests ( './test' ) ;
228
-
229
- expect ( manifests ) . toBeDefined ( ) ;
230
- expect ( manifests ! . length ) . toBeGreaterThan ( 0 ) ;
231
-
232
- for ( const manifest of manifests ! ) {
233
- expect ( manifest . name . startsWith ( '/' ) ) . toBe ( false ) ;
234
- }
235
-
236
- const expectedManifestNames = [
237
- 'package.json' ,
238
- 'package-lock.json' ,
239
- 'nested/package.json' ,
240
- 'nested/package-lock.json' ,
241
- ] ;
242
-
243
- const manifestsByName = manifests ! . reduce ( ( acc , manifest ) => {
244
- acc [ manifest . name ] = manifest ;
245
- return acc ;
246
- } , { } as Record < string , any > ) ;
247
-
248
- for ( const expectedName of expectedManifestNames ) {
249
- const manifest = manifestsByName [ expectedName ] ;
250
- expect ( manifest ) . toBeDefined ( ) ;
251
- expect ( manifest . name ) . toBe ( expectedName ) ;
252
- expect ( manifest . file ?. source_location ) . toBe ( expectedName ) ;
253
- }
254
- } , 15000 ) ;
0 commit comments