Skip to content

[QUESTION] Easy and performant way to say src/features/feature-a can't depend on src/features/feature-b? #55

@vincentjames501

Description

@vincentjames501

Question

We have a very large project with 100s of features. We really like the elegance of this API, however, we're struggling to keep the unit test time down (naively takes 100+s). Our goal is to simply say src/features/feature-a can't depend on src/features/feature-b and try to avoid any sort of n^2 complexity.

Code Context

This helps cut the time down a bit but is a bit hacky. Just curious if there was a better way to express this which could be faster?

    before(async () => {
      const violations = await projectFiles()
        .inFolder('src/app/features/**')
        .shouldNot()
        .dependOnFiles()
        .inFolder('src/app/features/**')
        .check();

      unexpectedByFeature = new Map();
      for (const v of violations) {
        for (const e of v.dependency.cumulatedEdges) {
          const from = featureOf(e.source);
          const to = featureOf(e.target);
          if (!from || !to || from === to) continue;
          if (CROSS_FEATURE_VIOLATIONS_SET.has(`${from}:${to}`)) continue;
          const arr = unexpectedByFeature.get(from) ?? [];
          arr.push(e);
          unexpectedByFeature.set(from, arr);
        }
      }
    });

    for (const fromFeature of features) {
      it(`${fromFeature} should not import from sibling features`, () => {
        const vs = unexpectedByFeature?.get(fromFeature) ?? [];
        if (vs.length > 0) {
          const lines = vs.map(e => `  ${e.source}\n    → ${e.target}`);
          throw new Error(
            `Feature "${fromFeature}" has forbidden cross-feature imports:\n${lines.join('\n')}`
          );
        }
      });
    }
  });

Your setup:

  • OS: MacOS
  • Node.js Version: 22
  • ArchUnitTS Version: 2.1.69
  • Testing Framework: Node and Vitest

📚 Documentation Checked

Have you checked the documentation?

  • [ x ] README.md
  • [ x ] API Documentation
  • [ x ] Examples folder
  • [ x ] GitHub Issues
  • Stack Overflow

📋 Additional Context

Add any other context about your question here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions