Blaž Vantur
10/23/2024, 8:07 AMBlaž Vantur
10/23/2024, 8:07 AMprivate val core = Layer("Core", "sp.bvantur.core..")
private val features = listOf(
Layer("Splash", "sp.bvantur.feature1.."),
Layer("Register", "sp.bvantur.feature2.."),
Layer("Login", "sp.bvantur.feature3..")
)
@Test
fun `single features depends only on core feature`() {
Konsist
.scopeFromProduction("composeApp")
.assertArchitecture {
features.forEach { feature ->
feature.dependsOn(core)
features.filter { it != feature }.forEach {
feature.doesNotDependOn(it)
}
}
}
}
igor.wojda
10/25/2024, 9:48 AM@Test
fun `single features depends only on core feature`() {
Konsist
.scopeFromProduction("composeApp")
.assertArchitecture {
features.forEach { feature ->
// feature depends only on core feature
feature.dependsOn(core)
// features does not depend on other feature
features.filter { it != feature }.forEach {
feature.doesNotDependOn(it)
}
}
}
}
Just keep in mind that Konsist describe layer dependencies (whatever given file is using imports from other layer). not module dependencies (sometimes these are aligned like in your case)
If core
layer is independent (from any other layers added inside assertArchitecture
) then you could also use dependsOnNothing
):
private val core = Layer("Core", "sp.bvantur.core..")
private val features = listOf(
Layer("Splash", "sp.bvantur.feature1.."),
Layer("Register", "sp.bvantur.feature2.."),
Layer("Login", "sp.bvantur.feature3..")
)
@Test
fun `single features depends only on core feature`() {
Konsist
.scopeFromProduction("composeApp")
.assertArchitecture {
// ...
core.doesOnNothing()
}
}
BTW We are currently refactoring assertArchitecture
(API will not change, but will be extended) . If you see anything off this is a very good time to let us know.
BTW Looking at your code I see that there is a potencial to remove forEach
- add a method working on collections:
fun `single features depends only on core feature`() {
Konsist
.scopeFromProduction("composeApp")
.assertArchitecture {
features.dependsOn(core) // Potential for API improvement on List<Layer>.dependsOn()
core.doesOnNothing()
}
}
Blaž Vantur
11/02/2024, 6:45 AM