Skip to content

Commit 50ca7c5

Browse files
committed
fixup! Introduce Kotlin integration tests
1 parent ab63752 commit 50ca7c5

File tree

1 file changed

+10
-12
lines changed

1 file changed

+10
-12
lines changed

src/jvmTest/kotlin/integration/typescript/TypeScriptTestBase.kt

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,13 @@ abstract class TypeScriptTestBase {
4646

4747
@JvmStatic
4848
protected fun executeCommand(command: String, workingDir: File): String {
49+
// Prefer running TypeScript via ts-node to avoid npx network delays on CI
50+
val adjusted = if (command.contains("npx tsx ")) {
51+
command.replaceFirst("npx tsx ", "node --loader ts-node/esm ")
52+
} else command
53+
4954
val process = ProcessBuilder()
50-
.command("bash", "-c", command)
55+
.command("bash", "-c", adjusted)
5156
.directory(workingDir)
5257
.redirectErrorStream(true)
5358
.start()
@@ -63,7 +68,7 @@ abstract class TypeScriptTestBase {
6368

6469
val exitCode = process.waitFor()
6570
if (exitCode != 0) {
66-
throw RuntimeException("Command execution failed with exit code $exitCode: $command\nOutput:\n$output")
71+
throw RuntimeException("Command execution failed with exit code $exitCode: $adjusted\nOutput:\n$output")
6772
}
6873

6974
return output.toString()
@@ -75,17 +80,10 @@ abstract class TypeScriptTestBase {
7580
}
7681

7782
@JvmStatic
78-
protected fun findFreePort(minPort: Int = 3000, maxPort: Int = 4000): Int {
79-
for (port in minPort..maxPort) {
80-
try {
81-
ServerSocket(port).use {
82-
return port
83-
}
84-
} catch (_: Exception) {
85-
// port is in use, try the next one
86-
}
83+
protected fun findFreePort(): Int {
84+
ServerSocket(0).use { socket ->
85+
return socket.localPort
8786
}
88-
throw RuntimeException("No free port found between $minPort and $maxPort")
8987
}
9088
}
9189

0 commit comments

Comments
 (0)