Skip to content

modulePath returns incorrect path for nested-module structures #14

Description

@arecmetafora

If you define your project in such a way you have more than one layer of modules, whenever you run tests for a specific class it will start a gradle task on the topmost parent module in the hierarchy.

For instance, imagine we have the following project structure:

  • myProject root
    • model
    • domain
    • presentation
      • feature1
      • feature2
      • featureN

Running any contextual testing action for a feature class will trigger a gradle task for the whole presentation module.
That can be problematic for projects with dozen of other sibling modules.

Executing tasks: [verifyPaparazziDebug, --tests, com.company.presentation.feature1.myClass] in project /Users/alex/git/myProject/presentation

The problem seems to be caused by the Path.modulePath extension, which probably assumes there will be only one layer of modules.

internal fun Project.modulePath(file: VirtualFile): String? {
return modules.asSequence().map { it.getModuleDir() }.firstOrNull { file.path.startsWith(it) }
?: basePath?.let { projectPath ->
val relativePath = FileUtil.getRelativePath(projectPath, file.path, File.separatorChar)
val moduleName = relativePath?.split(File.separator)?.firstOrNull()
if (moduleName != null) projectPath + File.separator + moduleName else null
}
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions