diff --git a/packages/cypress/src/utils/ct-helpers.spec.ts b/packages/cypress/src/utils/ct-helpers.spec.ts new file mode 100644 index 0000000000000..d56fb289678d1 --- /dev/null +++ b/packages/cypress/src/utils/ct-helpers.spec.ts @@ -0,0 +1,38 @@ +import { ProjectGraph } from '@nx/devkit'; +import { isCtProjectUsingBuildProject } from './ct-helpers'; + +describe('ct-helpers', () => { + /** + * app1 -> lib1 -> lib2 -> lib3 -> lib1 + * -> lib4 -> lib5 + * lib6 + */ + const projectGraph: ProjectGraph = { + dependencies: { + app1: [{ source: 'app1', target: 'lib1', type: 'static' }], + lib1: [{ source: 'lib1', target: 'lib2', type: 'static' }], + lib2: [{ source: 'lib2', target: 'lib3', type: 'static' }], + lib3: [ + { source: 'lib3', target: 'lib1', type: 'static' }, + { source: 'lib3', target: 'lib4', type: 'static' }, + ], + lib4: [{ source: 'lib4', target: 'lib5', type: 'static' }], + lib5: [], + lib6: [], + }, + nodes: {}, + externalNodes: {}, + }; + + it('should handle circular deps and find the relation', () => { + expect(isCtProjectUsingBuildProject(projectGraph, 'app1', 'lib5')).toBe( + true + ); + }); + + it('should handle circular deps and find no relation', () => { + expect(isCtProjectUsingBuildProject(projectGraph, 'app1', 'lib6')).toBe( + false + ); + }); +}); diff --git a/packages/cypress/src/utils/ct-helpers.ts b/packages/cypress/src/utils/ct-helpers.ts index 99466e8b7f75b..0cdeb2cfdef08 100644 --- a/packages/cypress/src/utils/ct-helpers.ts +++ b/packages/cypress/src/utils/ct-helpers.ts @@ -45,8 +45,13 @@ export function getTempTailwindPath(context: ExecutorContext) { export function isCtProjectUsingBuildProject( graph: ProjectGraph, parentProjectName: string, - childProjectName: string + childProjectName: string, + seen = new Set() ): boolean { + if (seen.has(parentProjectName)) { + return false; + } + seen.add(parentProjectName); const isProjectDirectDep = graph.dependencies[parentProjectName].some( (p) => p.target === childProjectName ); @@ -62,7 +67,8 @@ export function isCtProjectUsingBuildProject( isCtProjectUsingBuildProject( graph, maybeIntermediateProject.target, - childProjectName + childProjectName, + seen ) ) { return true;