Skip to content

Commit 2d15925

Browse files
committed
fix: Enable gradle9 wrapper test
1 parent 461b134 commit 2d15925

File tree

5 files changed

+144
-18
lines changed

5 files changed

+144
-18
lines changed

.circleci/config.yml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,14 @@ windows_defaults: &windows_defaults
3030
test_matrix_unix: &test_matrix_unix
3131
matrix:
3232
parameters:
33-
node_version: [ '16.18', '18.18', '20.9' ]
33+
node_version: [ '20.19', '22.19', '24.8' ]
3434
jdk_version: [ '8.0.292.j9-adpt' ]
3535
gradle_version: [ '4.10', '5.6.4', '6.9.4']
3636

3737
test_matrix_unix_new_versions: &test_matrix_unix_new_versions
3838
matrix:
3939
parameters:
40-
node_version: [ '16.18', '18.18', '20.9' ]
40+
node_version: [ '20.19', '22.19', '24.8' ]
4141
jdk_version: [ '17.0.9-jbr' ]
4242
gradle_version: [ '7.6', '8.14', '9.0.0', '9.1.0-rc-3' ]
4343

@@ -47,15 +47,15 @@ test_matrix_win: &test_matrix_win
4747
node_version: [ '20', '22', '24' ]
4848
jdk_version: [ '8' ]
4949
jdk_path: [ 'C:\Program Files\Eclipse Adoptium\jdk-8.0.442.6-hotspot' ]
50-
gradle_version: [ '4.10', '5.6', '6.9.4' ]
50+
gradle_version: [ '4.10', '5.6', '6.8.3' ]
5151

5252
test_matrix_win_new_versions: &test_matrix_win_new_versions
5353
matrix:
5454
parameters:
5555
node_version: [ '20', '22', '24' ]
5656
jdk_version: [ '17.0.2' ]
5757
jdk_path: [ 'C:\Program Files\OpenJDK\jdk-17.0.2' ]
58-
gradle_version: [ '7.6', '8.14', '9.0.0', '9.1.0-rc-3' ]
58+
gradle_version: [ '7.6', '8.14', '9.0.0' ]
5959

6060
filters_branches_only_main: &filters_branches_only_main
6161
filters:
@@ -261,6 +261,7 @@ jobs:
261261
docker:
262262
- image: cimg/node:<< parameters.node_version >>
263263
environment:
264+
JDK: << parameters.jdk_version >>
264265
GRADLE_VERSION: << parameters.gradle_version >>
265266
steps:
266267
- checkout

test/common.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,19 @@ export function createDepGraph(depGraph: DepGraphData, fixturePath: string) {
2020
{ encoding: 'utf8' },
2121
);
2222
}
23+
24+
/**
25+
* Check if the current JDK version is at least the specified minimum version
26+
* @param minVersion - The minimum version to check against (e.g., 8, 11, 17, 21)
27+
* @returns true if current JDK version >= minVersion, or if version is unknown (lets test run and fail naturally)
28+
*/
29+
export function jdkVersionAtLeast(minVersion: number): boolean {
30+
const jdkVersionFromProcess = process.env.JDK || '';
31+
if (!jdkVersionFromProcess) {
32+
return true; // If unknown, don't skip - let the test run and fail if incompatible
33+
}
34+
35+
const jdkVersionInUse: number = parseInt(jdkVersionFromProcess.split('.')[0]);
36+
37+
return jdkVersionInUse >= minVersion;
38+
}

test/system/android.test.ts

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,25 @@ const gradleVersionInUse: number = parseInt(
77
gradleVersionFromProcess.split('.')[0],
88
);
99
const isAndroidSupported: boolean = gradleVersionInUse > 7 ? true : false;
10-
if (isAndroidSupported) {
11-
describe('android version 8 build', () => {
12-
test('we can inspect naively', async () => {
10+
describe('android version 8 build', () => {
11+
const testOrSkip = isAndroidSupported ? test : test.skip;
12+
13+
testOrSkip(
14+
'we can inspect naively',
15+
async () => {
1316
const data = await inspect(
1417
'.',
1518
path.join(fixtureDir('modern-android'), 'build.gradle'),
1619
{ allSubProjects: true },
1720
);
1821
expect(data.scannedProjects.length).toEqual(2);
19-
}, 90000);
22+
},
23+
90000,
24+
);
2025

21-
test('we can inspect with configuration attribute selector', async () => {
26+
testOrSkip(
27+
'we can inspect with configuration attribute selector',
28+
async () => {
2229
const data = await inspect(
2330
'.',
2431
path.join(fixtureDir('modern-android'), 'build.gradle'),
@@ -29,9 +36,7 @@ if (isAndroidSupported) {
2936
},
3037
);
3138
expect(data.scannedProjects.length).toEqual(2);
32-
}, 90000);
33-
});
34-
} else {
35-
// eslint-disable-next-line @typescript-eslint/no-empty-function
36-
test('minimum gradle version for modern android project is 8', () => {});
37-
}
39+
},
40+
90000,
41+
);
42+
});

test/system/fixtures-with-wrappers.test.ts

Lines changed: 105 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@ import * as path from 'path';
22
import * as fs from 'fs';
33
import { NeedleResponse } from 'needle';
44

