How to write a next test - “module “core” should n...
# konsist
d
How to write a next test - “module “core” should not depend on any module whose name starts with “feature_“”?
i
ATM this should be double by checking packages
Copy code
fun `module 'core' should not depend on any module whose name starts with 'feature_'`() {
        Konsist
            .scopeFromProject()
            .files
            .withModule("core")
            .assertNot {
                it.imports.any { import -> import.name.contains(".feature.") }
            }
    }
.. however there is a hidden assumption to make this work - declarations in each feature module have proper package e.g
"feature_abc"
(module name) ->
com.myapp.feature.abc
(package for each declaration in given module) Fortunately the above can be verified by another Konsist Test:
Copy code
fun `files reside in package that is derived from module name`() {
        Konsist.scopeFromProduction()
            .files
            .assert {
                /*
                module -> package name:
                feature_meal_planner -> mealplanner
                feature_caloric_calculator -> caloriccalculator
                */
                val featurePackageName = it
                    .moduleName
                    .removePrefix("feature_")
                    .replace("_", "")

                it.hasPackage("com.myapp.${featurePackageName}..")
            }
    }
BTW this is very interesting case, so we will try to implement it in the near future as a part of
assertArchitecture
👍 1