Skip to content

Commit

Permalink
fix(testing): safely handle circular deps in component testing plugin (
Browse files Browse the repository at this point in the history
  • Loading branch information
leosvelperez authored Dec 20, 2023
1 parent dcb4bee commit 9e25c91
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 2 deletions.
38 changes: 38 additions & 0 deletions packages/cypress/src/utils/ct-helpers.spec.ts
Original file line number Diff line number Diff line change
@@ -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
);
});
});
10 changes: 8 additions & 2 deletions packages/cypress/src/utils/ct-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,13 @@ export function getTempTailwindPath(context: ExecutorContext) {
export function isCtProjectUsingBuildProject(
graph: ProjectGraph,
parentProjectName: string,
childProjectName: string
childProjectName: string,
seen = new Set<string>()
): boolean {
if (seen.has(parentProjectName)) {
return false;
}
seen.add(parentProjectName);
const isProjectDirectDep = graph.dependencies[parentProjectName].some(
(p) => p.target === childProjectName
);
Expand All @@ -62,7 +67,8 @@ export function isCtProjectUsingBuildProject(
isCtProjectUsingBuildProject(
graph,
maybeIntermediateProject.target,
childProjectName
childProjectName,
seen
)
) {
return true;
Expand Down

0 comments on commit 9e25c91

Please sign in to comment.