5-
import { getPathToFixture } from '../common';
5+
import { getPathToFixture, jdkVersionAtLeast } from '../common';
66
import { inspect } from '../../lib';
77
import * as search from '../../lib/search';
88
import type { PomCoords, SnykHttpClient } from '../../lib/types';
9+
import { DepGraphData } from '@snyk/dep-graph';
910

1011
// specify fixtures to test, or leave empty to test all fixtures
1112
let fixtures: string[] = [];
@@ -156,4 +157,107 @@ describe('inspect() fixtures', () => {
156157

157158
expect(result.dependencyGraph?.toJSON()).toEqual(expectedDepGraphJson);
158159
});
160+
161+
describe('kts-basic-gradle9 fixture tests - requires JDK 17+', () => {
162+
const isGradle9Compatible = jdkVersionAtLeast(17);
163+
const testOrSkip = isGradle9Compatible ? test : test.skip;
164+
165+
// Sanitizes DepGraph data to normalize platform-specific dependencies
166+
// Specifically converts kotlin-native-prebuilt entries with any architecture
167+
// to use macos-aarch64 for consistent test expectations
168+
const sanitizeDepGraphForPlatform = (depGraphData: DepGraphData): any => {
169+
if (!depGraphData) return depGraphData;
170+
171+
const sanitized = JSON.parse(JSON.stringify(depGraphData)); // deep clone
172+
173+
// Sanitize graph nodes
174+
if (sanitized.graph?.nodes) {
175+
sanitized.graph.nodes = sanitized.graph.nodes.map((node: any) => {
176+
if (node.nodeId && node.nodeId.includes('kotlin-native-prebuilt::')) {
177+
// Replace any architecture with macos-aarch64
178+
node.nodeId = node.nodeId.replace(
179+
/kotlin-native-prebuilt::[^@]+/,
180+
'kotlin-native-prebuilt::macos-aarch64',
181+
);
182+
}
183+
return node;
184+
});
185+
}
186+
187+
// Sanitize dependencies within nodes
188+
if (sanitized.graph?.nodes) {
189+
sanitized.graph.nodes.forEach((node: any) => {
190+
if (node.deps) {
191+
node.deps = node.deps.map((dep: any) => {
192+
if (
193+
dep.nodeId &&
194+
dep.nodeId.includes('kotlin-native-prebuilt::')
195+
) {
196+
dep.nodeId = dep.nodeId.replace(
197+
/kotlin-native-prebuilt::[^@]+/,
198+
'kotlin-native-prebuilt::macos-aarch64',
199+
);
200+
}
201+
return dep;
202+
});
203+
}
204+
});
205+
}
206+
207+
return sanitized;
208+
};
209+
210+
const expectSanitizedResult = (result: any, expectedDepGraphJson: any) => {
211+
const sanitizedResult = sanitizeDepGraphForPlatform(
212+
result.dependencyGraph?.toJSON() as DepGraphData,
213+
);
214+
expect(sanitizedResult).toEqual(expectedDepGraphJson);
215+
};
216+
217+
testOrSkip(
218+
'basic inspection',
219+
async () => {
220+
const fixturePath = getPathToFixture('kts-basic-gradle9');
221+
const pathToBuildConfig = path.join(fixturePath, 'build.gradle.kts');
222+
const expectedDepGraphJson = JSON.parse(
223+
fs.readFileSync(`${fixturePath}/dep-graph.json`, 'utf8'),
224+
);
225+
226+
const result = await inspect('.', pathToBuildConfig);
227+
expectSanitizedResult(result, expectedDepGraphJson);
228+
},
229+
140000,
230+
);
231+
232+
testOrSkip(
233+
'gradleNormalizeDeps',
234+
async () => {
235+
jest.spyOn(search, 'getMavenPackageInfo').mockImplementation(
236+
async (
237+
_sha1: string,
238+
depCoords: Partial<PomCoords>,
239+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
240+
_snykHttpClient: SnykHttpClient,
241+
) => {
242+
const type = depCoords.type ?? '';
243+
const classifier = depCoords.classifier
244+
? `:${depCoords.classifier}`
245+
: '';
246+
return `${depCoords.groupId}:${depCoords.artifactId}:${type}${classifier}@${depCoords.version}`;
247+
},
248+
);
249+
const fixturePath = getPathToFixture('kts-basic-gradle9');
250+
const pathToBuildConfig = path.join(fixturePath, 'build.gradle.kts');
251+
const expectedDepGraphJson = JSON.parse(
252+
fs.readFileSync(`${fixturePath}/dep-graph.json`, 'utf8'),
253+
);
254+
255+
const result = await inspect('.', pathToBuildConfig, {
256+
gradleNormalizeDeps: true,
257+
});
258+
expectSanitizedResult(result, expectedDepGraphJson);
259+
},
260+
140000,
261+
);
262+
});
159263
});

test/system/kotlin.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ if (gradleVersionInUse < 5) {
6262
expectedDirectDependencies.forEach((expectedDependency) => {
6363
expect(directDependencies).toContainEqual(expectedDependency);
6464
});
65-
}, 200000);
65+
}, 220000);
6666
} else {
6767
test('build.gradle.kts files are supported with Gradle version >= 9', async () => {
6868
const result = await inspect(
@@ -113,5 +113,5 @@ if (gradleVersionInUse < 5) {
113113
expectedDirectDependencies.forEach((expectedDependency) => {
114114
expect(directDependencies).toContainEqual(expectedDependency);
115115
});
116-
}, 200000);
116+
}, 220000);
117117
}

0 commit comments

Comments
 (0)