Skip to content

Commit bfd09fb

Browse files
committed
test(manifest): add Kotlin Multiplatform fixture for --facts
A minimal KMP project (jvm + js targets) exercises per-target compile and runtime classpaths (jvmMainCompileClasspath, jsTestRuntimeClasspath, ...) that aren't surfaced through Java's SourceSetContainer. Our name-pattern selection picks them up by suffix. The fixture pulls kotlinx-serialization-core (commonMain) so it shows up in both jvm and js target variants of the artifact, and slf4j-api (jvmMain-only) to confirm target-specific classpaths flow through. The test asserts both deps are present in the resulting components array.
1 parent 37d8e62 commit bfd09fb

4 files changed

Lines changed: 76 additions & 2 deletions

File tree

.github/workflows/e2e-tests.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,12 @@ jobs:
6868
# Required by socket-facts-init-gradle.e2e.test.mts — exercises the
6969
# `socket manifest gradle --facts` init script against real Gradle.
7070
# Without these the test auto-skips.
71-
- uses: actions/setup-java@v4
71+
- uses: actions/setup-java@c1e323688fd81a25caa38c78aa6df2d33d3e20d9 # v4
7272
with:
7373
distribution: temurin
7474
java-version: '21'
7575

76-
- uses: gradle/actions/setup-gradle@v4
76+
- uses: gradle/actions/setup-gradle@0b6dd653ba04f4f93bf581ec31e66cbd7dcb644d # v4
7777
with:
7878
gradle-version: '9.2.1'
7979

src/commands/manifest/socket-facts-init-gradle.e2e.test.mts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,36 @@ describeOrSkip('socket-facts.init.gradle', () => {
181181
})
182182
})
183183

184+
describe('kotlin-multiplatform fixture', () => {
185+
const fixture = path.join(fixturesRoot, 'kotlin-multiplatform')
186+
const output = path.join(fixture, '.socket.facts.json')
187+
188+
it('captures per-target classpaths from kotlin.targets', async () => {
189+
clean(output)
190+
await runFacts(fixture)
191+
expect(existsSync(output)).toBe(true)
192+
const facts = readFacts(output)
193+
// commonMain dep — should resolve into both jvm and js target variants.
194+
const serializationCore = findById(
195+
facts,
196+
c =>
197+
c.namespace === 'org.jetbrains.kotlinx' &&
198+
c.name.startsWith('kotlinx-serialization-core'),
199+
)
200+
expect(
201+
serializationCore.length,
202+
`expected kotlinx-serialization-core in at least one target variant: ${facts.components.map(c => c.id).join(', ')}`,
203+
).toBeGreaterThan(0)
204+
// jvmMain-only dep — should be present, exercising the per-target
205+
// classpath name pattern (`jvmMainRuntimeClasspath` and friends).
206+
const slf4j = findById(
207+
facts,
208+
c => c.namespace === 'org.slf4j' && c.name === 'slf4j-api',
209+
)
210+
expect(slf4j.length, 'jvmMain slf4j-api present').toBeGreaterThan(0)
211+
})
212+
})
213+
184214
describe('android-library fixture', () => {
185215
const fixture = path.join(fixturesRoot, 'android-library')
186216
const output = path.join(fixture, '.socket.facts.json')
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// Kotlin Multiplatform fixture for socket-facts.init.gradle. Exercises
2+
// per-target compile/runtime configurations (jvmMainCompileClasspath,
3+
// jsTestRuntimeClasspath, etc.) that the Java SourceSetContainer doesn't
4+
// surface, but which our name-pattern selection (`*CompileClasspath` /
5+
// `*RuntimeClasspath`) still picks up.
6+
plugins {
7+
id 'org.jetbrains.kotlin.multiplatform' version '1.9.25'
8+
}
9+
10+
group = 'com.example.socket.kmp'
11+
version = '1.0.0'
12+
13+
repositories {
14+
mavenCentral()
15+
}
16+
17+
kotlin {
18+
jvm()
19+
js {
20+
nodejs()
21+
}
22+
23+
sourceSets {
24+
commonMain {
25+
dependencies {
26+
implementation 'org.jetbrains.kotlinx:kotlinx-serialization-core:1.6.2'
27+
}
28+
}
29+
jvmMain {
30+
dependencies {
31+
implementation 'org.slf4j:slf4j-api:1.7.36'
32+
}
33+
}
34+
}
35+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
pluginManagement {
2+
repositories {
3+
gradlePluginPortal()
4+
mavenCentral()
5+
google()
6+
}
7+
}
8+
9+
rootProject.name = 'kotlin-multiplatform'

0 commit comments

Comments
 (0)